Support HTTPCore 0.13 (#1588)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Support HTTPCore 0.13 * Update httpcore minimum version * Call into 'handle_async_request', not 'arequest' * Drop unintentional commit * Update tests
authored by Tom Christie · committed by GitHub · parent 2d57104 · Browse files · 3 files·+15 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−23 removed
- tests:+5 added−3 removed
- other:+10 added−20 removed
Provenance
- Commit
d98e9e7- Tree
7f58c01- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
2d57104
3 files changed+15 added−23 removed
modified:httpx/_transports/default.py+9 added-19 removed
76 unmodified lines77 message = str(exc)78 raise mapped_exc(message) from exc79 80 81-def ensure_http_version_reason_phrase_as_bytes(extensions: dict) -> None:82- # From HTTPX 0.18 onwards we're treating the "reason_phrase" and "http_version"83- # extensions as bytes, in order to be more precise. Also we're using the84- # "reason_phrase" key in preference to "reason", in order to match properly85- # with the HTTP spec naming.86- # HTTPCore 0.12 does not yet use these same conventions for the extensions,87- # so we bridge between the two styles for now.88- if "reason" in extensions:89- extensions["reason_phrase"] = extensions.pop("reason").encode("ascii")90- if "http_version" in extensions:91- extensions["http_version"] = extensions["http_version"].encode("ascii")92-93-81 HTTPCORE_EXC_MAP = {82 httpcore.TimeoutException: TimeoutException,83 httpcore.ConnectTimeout: ConnectTimeout,84 httpcore.ReadTimeout: ReadTimeout,89 unmodified lines174 ) -> typing.Tuple[175 int, typing.List[typing.Tuple[bytes, bytes]], SyncByteStream, dict176 ]:177 with map_httpcore_exceptions():191- status_code, headers, byte_stream, extensions = self._pool.request(178+ status_code, headers, byte_stream, extensions = self._pool.handle_request(179 method=method,180 url=url,181 headers=headers,182 stream=httpcore.IteratorByteStream(iter(stream)),196- ext=extensions,183+ extensions=extensions,184 )185 199- ensure_http_version_reason_phrase_as_bytes(extensions)186 stream = ResponseStream(byte_stream)187 188 return status_code, headers, stream, extensions189 78 unmodified lines268 ) -> typing.Tuple[269 int, typing.List[typing.Tuple[bytes, bytes]], AsyncByteStream, dict270 ]:271 with map_httpcore_exceptions():286- status_code, headers, byte_stream, extensions = await self._pool.arequest(272+ (273+ status_code,274+ headers,275+ byte_stream,276+ extensions,277+ ) = await self._pool.handle_async_request(278 method=method,279 url=url,280 headers=headers,281 stream=httpcore.AsyncIteratorByteStream(stream.__aiter__()),291- ext=extensions,282+ extensions=extensions,283 )284 294- ensure_http_version_reason_phrase_as_bytes(extensions)285 stream = AsyncResponseStream(byte_stream)286 287 return status_code, headers, stream, extensions288 2 unmodified linesmodified:tests/test_exceptions.py+5 added-3 removed
44 unmodified lines45 46 def close(self):47 raise httpcore.CloseError()48 49- with mock.patch("httpcore.SyncConnectionPool.request", side_effect=connect_failed):49+ with mock.patch(50+ "httpcore.SyncConnectionPool.handle_request", side_effect=connect_failed51+ ):52 with pytest.raises(httpx.ConnectError):53 httpx.get(server.url)54 55 with mock.patch(54- "httpcore.SyncConnectionPool.request",56+ "httpcore.SyncConnectionPool.handle_request",57 return_value=(200, [], TimeoutStream(), {}),58 ):59 with pytest.raises(httpx.ReadTimeout):60 httpx.get(server.url)61 62 with mock.patch(61- "httpcore.SyncConnectionPool.request",63+ "httpcore.SyncConnectionPool.handle_request",64 return_value=(200, [], CloseFailedStream(), {}),65 ):66 with pytest.raises(httpx.CloseError):67 httpx.get(server.url)30 unmodified linesmodified:setup.py+1 added-1 removed
57 unmodified lines58 install_requires=[59 "certifi",60 "sniffio",61 "rfc3986[idna2008]>=1.3,<2",62- "httpcore>=0.12.1,<0.13",62+ "httpcore>=0.13.0,<0.14.0",63 "async_generator; python_version < '3.7'"64 ],65 extras_require={66 "http2": "h2==3.*",19 unmodified lines