| 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 15 matching lines...) Expand all Loading... |
| 26 from third_party.rietveld import upload | 26 from third_party.rietveld import upload |
| 27 | 27 |
| 28 from utils import zip_package | 28 from utils import zip_package |
| 29 | 29 |
| 30 # Hack out upload logging.info() | 30 # Hack out upload logging.info() |
| 31 upload.logging = logging.getLogger('upload') | 31 upload.logging = logging.getLogger('upload') |
| 32 # Mac pylint choke on this line. | 32 # Mac pylint choke on this line. |
| 33 upload.logging.setLevel(logging.WARNING) # pylint: disable=E1103 | 33 upload.logging.setLevel(logging.WARNING) # pylint: disable=E1103 |
| 34 | 34 |
| 35 | 35 |
| 36 # TODO(vadimsh): Remove this once we don't have to support python 2.6 anymore. |
| 37 def monkey_patch_httplib(): |
| 38 """Patch httplib.HTTPConnection to have '_tunnel_host' attribute. |
| 39 |
| 40 'requests' library (>= v2) accesses 'HTTPConnection._tunnel_host' attribute |
| 41 added only in python 2.6.3. This function patches HTTPConnection to have it |
| 42 on python 2.6.2 as well. |
| 43 """ |
| 44 conn = httplib.HTTPConnection('example.com') |
| 45 if not hasattr(conn, '_tunnel_host'): |
| 46 httplib.HTTPConnection._tunnel_host = None |
| 47 monkey_patch_httplib() |
| 48 |
| 49 |
| 36 # Big switch that controls what API to use to make HTTP requests. | 50 # Big switch that controls what API to use to make HTTP requests. |
| 37 # It's temporary here to simplify benchmarking of old vs new implementation. | 51 # It's temporary here to simplify benchmarking of old vs new implementation. |
| 38 USE_REQUESTS_LIB = True | 52 USE_REQUESTS_LIB = True |
| 39 | 53 |
| 40 # The name of the key to store the count of url attempts. | 54 # The name of the key to store the count of url attempts. |
| 41 COUNT_KEY = 'UrlOpenAttempt' | 55 COUNT_KEY = 'UrlOpenAttempt' |
| 42 | 56 |
| 43 # Default maximum number of attempts to trying opening a url before aborting. | 57 # Default maximum number of attempts to trying opening a url before aborting. |
| 44 URL_OPEN_MAX_ATTEMPTS = 30 | 58 URL_OPEN_MAX_ATTEMPTS = 30 |
| 45 | 59 |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 attemp_obj = RetryAttempt(attempt, remaining) | 791 attemp_obj = RetryAttempt(attempt, remaining) |
| 778 yield attemp_obj | 792 yield attemp_obj |
| 779 if attemp_obj.skip_sleep: | 793 if attemp_obj.skip_sleep: |
| 780 continue | 794 continue |
| 781 # Only sleep if we are going to try again. | 795 # Only sleep if we are going to try again. |
| 782 if max_attempts and attempt != max_attempts - 1: | 796 if max_attempts and attempt != max_attempts - 1: |
| 783 remaining = (timeout - (current_time() - start)) if timeout else None | 797 remaining = (timeout - (current_time() - start)) if timeout else None |
| 784 if remaining is not None and remaining < 0: | 798 if remaining is not None and remaining < 0: |
| 785 break | 799 break |
| 786 sleep_before_retry(attempt, remaining) | 800 sleep_before_retry(attempt, remaining) |
| OLD | NEW |