Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: cms/translations/xtm/xtm_api.py

Issue 29968558: Issue 7037 - [XTM Integration] Make REST API url customizable
Left Patch Set: Removed unnecessary print statements Created Sept. 17, 2019, 12:24 p.m.
Right Patch Set: Merged with changes from 7039 Created Sept. 17, 2019, 1:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cms/translations/xtm/utils.py ('k') | tests/test_xtm_api.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 else: 224 else:
225 # Hacky way to go around 415 error code 225 # Hacky way to go around 415 error code
226 files_to_upload = {'a': 'b'} 226 files_to_upload = {'a': 'b'}
227 227
228 url = urlparse.urljoin(self.base_url, self._UrlPaths.CREATE) 228 url = urlparse.urljoin(self.base_url, self._UrlPaths.CREATE)
229 229
230 response = self._execute(url, data=data, files=files_to_upload) 230 response = self._execute(url, data=data, files=files_to_upload)
231 231
232 if response.status_code != self._SuccessCodes.CREATE: 232 if response.status_code != self._SuccessCodes.CREATE:
233 # The creation was not successful 233 # The creation was not successful
234 print('Raising exception')
235 raise XTMCloudException(response.status_code, 234 raise XTMCloudException(response.status_code,
236 response.text.decode('utf-8'), 235 response.text.decode('utf-8'),
237 'creating job') 236 'creating job')
238 237
239 data = json.loads(response.text.encode('utf-8')) 238 data = json.loads(response.text.encode('utf-8'))
240 239
241 return data['projectId'], data['jobs'] 240 return data['projectId'], data['jobs']
242 241
243 def upload_files(self, files, project_id, overwrite=True): 242 def upload_files(self, files, project_id, overwrite=True):
244 """Upload a set of files to a project. 243 """Upload a set of files to a project.
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 headers = {'content-type': 'application/json'} 469 headers = {'content-type': 'application/json'}
471 470
472 response = requests.post(url, data=request_body, headers=headers) 471 response = requests.post(url, data=request_body, headers=headers)
473 472
474 if response.status_code == 200: 473 if response.status_code == 200:
475 return json.loads(response.text)['token'].encode() 474 return json.loads(response.text)['token'].encode()
476 475
477 raise XTMCloudException(response.status_code, 476 raise XTMCloudException(response.status_code,
478 response.text.encode('utf-8'), 477 response.text.encode('utf-8'),
479 'generating token') 478 'generating token')
LEFTRIGHT

Powered by Google App Engine
This is Rietveld