| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Classes and functions for generic network communication over HTTP.""" | 5 """Classes and functions for generic network communication over HTTP.""" |
| 6 | 6 |
| 7 import cookielib | 7 import cookielib |
| 8 import cStringIO as StringIO | 8 import cStringIO as StringIO |
| 9 import httplib | 9 import httplib |
| 10 import itertools | 10 import itertools |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 raise TimeoutError exception whenever there's no response from the server | 312 raise TimeoutError exception whenever there's no response from the server |
| 313 for more than |read_timeout| seconds. It can happen during any read | 313 for more than |read_timeout| seconds. It can happen during any read |
| 314 operation so once you pass non-None |read_timeout| be prepared to handle | 314 operation so once you pass non-None |read_timeout| be prepared to handle |
| 315 these exceptions in subsequent reads from the stream. | 315 these exceptions in subsequent reads from the stream. |
| 316 | 316 |
| 317 Returns a file-like object, where the response may be read from, or None | 317 Returns a file-like object, where the response may be read from, or None |
| 318 if it was unable to connect. If |stream| is False will read whole response | 318 if it was unable to connect. If |stream| is False will read whole response |
| 319 into memory buffer before returning file-like object that reads from this | 319 into memory buffer before returning file-like object that reads from this |
| 320 memory buffer. | 320 memory buffer. |
| 321 """ | 321 """ |
| 322 assert urlpath and urlpath[0] == '/' | 322 assert urlpath and urlpath[0] == '/', urlpath |
| 323 | 323 |
| 324 if data is not None: | 324 if data is not None: |
| 325 assert method in (None, 'POST', 'PUT') | 325 assert method in (None, 'POST', 'PUT') |
| 326 method = method or 'POST' | 326 method = method or 'POST' |
| 327 content_type = content_type or DEFAULT_CONTENT_TYPE | 327 content_type = content_type or DEFAULT_CONTENT_TYPE |
| 328 body = self.encode_request_body(data, content_type) | 328 body = self.encode_request_body(data, content_type) |
| 329 else: | 329 else: |
| 330 assert method in (None, 'GET') | 330 assert method in (None, 'GET') |
| 331 method = method or 'GET' | 331 method = method or 'GET' |
| 332 body = None | 332 body = None |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 attemp_obj = RetryAttempt(attempt, remaining) | 765 attemp_obj = RetryAttempt(attempt, remaining) |
| 766 yield attemp_obj | 766 yield attemp_obj |
| 767 if attemp_obj.skip_sleep: | 767 if attemp_obj.skip_sleep: |
| 768 continue | 768 continue |
| 769 # Only sleep if we are going to try again. | 769 # Only sleep if we are going to try again. |
| 770 if max_attempts and attempt != max_attempts - 1: | 770 if max_attempts and attempt != max_attempts - 1: |
| 771 remaining = (timeout - (current_time() - start)) if timeout else None | 771 remaining = (timeout - (current_time() - start)) if timeout else None |
| 772 if remaining is not None and remaining < 0: | 772 if remaining is not None and remaining < 0: |
| 773 break | 773 break |
| 774 sleep_before_retry(attempt, remaining) | 774 sleep_before_retry(attempt, remaining) |
| OLD | NEW |