@@ -47,7 +47,8 @@ def get(self, key):
4747class CDSHandler (object ):
4848 """Handles communication with the Content Delivery Service."""
4949
50- def __init__ (self , configured_languages , token , secret = None , host = TRANSIFEX_CDS_HOST ):
50+ def __init__ (self , configured_languages , token , secret = None ,
51+ host = TRANSIFEX_CDS_HOST ):
5152 """Constructor.
5253
5354 :param list configured_languages: a list of language codes for the
@@ -72,10 +73,13 @@ def fetch_languages(self):
7273 languages = []
7374
7475 try :
75- response = requests .get (
76- self .host + cds_url ,
77- headers = self ._get_headers (),
78- )
76+ last_response_status = 202
77+ while last_response_status == 202 :
78+ response = requests .get (
79+ self .host + cds_url ,
80+ headers = self ._get_headers (),
81+ )
82+ last_response_status = response .status_code
7983
8084 if not response .ok :
8185 logger .error (
@@ -89,18 +93,16 @@ def fetch_languages(self):
8993 languages = json_content ['data' ]
9094
9195 except (KeyError , ValueError ):
92- # Compatibility with python2.7 where `JSONDecodeError` doesn't exist
96+ # Compatibility with python2.7 where `JSONDecodeError` doesn't
97+ # exist
9398 logger .error (
9499 'Error retrieving languages from CDS: Malformed response' )
95100 except requests .ConnectionError :
96101 logger .error (
97102 'Error retrieving languages from CDS: ConnectionError' )
98103 except Exception as e :
99- logger .error (
100- 'Error retrieving languages from CDS: UnknownError (`{}`)' .format (
101- str (e )
102- )
103- )
104+ logger .error ('Error retrieving languages from CDS: UnknownError '
105+ '(`{}`)' .format (str (e )))
104106
105107 return languages
106108
@@ -128,12 +130,16 @@ def fetch_translations(self, language_code=None):
128130 set (self .configured_language_codes ):
129131
130132 try :
131- response = requests .get (
132- self .host + cds_url .format (language_code = language_code ),
133- headers = self ._get_headers (
134- etag = self .etags .get (language_code )
133+ last_response_status = 202
134+ while last_response_status == 202 :
135+ response = requests .get (
136+ (self .host +
137+ cds_url .format (language_code = language_code )),
138+ headers = self ._get_headers (
139+ etag = self .etags .get (language_code )
140+ )
135141 )
136- )
142+ last_response_status = response . status_code
137143
138144 if not response .ok :
139145 logger .error (
@@ -155,19 +161,19 @@ def fetch_translations(self, language_code=None):
155161 )
156162
157163 except (KeyError , ValueError ):
158- # Compatibility with python2.7 where `JSONDecodeError` doesn't exist
159- logger .error (
160- 'Error retrieving translations from CDS: Malformed response' ) # pragma no cover
164+ # Compatibility with python2.7 where `JSONDecodeError` doesn't
165+ # exist
166+ logger .error ('Error retrieving translations from CDS: '
167+ 'Malformed response' ) # pragma no cover
161168 translations [language_code ] = (False , {}) # pragma no cover
162169 except requests .ConnectionError :
163170 logger .error (
164171 'Error retrieving translations from CDS: ConnectionError' )
165172 translations [language_code ] = (False , {})
166173 except Exception as e :
167174 logger .error (
168- 'Error retrieving translations from CDS: UnknownError (`{}`)' .format (
169- str (e )
170- )
175+ 'Error retrieving translations from CDS: UnknownError '
176+ '(`{}`)' .format (str (e ))
171177 ) # pragma no cover
172178 translations [language_code ] = (False , {})
173179
@@ -176,19 +182,17 @@ def fetch_translations(self, language_code=None):
176182 def push_source_strings (self , strings , purge = False ):
177183 """Push source strings to CDS.
178184
179- :param list(SourceString) strings: a list of `SourceString` objects holding
180- source strings
181- :param bool purge: True deletes destination source content not included in
182- pushed content.
183- False appends the pushed content to destination source
184- content.
185+ :param list(SourceString) strings: a list of `SourceString` objects
186+ holding source strings
187+ :param bool purge: True deletes destination source content not included
188+ in pushed content. False appends the pushed content to destination
189+ source content.
185190 :return: the HTTP response object
186191 :rtype: requests.Response
187192 """
188193 if not self .secret :
189- raise Exception (
190- 'You need to use `TRANSIFEX_SECRET` when pushing source content'
191- )
194+ raise Exception ('You need to use `TRANSIFEX_SECRET` when pushing '
195+ 'source content' )
192196
193197 cds_url = TRANSIFEX_CDS_URLS ['PUSH_SOURCE_STRINGS' ]
194198
@@ -208,11 +212,8 @@ def push_source_strings(self, strings, purge=False):
208212 logger .error (
209213 'Error pushing source strings to CDS: ConnectionError' )
210214 except Exception as e :
211- logger .error (
212- 'Error pushing source strings to CDS: UnknownError (`{}`)' .format (
213- str (e )
214- )
215- )
215+ logger .error ('Error pushing source strings to CDS: UnknownError '
216+ '(`{}`)' .format (str (e )))
216217
217218 return response
218219
0 commit comments