Skip to content
Myr

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

3 files+15 added−23 removed

modified:httpx/_transports/default.py+9 added-19 removed
76 unmodified lines
77 message = str(exc)78 raise mapped_exc(message) from exc798081def 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")929381HTTPCORE_EXC_MAP = {82 httpcore.TimeoutException: TimeoutException,83 httpcore.ConnectTimeout: ConnectTimeout,84 httpcore.ReadTimeout: ReadTimeout,
89 unmodified lines
174 ) -> 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 )185199 ensure_http_version_reason_phrase_as_bytes(extensions)186 stream = ResponseStream(byte_stream)187188 return status_code, headers, stream, extensions189
78 unmodified lines
268 ) -> 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 )284294 ensure_http_version_reason_phrase_as_bytes(extensions)285 stream = AsyncResponseStream(byte_stream)286287 return status_code, headers, stream, extensions288
2 unmodified lines
modified:tests/test_exceptions.py+5 added-3 removed
44 unmodified lines
4546 def close(self):47 raise httpcore.CloseError()4849 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)5455 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)6162 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 lines
modified:setup.py+1 added-1 removed
57 unmodified lines
58 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