| OLD | NEW |
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be 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 httplib | 8 import httplib |
| 9 import itertools | 9 import itertools |
| 10 import json | 10 import json |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 # Content type -> function that encodes a request body. | 62 # Content type -> function that encodes a request body. |
| 63 CONTENT_ENCODERS = { | 63 CONTENT_ENCODERS = { |
| 64 URL_ENCODED_FORM_CONTENT_TYPE: | 64 URL_ENCODED_FORM_CONTENT_TYPE: |
| 65 urllib.urlencode, | 65 urllib.urlencode, |
| 66 JSON_CONTENT_TYPE: | 66 JSON_CONTENT_TYPE: |
| 67 lambda x: json.dumps(x, sort_keys=True, separators=(',', ':')), | 67 lambda x: json.dumps(x, sort_keys=True, separators=(',', ':')), |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 # Google Storage URL regular expression. | 71 # Google Storage URL regular expression. |
| 72 GS_STORAGE_HOST_URL_RE = re.compile(r'https://.*\.storage\.googleapis\.com') | 72 GS_STORAGE_HOST_URL_RE = re.compile(r'https://(.+\.)?storage\.googleapis\.com') |
| 73 | 73 |
| 74 # Global (for now) map: server URL (http://example.com) -> HttpService instance. | 74 # Global (for now) map: server URL (http://example.com) -> HttpService instance. |
| 75 # Used by get_http_service to cache HttpService instances. | 75 # Used by get_http_service to cache HttpService instances. |
| 76 _http_services = {} | 76 _http_services = {} |
| 77 _http_services_lock = threading.Lock() | 77 _http_services_lock = threading.Lock() |
| 78 | 78 |
| 79 # This lock ensures that user won't be confused with multiple concurrent | 79 # This lock ensures that user won't be confused with multiple concurrent |
| 80 # login prompts. | 80 # login prompts. |
| 81 _auth_lock = threading.Lock() | 81 _auth_lock = threading.Lock() |
| 82 | 82 |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 attemp_obj = RetryAttempt(attempt, remaining) | 802 attemp_obj = RetryAttempt(attempt, remaining) |
| 803 yield attemp_obj | 803 yield attemp_obj |
| 804 if attemp_obj.skip_sleep: | 804 if attemp_obj.skip_sleep: |
| 805 continue | 805 continue |
| 806 # Only sleep if we are going to try again. | 806 # Only sleep if we are going to try again. |
| 807 if max_attempts and attempt != max_attempts - 1: | 807 if max_attempts and attempt != max_attempts - 1: |
| 808 remaining = (timeout - (current_time() - start)) if timeout else None | 808 remaining = (timeout - (current_time() - start)) if timeout else None |
| 809 if remaining is not None and remaining < 0: | 809 if remaining is not None and remaining < 0: |
| 810 break | 810 break |
| 811 sleep_before_retry(attempt, remaining) | 811 sleep_before_retry(attempt, remaining) |
| OLD | NEW |