2828import re
2929import warnings
3030
31- _BINDING_VERSION = '1.3 .0'
31+ _BINDING_VERSION = '1.4 .0'
3232_GZIP_BYTEARRAY = bytearray ([0x1F , 0x8b , 0x08 ])
3333
3434_IsPy3 = sys .version_info [0 ] == 3
@@ -522,7 +522,6 @@ def __init__(
522522 if (refresh_duration < 0 ):
523523 refresh_duration = 0
524524
525- self .num_retries = retries
526525 self .connection_refresh_duration = refresh_duration
527526 self .options = {}
528527 self .customHeaders = {}
@@ -538,8 +537,6 @@ def _set_pool_size(self):
538537
539538 def _make_request (self , op , url , data , headers ):
540539 """
541- Handles the actual request, retrying if a 429 is encountered
542-
543540 @param op: POST or GET
544541 @param url: endpoing URL
545542 @param data: request data
@@ -556,43 +553,39 @@ def _make_request(self, op, url, data, headers):
556553 session = requests .Session ()
557554 prepared_request = session .prepare_request (request )
558555
559- for i in range (self .num_retries + 1 ):
560- try :
561- response = session .send (prepared_request )
562- status = response .status_code
563- rdata = response .content
564- dict_headers = dict (response .headers )
565- response_headers = {"responseHeaders" : dict_headers }
566- if 'x-rosetteapi-concurrency' in dict_headers :
567- if dict_headers ['x-rosetteapi-concurrency' ] != self .maxPoolSize :
568- self .maxPoolSize = dict_headers ['x-rosetteapi-concurrency' ]
569- self ._set_pool_size ()
570-
571- if status == 200 :
572- return rdata , status , response_headers
573- if status == 429 :
574- code = status
575- message = "{0} ({1})" .format (rdata , i )
576- time .sleep (self .connection_refresh_duration )
577- continue
578- if rdata is not None :
579- try :
580- the_json = _my_loads (rdata , response_headers )
581- if 'message' in the_json :
582- message = the_json ['message' ]
583- if "code" in the_json :
584- code = the_json ['code' ]
585- else :
586- code = status
587- raise RosetteException (code , message , url )
588-
589- except :
590- raise
591- except requests .exceptions .RequestException as e :
592- raise RosetteException (
593- e .message ,
594- "Unable to establish connection to the Rosette API server" ,
595- url )
556+ try :
557+ response = session .send (prepared_request )
558+ status = response .status_code
559+ rdata = response .content
560+ dict_headers = dict (response .headers )
561+ response_headers = {"responseHeaders" : dict_headers }
562+ if 'x-rosetteapi-concurrency' in dict_headers :
563+ if dict_headers ['x-rosetteapi-concurrency' ] != self .maxPoolSize :
564+ self .maxPoolSize = dict_headers ['x-rosetteapi-concurrency' ]
565+ self ._set_pool_size ()
566+
567+ if status == 200 :
568+ return rdata , status , response_headers
569+ if rdata is not None :
570+ try :
571+ the_json = _my_loads (rdata , response_headers )
572+ if 'message' in the_json :
573+ message = the_json ['message' ]
574+ if "code" in the_json :
575+ code = the_json ['code' ]
576+ else :
577+ code = status
578+ if not message :
579+ message = rdata
580+ raise RosetteException (code , message , url )
581+
582+ except :
583+ raise
584+ except requests .exceptions .RequestException as e :
585+ raise RosetteException (
586+ e .message ,
587+ "Unable to establish connection to the Rosette API server" ,
588+ url )
596589
597590 raise RosetteException (code , message , url )
598591
@@ -841,3 +834,11 @@ def text_embedding(self, parameters):
841834 @type parameters: L{DocumentParameters} or L{str}
842835 @return: A python dictionary containing the results of text embedding."""
843836 return EndpointCaller (self , "text-embedding" ).call (parameters )
837+
838+ def syntax_dependencies (self , parameters ):
839+ """
840+ Create an L{EndpointCaller} to identify the syntactic dependencies in the texts
841+ to which it is applied and call it.
842+ @type parameters: L{DocumentParameters} or L{str}
843+ @return: A python dictionary containing the results of syntactic dependencies identification"""
844+ return EndpointCaller (self , "syntax/dependencies" ).call (parameters )
0 commit comments