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 29 matching lines...) Expand all Loading... |
40 self.email = email | 40 self.email = email |
41 self.password = password | 41 self.password = password |
42 if email and password: | 42 if email and password: |
43 get_creds = lambda: (email, password) | 43 get_creds = lambda: (email, password) |
44 self.rpc_server = upload.HttpRpcServer( | 44 self.rpc_server = upload.HttpRpcServer( |
45 self.url, | 45 self.url, |
46 get_creds, | 46 get_creds, |
47 extra_headers=extra_headers or {}) | 47 extra_headers=extra_headers or {}) |
48 else: | 48 else: |
49 self.rpc_server = upload.GetRpcServer(url, email) | 49 self.rpc_server = upload.GetRpcServer(url, email) |
| 50 # If email is given as an empty string, then assume we want to make |
| 51 # requests that do not need authentication. Bypass authentication by |
| 52 # setting the flag to True. |
| 53 if email == '': |
| 54 self.rpc_server.authenticated = True |
| 55 |
50 self._xsrf_token = None | 56 self._xsrf_token = None |
51 self._xsrf_token_time = None | 57 self._xsrf_token_time = None |
52 | 58 |
53 def xsrf_token(self): | 59 def xsrf_token(self): |
54 if (not self._xsrf_token_time or | 60 if (not self._xsrf_token_time or |
55 (time.time() - self._xsrf_token_time) > 30*60): | 61 (time.time() - self._xsrf_token_time) > 30*60): |
56 self._xsrf_token_time = time.time() | 62 self._xsrf_token_time = time.time() |
57 self._xsrf_token = self.get( | 63 self._xsrf_token = self.get( |
58 '/xsrf_token', | 64 '/xsrf_token', |
59 extra_headers={'X-Requesting-XSRF-Token': '1'}) | 65 extra_headers={'X-Requesting-XSRF-Token': '1'}) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 if not 'Name or service not known' in e.reason: | 342 if not 'Name or service not known' in e.reason: |
337 # Usually internal GAE flakiness. | 343 # Usually internal GAE flakiness. |
338 raise | 344 raise |
339 # If reaching this line, loop again. Uses a small backoff. | 345 # If reaching this line, loop again. Uses a small backoff. |
340 time.sleep(1+maxtries*2) | 346 time.sleep(1+maxtries*2) |
341 finally: | 347 finally: |
342 upload.ErrorExit = old_error_exit | 348 upload.ErrorExit = old_error_exit |
343 | 349 |
344 # DEPRECATED. | 350 # DEPRECATED. |
345 Send = get | 351 Send = get |
OLD | NEW |