From adb491e498796293237f2252a5d8ba14e466b073 Mon Sep 17 00:00:00 2001 From: Mathias Seidler Date: Sun, 23 Feb 2020 07:30:29 +0100 Subject: [PATCH 1/5] Fix collections.abc imports for python 3.7. --- hyper/common/headers.py | 8 ++++++-- hyper/http11/connection.py | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hyper/common/headers.py b/hyper/common/headers.py index 655a591a..b2990ddb 100644 --- a/hyper/common/headers.py +++ b/hyper/common/headers.py @@ -5,12 +5,16 @@ Contains hyper's structures for storing and working with HTTP headers. """ -import collections +try: + from collections.abc import MutableMapping +except ImportError: # pragma: no cover + # Python 2.7 compatibility + from collections import MutableMapping from hyper.common.util import to_bytestring, to_bytestring_tuple -class HTTPHeaderMap(collections.MutableMapping): +class HTTPHeaderMap(MutableMapping): """ A structure that contains HTTP headers. diff --git a/hyper/http11/connection.py b/hyper/http11/connection.py index 4311d307..b7162dc3 100644 --- a/hyper/http11/connection.py +++ b/hyper/http11/connection.py @@ -10,9 +10,12 @@ import socket import base64 -from collections import Iterable, Mapping +try: + from collections.abc import Iterable, Mapping +except ImportError: # pragma: no cover + # Python 2.7 compatibility + from collections import Iterable, Mapping -import collections from hyperframe.frame import SettingsFrame from .response import HTTP11Response @@ -390,7 +393,7 @@ def _send_body(self, body, body_type): return # Iterables that set a specific content length. - elif isinstance(body, collections.Iterable): + elif isinstance(body, Iterable): for item in body: try: self._sock.send(item) From 47c520b91a27fcbf3d7e3fd1fe1da69be764df6d Mon Sep 17 00:00:00 2001 From: Mathias Seidler Date: Sun, 23 Feb 2020 08:18:15 +0100 Subject: [PATCH 2/5] Fix h2.settings.SettingCodes usage. --- hyper/http20/connection.py | 4 ++-- test/test_hyper.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hyper/http20/connection.py b/hyper/http20/connection.py index b8be292b..d2805a09 100644 --- a/hyper/http20/connection.py +++ b/hyper/http20/connection.py @@ -403,7 +403,7 @@ def _connect_upgrade(self, sock): with self._conn as conn: conn.initiate_upgrade_connection() conn.update_settings( - {h2.settings.ENABLE_PUSH: int(self._enable_push)} + {h2.settings.SettingCodes.ENABLE_PUSH: int(self._enable_push)} ) self._send_outstanding_data() @@ -424,7 +424,7 @@ def _send_preamble(self): with self._conn as conn: conn.initiate_connection() conn.update_settings( - {h2.settings.ENABLE_PUSH: int(self._enable_push)} + {h2.settings.SettingCodes.ENABLE_PUSH: int(self._enable_push)} ) self._send_outstanding_data() diff --git a/test/test_hyper.py b/test/test_hyper.py index b826c63c..df30ee70 100644 --- a/test/test_hyper.py +++ b/test/test_hyper.py @@ -766,7 +766,8 @@ def test_incrementing_window_after_close(self): # the default max frame size (16,384 bytes). That will, on the third # frame, trigger the processing to increment the flow control window, # which should then not happen. - f = SettingsFrame(0, settings={h2.settings.INITIAL_WINDOW_SIZE: 100}) + f = SettingsFrame(0, settings={ + h2.settings.SettingCodes.INITIAL_WINDOW_SIZE: 100}) c = HTTP20Connection('www.google.com') c._sock = DummySocket() From b359887ee4e27234f2c1393c6087f03dc3305a8b Mon Sep 17 00:00:00 2001 From: Mathias Seidler Date: Sun, 23 Feb 2020 08:51:22 +0100 Subject: [PATCH 3/5] Correct requests example. --- docs/source/quickstart.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst index 6ad44ec1..008d6749 100644 --- a/docs/source/quickstart.rst +++ b/docs/source/quickstart.rst @@ -135,8 +135,8 @@ Using ``hyper`` with requests is super simple:: >>> import requests >>> from hyper.contrib import HTTP20Adapter >>> s = requests.Session() - >>> s.mount('https://http2bin.org', HTTP20Adapter()) - >>> r = s.get('https://http2bin.org/get') + >>> s.mount('https://', HTTP20Adapter()) + >>> r = s.get('https://httpbin.org/get') >>> print(r.status_code) 200 From 2fc8b6442213806e6b5727151da49f66e69b92e8 Mon Sep 17 00:00:00 2001 From: Mathias Seidler Date: Sun, 23 Feb 2020 08:59:50 +0100 Subject: [PATCH 4/5] Fix flake8 basestring complaints. --- hyper/tls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyper/tls.py b/hyper/tls.py index 422b001c..39fa8e88 100644 --- a/hyper/tls.py +++ b/hyper/tls.py @@ -122,8 +122,8 @@ def init_context(cert_path=None, cert=None, cert_password=None): if cert is not None: try: - basestring - except NameError: + from builtins import basestring + except ImportError: basestring = (str, bytes) if not isinstance(cert, basestring): context.load_cert_chain(cert[0], cert[1], cert_password) From 9318d1211780f98714707a819b564d4c85f6b5fa Mon Sep 17 00:00:00 2001 From: Mathias Seidler Date: Sun, 23 Feb 2020 09:10:34 +0100 Subject: [PATCH 5/5] Fix pytest-xdist>=v1.28.0 would require pytest>=4.4.0. But travis only has pytest 4.3.1. --- test_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_requirements.txt b/test_requirements.txt index cae2fbc6..e0941764 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,5 +1,5 @@ pytest>=3.0 -pytest-xdist +pytest-xdist<=1.27.0 pytest-cov requests mock