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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 if (not self._xsrf_token_time or | 63 if (not self._xsrf_token_time or |
64 (time.time() - self._xsrf_token_time) > 30*60): | 64 (time.time() - self._xsrf_token_time) > 30*60): |
65 self._xsrf_token_time = time.time() | 65 self._xsrf_token_time = time.time() |
66 self._xsrf_token = self.get( | 66 self._xsrf_token = self.get( |
67 '/xsrf_token', | 67 '/xsrf_token', |
68 extra_headers={'X-Requesting-XSRF-Token': '1'}) | 68 extra_headers={'X-Requesting-XSRF-Token': '1'}) |
69 return self._xsrf_token | 69 return self._xsrf_token |
70 | 70 |
71 def get_pending_issues(self): | 71 def get_pending_issues(self): |
72 """Returns an array of dict of all the pending issues on the server.""" | 72 """Returns an array of dict of all the pending issues on the server.""" |
73 return json.loads(self.get( | 73 # TODO: Convert this to use Rietveld::search(), defined below. |
74 '/search?format=json&commit=2&closed=3&keys_only=True&limit=1000') | 74 return json.loads( |
75 )['results'] | 75 self.get('/search?format=json&commit=2&closed=3&' |
| 76 'keys_only=True&limit=1000&order=__key__'))['results'] |
76 | 77 |
77 def close_issue(self, issue): | 78 def close_issue(self, issue): |
78 """Closes the Rietveld issue for this changelist.""" | 79 """Closes the Rietveld issue for this changelist.""" |
79 logging.info('closing issue %d' % issue) | 80 logging.info('closing issue %d' % issue) |
80 self.post("/%d/close" % issue, [('xsrf_token', self.xsrf_token())]) | 81 self.post("/%d/close" % issue, [('xsrf_token', self.xsrf_token())]) |
81 | 82 |
82 def get_description(self, issue): | 83 def get_description(self, issue): |
83 """Returns the issue's description.""" | 84 """Returns the issue's description.""" |
84 return self.get('/%d/description' % issue) | 85 return self.get('/%d/description' % issue) |
85 | 86 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 if not 'Name or service not known' in e.reason: | 388 if not 'Name or service not known' in e.reason: |
388 # Usually internal GAE flakiness. | 389 # Usually internal GAE flakiness. |
389 raise | 390 raise |
390 # If reaching this line, loop again. Uses a small backoff. | 391 # If reaching this line, loop again. Uses a small backoff. |
391 time.sleep(1+maxtries*2) | 392 time.sleep(1+maxtries*2) |
392 finally: | 393 finally: |
393 upload.ErrorExit = old_error_exit | 394 upload.ErrorExit = old_error_exit |
394 | 395 |
395 # DEPRECATED. | 396 # DEPRECATED. |
396 Send = get | 397 Send = get |
OLD | NEW |