OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Defines class Rietveld to easily access a rietveld instance. | 5 """Defines class Rietveld to easily access a rietveld instance. |
6 | 6 |
7 Security implications: | 7 Security implications: |
8 | 8 |
9 The following hypothesis are made: | 9 The following hypothesis are made: |
10 - Rietveld enforces: | 10 - Rietveld enforces: |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 def get(self, request_path, **kwargs): | 350 def get(self, request_path, **kwargs): |
351 kwargs.setdefault('payload', None) | 351 kwargs.setdefault('payload', None) |
352 return self._send(request_path, **kwargs) | 352 return self._send(request_path, **kwargs) |
353 | 353 |
354 def post(self, request_path, data, **kwargs): | 354 def post(self, request_path, data, **kwargs): |
355 ctype, body = upload.EncodeMultipartFormData(data, []) | 355 ctype, body = upload.EncodeMultipartFormData(data, []) |
356 return self._send(request_path, payload=body, content_type=ctype, **kwargs) | 356 return self._send(request_path, payload=body, content_type=ctype, **kwargs) |
357 | 357 |
358 def _send(self, request_path, **kwargs): | 358 def _send(self, request_path, **kwargs): |
359 """Sends a POST/GET to Rietveld. Returns the response body.""" | 359 """Sends a POST/GET to Rietveld. Returns the response body.""" |
| 360 logging.debug('POSTing to %s, args %s.', request_path, kwargs) |
360 try: | 361 try: |
361 # Sadly, upload.py calls ErrorExit() which does a sys.exit(1) on HTTP | 362 # Sadly, upload.py calls ErrorExit() which does a sys.exit(1) on HTTP |
362 # 500 in AbstractRpcServer.Send(). | 363 # 500 in AbstractRpcServer.Send(). |
363 old_error_exit = upload.ErrorExit | 364 old_error_exit = upload.ErrorExit |
364 def trap_http_500(msg): | 365 def trap_http_500(msg): |
365 """Converts an incorrect ErrorExit() call into a HTTPError exception.""" | 366 """Converts an incorrect ErrorExit() call into a HTTPError exception.""" |
366 m = re.search(r'(50\d) Server Error', msg) | 367 m = re.search(r'(50\d) Server Error', msg) |
367 if m: | 368 if m: |
368 # Fake an HTTPError exception. Cheezy. :( | 369 # Fake an HTTPError exception. Cheezy. :( |
369 raise urllib2.HTTPError(request_path, m.group(1), msg, None, None) | 370 raise urllib2.HTTPError(request_path, m.group(1), msg, None, None) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 if not messages: | 440 if not messages: |
440 # Assumes self._lookup uses deepcopy. | 441 # Assumes self._lookup uses deepcopy. |
441 del data['messages'] | 442 del data['messages'] |
442 return data | 443 return data |
443 | 444 |
444 def get_patchset_properties(self, issue, patchset): | 445 def get_patchset_properties(self, issue, patchset): |
445 return self._lookup( | 446 return self._lookup( |
446 'get_patchset_properties', | 447 'get_patchset_properties', |
447 (issue, patchset), | 448 (issue, patchset), |
448 super(CachingRietveld, self).get_patchset_properties) | 449 super(CachingRietveld, self).get_patchset_properties) |
OLD | NEW |