| 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 28 matching lines...) Expand all Loading... |
| 39 # email and the cookie. | 39 # email and the cookie. |
| 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) | |
| 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 == '': | 49 if email == '': |
| 54 self.rpc_server.authenticated = True | 50 get_creds = lambda: (email, None) |
| 51 self.rpc_server = upload.HttpRpcServer(url, get_creds) |
| 52 else: |
| 53 self.rpc_server = upload.GetRpcServer(url, email) |
| 55 | 54 |
| 56 self._xsrf_token = None | 55 self._xsrf_token = None |
| 57 self._xsrf_token_time = None | 56 self._xsrf_token_time = None |
| 58 | 57 |
| 59 def xsrf_token(self): | 58 def xsrf_token(self): |
| 60 if (not self._xsrf_token_time or | 59 if (not self._xsrf_token_time or |
| 61 (time.time() - self._xsrf_token_time) > 30*60): | 60 (time.time() - self._xsrf_token_time) > 30*60): |
| 62 self._xsrf_token_time = time.time() | 61 self._xsrf_token_time = time.time() |
| 63 self._xsrf_token = self.get( | 62 self._xsrf_token = self.get( |
| 64 '/xsrf_token', | 63 '/xsrf_token', |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 if not 'Name or service not known' in e.reason: | 341 if not 'Name or service not known' in e.reason: |
| 343 # Usually internal GAE flakiness. | 342 # Usually internal GAE flakiness. |
| 344 raise | 343 raise |
| 345 # If reaching this line, loop again. Uses a small backoff. | 344 # If reaching this line, loop again. Uses a small backoff. |
| 346 time.sleep(1+maxtries*2) | 345 time.sleep(1+maxtries*2) |
| 347 finally: | 346 finally: |
| 348 upload.ErrorExit = old_error_exit | 347 upload.ErrorExit = old_error_exit |
| 349 | 348 |
| 350 # DEPRECATED. | 349 # DEPRECATED. |
| 351 Send = get | 350 Send = get |
| OLD | NEW |