2424import sys
2525import os
2626import re
27+ import warnings
2728import requests
2829
29- _BINDING_VERSION = '1.5 .0'
30+ _BINDING_VERSION = '1.6 .0'
3031_GZIP_BYTEARRAY = bytearray ([0x1F , 0x8b , 0x08 ])
3132
3233_ISPY3 = sys .version_info [0 ] == 3
3738else :
3839 _GZIP_SIGNATURE = str (_GZIP_BYTEARRAY )
3940
41+ warnings .simplefilter ('always' )
42+
4043
4144class _ReturnObject :
4245
@@ -79,6 +82,46 @@ def __str__(self):
7982 return sst + ": " + self .message + ":\n " + self .response_message
8083
8184
85+ class _PseudoEnum :
86+ """ Base class for MorphologyOutput """
87+
88+ def __init__ (self ):
89+ pass
90+
91+ @classmethod
92+ def validate (cls , value , name ):
93+ """ validation method """
94+ values = []
95+ for (key , value ) in vars (cls ).items ():
96+ if not key .startswith ("__" ):
97+ values += [value ]
98+
99+ # this is still needed to make sure that the parameter NAMES are known.
100+ # If python didn't allow setting unknown values, this would be a
101+ # language error.
102+ if value not in values :
103+ raise RosetteException (
104+ "unknownVariable" ,
105+ "The value supplied for " +
106+ name +
107+ " is not one of " +
108+ ", " .join (values ) +
109+ "." ,
110+ repr (value ))
111+
112+
113+ class MorphologyOutput (_PseudoEnum ):
114+ """ Class to provide Morphology sub-endpoints """
115+ warnings .warn ('MorphologyOutput to be removed in version 1.9.0. '
116+ 'Please use API.morphology_output' ,
117+ DeprecationWarning )
118+ LEMMAS = "lemmas"
119+ PARTS_OF_SPEECH = "parts-of-speech"
120+ COMPOUND_COMPONENTS = "compound-components"
121+ HAN_READINGS = "han-readings"
122+ COMPLETE = "complete"
123+
124+
82125class _DocumentParamSetBase (object ):
83126
84127 def __init__ (self , repertoire ):
@@ -349,7 +392,7 @@ def info(self):
349392 headers = {'Accept' : 'application/json' , 'X-RosetteAPI-Binding' : 'python' ,
350393 'X-RosetteAPI-Binding-Version' : _BINDING_VERSION }
351394
352- custom_headers = self .api .getcustom_headers ()
395+ custom_headers = self .api .get_custom_headers ()
353396 pattern = re .compile ('^X-RosetteAPI-' )
354397 if custom_headers is not None :
355398 for key in custom_headers .keys ():
@@ -359,7 +402,7 @@ def info(self):
359402 raise RosetteException ("badHeader" ,
360403 "Custom header name must begin with \" X-RosetteAPI-\" " ,
361404 key )
362- self .api .clearcustom_headers ()
405+ self .api .clear_custom_headers ()
363406
364407 if self .debug :
365408 headers ['X-RosetteAPI-Devel' ] = 'true'
@@ -379,7 +422,7 @@ def ping(self):
379422 headers = {'Accept' : 'application/json' , 'X-RosetteAPI-Binding' : 'python' ,
380423 'X-RosetteAPI-Binding-Version' : _BINDING_VERSION }
381424
382- custom_headers = self .api .getcustom_headers ()
425+ custom_headers = self .api .get_custom_headers ()
383426 pattern = re .compile ('^X-RosetteAPI-' )
384427 if custom_headers is not None :
385428 for key in custom_headers .keys ():
@@ -389,7 +432,7 @@ def ping(self):
389432 raise RosetteException ("badHeader" ,
390433 "Custom header name must begin with \" X-RosetteAPI-\" " ,
391434 key )
392- self .api .clearcustom_headers ()
435+ self .api .clear_custom_headers ()
393436
394437 if self .debug :
395438 headers ['X-RosetteAPI-Devel' ] = 'true'
@@ -439,7 +482,7 @@ def call(self, parameters):
439482 params_to_serialize = parameters .serialize (self .api .options )
440483 headers = {}
441484 if self .user_key is not None :
442- custom_headers = self .api .getcustom_headers ()
485+ custom_headers = self .api .get_custom_headers ()
443486 pattern = re .compile ('^X-RosetteAPI-' )
444487 if custom_headers is not None :
445488 for key in custom_headers .keys ():
@@ -450,7 +493,7 @@ def call(self, parameters):
450493 "Custom header name must "
451494 "begin with \" X-RosetteAPI-\" " ,
452495 key )
453- self .api .clearcustom_headers ()
496+ self .api .clear_custom_headers ()
454497
455498 headers ["X-RosetteAPI-Key" ] = self .user_key
456499 headers ["X-RosetteAPI-Binding" ] = "python"
@@ -662,12 +705,31 @@ def post_http(self, url, data, headers):
662705
663706 return _ReturnObject (_my_loads (rdata , response_headers ), status )
664707
708+ def getPoolSize (self ):
709+ """
710+ Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value
711+ """
712+ warnings .warn ('Method renamed to API.get_pool_size(). To be removed in version 1.9.0' ,
713+ DeprecationWarning )
714+ return self .get_pool_size ()
715+
665716 def get_pool_size (self ):
666717 """
667718 Returns the maximum pool size, which is the returned x-rosetteapi-concurrency value
668719 """
669720 return int (self .max_pool_size )
670721
722+ def setOption (self , name , value ):
723+ """
724+ Sets an option
725+
726+ @param name: name of option
727+ @param value: value of option
728+ """
729+ warnings .warn ('Method renamed to API.set_option(). To be removed in version 1.9.0' ,
730+ DeprecationWarning )
731+ return self .set_option (name , value )
732+
671733 def set_option (self , name , value ):
672734 """
673735 Sets an option
@@ -680,6 +742,18 @@ def set_option(self, name, value):
680742 else :
681743 self .options [name ] = value
682744
745+ def getOption (self , name ):
746+ """
747+ Gets an option
748+
749+ @param name: name of option
750+
751+ @return: value of option
752+ """
753+ warnings .warn ('Method renamed to API.get_option(). To be removed in version 1.9.0' ,
754+ DeprecationWarning )
755+ return self .get_option (name )
756+
683757 def get_option (self , name ):
684758 """
685759 Gets an option
@@ -693,12 +767,31 @@ def get_option(self, name):
693767 else :
694768 return None
695769
770+ def clearOptions (self ):
771+ """
772+ Clears all options
773+ """
774+ warnings .warn ('Method renamed to API.clear_options(). To be removed in version 1.9.0' ,
775+ DeprecationWarning )
776+ self .clear_options ()
777+
696778 def clear_options (self ):
697779 """
698780 Clears all options
699781 """
700782 self .options .clear ()
701783
784+ def setUrlParameter (self , name , value ):
785+ """
786+ Sets a URL parameter
787+
788+ @param name: name of parameter
789+ @param value: value of parameter
790+ """
791+ warnings .warn ('Method renamed to API.set_url_parameter(). To be removed in version 1.9.0' ,
792+ DeprecationWarning )
793+ return self .set_url_parameter (name , value )
794+
702795 def set_url_parameter (self , name , value ):
703796 """
704797 Sets a URL parameter
@@ -711,6 +804,18 @@ def set_url_parameter(self, name, value):
711804 else :
712805 self .url_parameters [name ] = value
713806
807+ def getUrlParameter (self , name ):
808+ """
809+ Gets a URL parameter
810+
811+ @param name: name of parameter
812+
813+ @return: value of parameter
814+ """
815+ warnings .warn ('Method renamed to API.get_url_parameter(). To be removed in version 1.9.0' ,
816+ DeprecationWarning )
817+ return self .get_url_parameter (name )
818+
714819 def get_url_parameter (self , name ):
715820 """
716821 Gets a URL parameter
@@ -724,13 +829,32 @@ def get_url_parameter(self, name):
724829 else :
725830 return None
726831
727- def clearurl_parameters (self ):
832+ def clearUrlParameters (self ):
833+ """
834+ Clears all options
835+ """
836+ warnings .warn ('Method renamed to API.clear_url_parameters(). '
837+ 'To be removed in version 1.9.0' ,
838+ DeprecationWarning )
839+ self .clear_url_parameters ()
840+
841+ def clear_url_parameters (self ):
728842 """
729843 Clears all options
730844 """
731845 self .url_parameters .clear ()
732846
733- def setcustom_headers (self , name , value ):
847+ def setCustomHeaders (self , name , value ):
848+ """
849+ Sets custom headers
850+
851+ @param headers: array of custom headers to be set
852+ """
853+ warnings .warn ('Method renamed to API.set_custom_headers(). To be removed in version 1.9.0' ,
854+ DeprecationWarning )
855+ return self .set_custom_headers (name , value )
856+
857+ def set_custom_headers (self , name , value ):
734858 """
735859 Sets custom headers
736860
@@ -741,13 +865,30 @@ def setcustom_headers(self, name, value):
741865 else :
742866 self .custom_headers [name ] = value
743867
744- def getcustom_headers (self ):
868+ def getCustomHeaders (self ):
869+ """
870+ Get custom headers
871+ """
872+ warnings .warn ('Method renamed to API.get_custom_headers(). To be removed in version 1.9.0' ,
873+ DeprecationWarning )
874+ return self .get_custom_headers ()
875+
876+ def get_custom_headers (self ):
745877 """
746878 Get custom headers
747879 """
748880 return self .custom_headers
749881
750- def clearcustom_headers (self ):
882+ def clearCustomHeaders (self ):
883+ """
884+ Clears custom headers
885+ """
886+ warnings .warn ('Method renamed to API.clear_custom_headers(). '
887+ 'To be removed in version 1.9.0' ,
888+ DeprecationWarning )
889+ self .clear_custom_headers ()
890+
891+ def clear_custom_headers (self ):
751892 """
752893 Clears custom headers
753894 """
0 commit comments