diff options
author | Haibo Huang <hhb@google.com> | 2019-02-25 19:15:32 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-02-25 19:15:32 -0800 |
commit | 2f4eea998dae784f2c66396a73d525ba3f53bfb0 (patch) | |
tree | 8d036b85bcd46a445ab961acbea273539d570980 | |
parent | 75829912709cc54439cba0648317ad712ac9ad1d (diff) | |
parent | 555566ad4e194207753a5776a473691f4e30073b (diff) | |
download | httplib2-android10-c2f2-s1-release.tar.gz |
Upgrade python/httplib2 to v0.12.1 am: a3b3c868e6 am: 758333f2a3android-mainline-10.0.0_r9android-mainline-10.0.0_r7android-mainline-10.0.0_r5android-mainline-10.0.0_r4android-mainline-10.0.0_r10android-10.0.0_r9android-10.0.0_r8android-10.0.0_r7android-10.0.0_r45android-10.0.0_r44android-10.0.0_r43android-10.0.0_r42android-10.0.0_r41android-10.0.0_r40android-10.0.0_r39android-10.0.0_r38android-10.0.0_r37android-10.0.0_r36android-10.0.0_r35android-10.0.0_r34android-10.0.0_r33android-10.0.0_r32android-10.0.0_r31android-10.0.0_r30android-10.0.0_r29android-10.0.0_r28android-10.0.0_r27android-10.0.0_r26android-10.0.0_r25android-10.0.0_r24android-10.0.0_r23android-10.0.0_r22android-10.0.0_r21android-10.0.0_r20android-10.0.0_r19android-10.0.0_r18android-10.0.0_r16android-10.0.0_r15android-10.0.0_r14android-10.0.0_r13android-10.0.0_r12android10-qpr3-s1-releaseandroid10-qpr3-releaseandroid10-qpr2-s4-releaseandroid10-qpr2-s3-releaseandroid10-qpr2-s2-releaseandroid10-qpr2-s1-releaseandroid10-qpr2-releaseandroid10-qpr1-releaseandroid10-qpr1-mainline-releaseandroid10-qpr1-d-releaseandroid10-qpr1-c-s1-releaseandroid10-qpr1-c-releaseandroid10-qpr1-b-s1-releaseandroid10-qpr1-b-releaseandroid10-mainline-media-releaseandroid10-devandroid10-d4-s1-releaseandroid10-d4-releaseandroid10-c2f2-s2-releaseandroid10-c2f2-s1-releaseandroid10-c2f2-release
am: 555566ad4e
Change-Id: Ie4e6b40e71960b8c49b074226b33b2115f49d298
-rw-r--r-- | .travis.yml | 9 | ||||
-rw-r--r-- | CHANGELOG | 9 | ||||
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | python2/httplib2/__init__.py | 12 | ||||
-rw-r--r-- | python3/httplib2/__init__.py | 10 | ||||
-rwxr-xr-x | setup.py | 7 | ||||
-rw-r--r-- | tests/test_other.py | 26 |
7 files changed, 68 insertions, 11 deletions
diff --git a/.travis.yml b/.travis.yml index 8e0a165..57991d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -sudo: false language: python +dist: xenial cache: apt: true @@ -16,7 +16,7 @@ python: - 3.4 - 3.5 - 3.6 - - pypy + - 3.7 matrix: fast_finish: true install: pip install $pip_install_common 'codecov>=2.0.15' -r requirements-test.txt @@ -28,6 +28,11 @@ stages: jobs: include: - stage: test + python: pypy + dist: trusty + install: pip install $pip_install_common 'codecov>=2.0.15' -r requirements-test.txt + script: script/test -sv && codecov + - stage: test env: _=py2-pep8 python: 2.7 install: pip install -r requirements-test.txt @@ -1,3 +1,12 @@ +0.12.1 + + Catch socket timeouts and clear dead connection + https://github.com/httplib2/httplib2/issues/18 + https://github.com/httplib2/httplib2/pull/111 + + Officially support Python 3.7 (package metadata) + https://github.com/httplib2/httplib2/issues/123 + 0.12.0 Drop support for Python 3.3 @@ -7,12 +7,12 @@ third_party { } url { type: GIT - value: "https://github.com/httplib2/httplib2/" + value: "https://github.com/httplib2/httplib2.git" } - version: "v0.12.0" + version: "v0.12.1" last_upgrade_date { year: 2019 month: 2 - day: 1 + day: 21 } } diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py index b89f2fe..fee091d 100644 --- a/python2/httplib2/__init__.py +++ b/python2/httplib2/__init__.py @@ -19,7 +19,7 @@ __contributors__ = [ "Alex Yu", ] __license__ = "MIT" -__version__ = '0.12.0' +__version__ = '0.12.1' import base64 import calendar @@ -1924,6 +1924,8 @@ class Http(object): being and instance of the 'Response' class, the second being a string that contains the response entity body. """ + conn_key = '' + try: if headers is None: headers = {} @@ -2133,13 +2135,19 @@ class Http(object): cachekey, ) except Exception as e: + is_timeout = isinstance(e, socket.timeout) + if is_timeout: + conn = self.connections.pop(conn_key, None) + if conn: + conn.close() + if self.force_exception_to_status_code: if isinstance(e, HttpLib2ErrorWithResponse): response = e.response content = e.content response.status = 500 response.reason = str(e) - elif isinstance(e, socket.timeout): + elif is_timeout: content = "Request Timeout" response = Response( { diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py index b1b86f4..8b64c41 100644 --- a/python3/httplib2/__init__.py +++ b/python3/httplib2/__init__.py @@ -15,7 +15,7 @@ __contributors__ = [ "Alex Yu", ] __license__ = "MIT" -__version__ = '0.12.0' +__version__ = '0.12.1' import base64 import calendar @@ -1722,6 +1722,8 @@ The return value is a tuple of (response, content), the first being and instance of the 'Response' class, the second being a string that contains the response entity body. """ + conn_key = '' + try: if headers is None: headers = {} @@ -1924,6 +1926,12 @@ a string that contains the response entity body. cachekey, ) except Exception as e: + is_timeout = isinstance(e, socket.timeout) + if is_timeout: + conn = self.connections.pop(conn_key, None) + if conn: + conn.close() + if self.force_exception_to_status_code: if isinstance(e, HttpLib2ErrorWithResponse): response = e.response @@ -4,7 +4,7 @@ import setuptools.command.test import sys pkgdir = {"": "python%s" % sys.version_info[0]} -VERSION = '0.12.0' +VERSION = '0.12.1' # `python setup.py test` uses existing Python environment, no virtualenv, no pip. @@ -87,7 +87,7 @@ A comprehensive HTTP client library, ``httplib2`` supports many features left ou package_data={"httplib2": ["*.txt"]}, tests_require=read_requirements("requirements-test.txt"), cmdclass={"test": TestCommand}, - classifiers=( + classifiers=[ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", @@ -100,7 +100,8 @@ A comprehensive HTTP client library, ``httplib2`` supports many features left ou "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries", - ), + ], ) diff --git a/tests/test_other.py b/tests/test_other.py index f714c61..f87cfbd 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -108,6 +108,32 @@ def test_timeout_individual(): assert response.reason.startswith("Request Timeout") +def test_timeout_subsequent(): + class Handler(object): + number = 0 + + @classmethod + def handle(cls, request): + # request.number is always 1 because of + # the new socket connection each time + cls.number += 1 + if cls.number % 2 != 0: + time.sleep(0.6) + return tests.http_response_bytes(status=500) + return tests.http_response_bytes(status=200) + + http = httplib2.Http(timeout=0.5) + http.force_exception_to_status_code = True + + with tests.server_request(Handler.handle, request_count=2) as uri: + response, _ = http.request(uri) + assert response.status == 408 + assert response.reason.startswith("Request Timeout") + + response, _ = http.request(uri) + assert response.status == 200 + + def test_timeout_https(): c = httplib2.HTTPSConnectionWithTimeout("localhost", 80, timeout=47) assert 47 == c.timeout |