Skip to content

Commit 8dd85a3

Browse files
committed
Move deprecated decorator to utils
1 parent f461fed commit 8dd85a3

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

watson_developer_cloud/document_conversion_v1.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,24 @@
1616
The v1 Document Conversion service
1717
(https://www.ibm.com/watson/developercloud/document-conversion.html)
1818
"""
19-
import warnings
19+
from .utils import deprecated
2020
from .watson_service import WatsonService
2121
import os
2222
import json
2323

24-
def deprecated(func):
25-
def deprecated_func(*args, **kwargs):
26-
warnings.warn("{} retired in October 2017. To continue using document conversion capabilities, please use Watson Discovery.".format(func.__name__),
27-
category=DeprecationWarning,
28-
stacklevel=2)
29-
warnings.simplefilter('default', DeprecationWarning)
30-
return func(*args, **kwargs)
31-
return deprecated_func
32-
3324
class DocumentConversionV1(WatsonService):
3425
DEFAULT_URL = 'https://gateway.watsonplatform.net/document-conversion/api'
3526
ANSWER_UNITS = 'answer_units'
3627
NORMALIZED_HTML = 'normalized_html'
3728
NORMALIZED_TEXT = 'normalized_text'
3829
latest_version = '2016-02-10'
3930

40-
@deprecated
31+
@deprecated("To continue using document conversion capabilities, please use Watson Discovery.")
4132
def __init__(self, version, url=DEFAULT_URL, **kwargs):
4233
WatsonService.__init__(self, 'document_conversion', url, **kwargs)
4334
self.version = version
4435

45-
@deprecated
36+
@deprecated("To continue using document conversion capabilities, please use Watson Discovery.")
4637
def convert_document(self, document, config, media_type=None):
4738
params = {'version': self.version}
4839
filename = os.path.basename(document.name)
@@ -56,7 +47,7 @@ def convert_document(self, document, config, media_type=None):
5647
return self.request(method='POST', url='/v1/convert_document',
5748
files=files, params=params,
5849
accept_json=accept_json)
59-
@deprecated
50+
@deprecated("To continue using document conversion capabilities, please use Watson Discovery.")
6051
def index_document(self, config, document=None, metadata=None,
6152
media_type=None):
6253
if document is None and metadata is None:

watson_developer_cloud/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import warnings
2+
3+
def deprecated(message):
4+
def deprecated_decorator(func):
5+
def deprecated_func(*args, **kwargs):
6+
warnings.warn("{} is a deprecated function. {}".format(func.__name__, message),
7+
category=DeprecationWarning,
8+
stacklevel=2)
9+
warnings.simplefilter('default', DeprecationWarning)
10+
return func(*args, **kwargs)
11+
return deprecated_func
12+
return deprecated_decorator

0 commit comments

Comments
 (0)