Drop Protocol str enum class in favor of plain old strings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tom Christie · committed by Tom Christie · parent b2397ff · Browse files · 5 files·+11 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+11 added−25 removed
- tests:+3 added−10 removed
- other:+8 added−15 removed
Provenance
- Commit
dfbfa7c- Tree
e6da27a- Author
Tom Christie <tom@tomchristie.com>- Committer
Tom Christie <tom@tomchristie.com>- Parent
b2397ff
5 files changed+11 added−25 removed
modified:httpx/concurrency/asyncio.py+3 added-4 removed
20 unmodified lines21 BasePoolSemaphore,22 BaseReader,23 BaseWriter,24 ConcurrencyBackend,25- Protocol,25 )26 27 SSL_MONKEY_PATCH_APPLIED = False28 171 unmodified lines200 hostname: str,201 port: int,202 ssl_context: typing.Optional[ssl.SSLContext],203 timeout: TimeoutConfig,205- ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:204+ ) -> typing.Tuple[BaseReader, BaseWriter, str]:205 try:206 stream_reader, stream_writer = await asyncio.wait_for( # type: ignore207 asyncio.open_connection(hostname, port, ssl=ssl_context),208 timeout.connect_timeout,10 unmodified lines219 ident = ssl_object.selected_npn_protocol()220 221 reader = Reader(stream_reader=stream_reader, timeout=timeout)222 writer = Writer(stream_writer=stream_writer, timeout=timeout)224- protocol = Protocol.HTTP_2 if ident == "h2" else Protocol.HTTP_11223+ http_version = "HTTP/2" if ident == "h2" else "HTTP/1.1"224 226- return reader, writer, protocol225+ return reader, writer, http_version226 227 async def run_in_threadpool(228 self, func: typing.Callable, *args: typing.Any, **kwargs: typing.Any229 ) -> typing.Any:44 unmodified linesmodified:httpx/dispatch/connection.py+4 added-3 removed
8 unmodified lines9 TimeoutConfig,10 TimeoutTypes,11 VerifyTypes,12 )13-from ..interfaces import AsyncDispatcher, ConcurrencyBackend, Protocol13+from ..interfaces import AsyncDispatcher, ConcurrencyBackend14 from ..models import AsyncRequest, AsyncResponse, Origin15 from .http2 import HTTP2Connection16 from .http11 import HTTP11Connection17 59 unmodified lines77 on_release = None78 else:79 on_release = functools.partial(self.release_func, self)80 81- reader, writer, protocol = await self.backend.connect(81+ reader, writer, http_version = await self.backend.connect(82 host, port, ssl_context, timeout83 )84- if protocol == Protocol.HTTP_2:84+ if http_version == "HTTP/2":85 self.h2_connection = HTTP2Connection(86 reader, writer, self.backend, on_release=on_release87 )88 else:89+ assert http_version == "HTTP/1.1"90 self.h11_connection = HTTP11Connection(91 reader, writer, self.backend, on_release=on_release92 )93 24 unmodified linesmodified:httpx/__init__.py-2 removed
36 unmodified lines37 BaseReader,38 BaseWriter,39 ConcurrencyBackend,40 Dispatcher,41- Protocol,41 )42 from .models import (43 URL,44 AsyncRequest,62 unmodified lines107 "BaseReader",108 "BaseWriter",109 "ConcurrencyBackend",110 "Dispatcher",112- "Protocol",111 "URL",112 "URLTypes",113 "StatusCode",114 "codes",19 unmodified linesmodified:httpx/interfaces.py+1 added-6 removed
15 unmodified lines16 URLTypes,17 )18 19 20-class Protocol(str, enum.Enum):21- HTTP_11 = "HTTP/1.1"22- HTTP_2 = "HTTP/2"23-24-20 class AsyncDispatcher:21 """22 Base class for async dispatcher classes, that handle sending the request.23 142 unmodified lines166 hostname: str,167 port: int,168 ssl_context: typing.Optional[ssl.SSLContext],169 timeout: TimeoutConfig,175- ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:170+ ) -> typing.Tuple[BaseReader, BaseWriter, str]:171 raise NotImplementedError() # pragma: no cover172 173 def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:174 raise NotImplementedError() # pragma: no cover51 unmodified linesmodified:tests/dispatch/utils.py+3 added-10 removed
4 unmodified lines5 import h2.config6 import h2.connection7 import h2.events8 9-from httpx import (10- AsyncioBackend,11- BaseReader,12- BaseWriter,13- Protocol,14- Request,15- TimeoutConfig,16-)9+from httpx import AsyncioBackend, BaseReader, BaseWriter, Request, TimeoutConfig10 11 12 class MockHTTP2Backend(AsyncioBackend):13 def __init__(self, app):5 unmodified lines19 hostname: str,20 port: int,21 ssl_context: typing.Optional[ssl.SSLContext],22 timeout: TimeoutConfig,30- ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:23+ ) -> typing.Tuple[BaseReader, BaseWriter, str]:24 self.server = MockHTTP2Server(self.app)32- return self.server, self.server, Protocol.HTTP_225+ return self.server, self.server, "HTTP/2"26 27 28 class MockHTTP2Server(BaseReader, BaseWriter):29 """86 unmodified lines