3131_APPLICATION_JSON = 'application/json'
3232_BINDING_LANGUAGE = 'python'
3333_BINDING_VERSION = '1.30.0'
34- _CONCURRENCY_HEADER = 'x-rosetteapi-concurrency'
35- _CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-'
36- _CUSTOM_HEADER_PATTERN = re .compile ('^' + _CUSTOM_HEADER_PREFIX )
34+ # TODO Remove legacies in future release
35+ _LEGACY_CONCURRENCY_HEADER = 'x-rosetteapi-concurrency'
36+ _CONCURRENCY_HEADER = 'x-babelstreetapi-concurrency'
37+ _LEGACY_CUSTOM_HEADER_PREFIX = 'X-RosetteAPI-'
38+ _CUSTOM_HEADER_PREFIX = "X-BabelStreetAPI-"
39+ _CUSTOM_HEADER_PATTERN = re .compile ('^(:?' + _CUSTOM_HEADER_PREFIX + '|' + _LEGACY_CUSTOM_HEADER_PREFIX + ')' )
3740_GZIP_BYTEARRAY = bytearray ([0x1F , 0x8b , 0x08 ])
3841
3942_ISPY3 = sys .version_info [0 ] == 3
@@ -413,12 +416,15 @@ def __finish_result(self, response, ename):
413416 complaint_url = ename + " " + self .suburl
414417
415418 raise RosetteException (code , complaint_url +
416- " : failed to communicate with Analytics" , msg )
419+ " : failed to communicate with Babel Street Analytics API " , msg )
417420
418421 def __set_headers (self ):
419422 headers = {'Accept' : _APPLICATION_JSON ,
420423 _CUSTOM_HEADER_PREFIX + 'Binding' : _BINDING_LANGUAGE ,
421- _CUSTOM_HEADER_PREFIX + 'Binding-Version' : _BINDING_VERSION }
424+ _CUSTOM_HEADER_PREFIX + 'Binding-Version' : _BINDING_VERSION ,
425+ #TODO Remove in future release
426+ _LEGACY_CUSTOM_HEADER_PREFIX + 'Binding' : _BINDING_LANGUAGE ,
427+ _LEGACY_CUSTOM_HEADER_PREFIX + 'Binding-Version' : _BINDING_VERSION }
422428
423429 custom_headers = self .api .get_custom_headers ()
424430 if custom_headers is not None :
@@ -427,12 +433,13 @@ def __set_headers(self):
427433 headers [key ] = custom_headers [key ]
428434 else :
429435 raise RosetteException ("badHeader" ,
430- "Custom header name must begin with \" " + _CUSTOM_HEADER_PREFIX + "\" " ,
436+ "Custom header name must begin with \" " + _CUSTOM_HEADER_PREFIX + "\" or \" "
437+ + _LEGACY_CUSTOM_HEADER_PREFIX + "\" " ,
431438 key )
432439 self .api .clear_custom_headers ()
433440
434441 if self .debug :
435- headers [_CUSTOM_HEADER_PREFIX + 'Devel' ] = 'true'
442+ headers [_LEGACY_CUSTOM_HEADER_PREFIX + 'Devel' ] = 'true'
436443
437444 if self .user_key is not None :
438445 headers ["X-BabelStreetAPI-Key" ] = self .user_key
@@ -537,7 +544,7 @@ def call(self, parameters, paramtype=None):
537544 _my_loads (rdata , response_headers ), status )
538545 else :
539546 if self .debug :
540- headers [_CUSTOM_HEADER_PREFIX + 'Devel' ] = 'true'
547+ headers [_LEGACY_CUSTOM_HEADER_PREFIX + 'Devel' ] = 'true'
541548 self .logger .info ('operate: ' + url )
542549 headers ['Accept' ] = _APPLICATION_JSON
543550 headers ['Accept-Encoding' ] = "gzip"
@@ -584,7 +591,7 @@ def __init__(
584591 self .url_parameters = {}
585592 self .max_pool_size = 1
586593 self .session = requests .Session ()
587- self .user_agent_string = 'RosetteAPIPython /' + _BINDING_VERSION + '/' + platform .python_version ()
594+ self .user_agent_string = 'Babel-Street-Analytics-API-Python /' + _BINDING_VERSION + '/' + platform .python_version ()
588595
589596 self .morphology_output = {
590597 'LEMMAS' : 'lemmas' ,
@@ -646,8 +653,12 @@ def set_pool_size(self, new_pool_size):
646653 self .session .mount ('http://' , adapter ) # NOSONAR
647654
648655 def __adjust_concurrency (self , dict_headers ):
649- if _CONCURRENCY_HEADER in dict_headers and dict_headers [_CONCURRENCY_HEADER ] != self .max_pool_size :
650- self .set_pool_size (dict_headers [_CONCURRENCY_HEADER ])
656+ if _CONCURRENCY_HEADER in dict_headers :
657+ if dict_headers [_CONCURRENCY_HEADER ] != self .max_pool_size :
658+ self .set_pool_size (dict_headers [_CONCURRENCY_HEADER ])
659+ elif _LEGACY_CONCURRENCY_HEADER in dict_headers :
660+ if dict_headers [_LEGACY_CONCURRENCY_HEADER ] != self .max_pool_size :
661+ self .set_pool_size (dict_headers [_LEGACY_CONCURRENCY_HEADER ])
651662
652663 def _make_request (self , operation , url , data , headers ):
653664 """
0 commit comments