From: Tom Christie Date: Tue, 20 Aug 2019 13:17:26 +0000 (+0100) Subject: Drop Protocol str enum class in favor of plain old strings X-Git-Tag: 0.7.2~20^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfbfa7c7ec21763518a5f63e3b22c35c27bec64f;p=thirdparty%2Fhttpx.git Drop Protocol str enum class in favor of plain old strings --- diff --git a/httpx/__init__.py b/httpx/__init__.py index c2925d5c..da492440 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -38,7 +38,6 @@ from .interfaces import ( BaseWriter, ConcurrencyBackend, Dispatcher, - Protocol, ) from .models import ( URL, @@ -109,7 +108,6 @@ __all__ = [ "BaseWriter", "ConcurrencyBackend", "Dispatcher", - "Protocol", "URL", "URLTypes", "StatusCode", diff --git a/httpx/concurrency/asyncio.py b/httpx/concurrency/asyncio.py index 6c5dc0c4..d8421f71 100644 --- a/httpx/concurrency/asyncio.py +++ b/httpx/concurrency/asyncio.py @@ -22,7 +22,6 @@ from ..interfaces import ( BaseReader, BaseWriter, ConcurrencyBackend, - Protocol, ) SSL_MONKEY_PATCH_APPLIED = False @@ -202,7 +201,7 @@ class AsyncioBackend(ConcurrencyBackend): port: int, ssl_context: typing.Optional[ssl.SSLContext], timeout: TimeoutConfig, - ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]: + ) -> typing.Tuple[BaseReader, BaseWriter, str]: try: stream_reader, stream_writer = await asyncio.wait_for( # type: ignore asyncio.open_connection(hostname, port, ssl=ssl_context), @@ -221,9 +220,9 @@ class AsyncioBackend(ConcurrencyBackend): reader = Reader(stream_reader=stream_reader, timeout=timeout) writer = Writer(stream_writer=stream_writer, timeout=timeout) - protocol = Protocol.HTTP_2 if ident == "h2" else Protocol.HTTP_11 + http_version = "HTTP/2" if ident == "h2" else "HTTP/1.1" - return reader, writer, protocol + return reader, writer, http_version async def run_in_threadpool( self, func: typing.Callable, *args: typing.Any, **kwargs: typing.Any diff --git a/httpx/dispatch/connection.py b/httpx/dispatch/connection.py index 9dda06d0..d7417c95 100644 --- a/httpx/dispatch/connection.py +++ b/httpx/dispatch/connection.py @@ -10,7 +10,7 @@ from ..config import ( TimeoutTypes, VerifyTypes, ) -from ..interfaces import AsyncDispatcher, ConcurrencyBackend, Protocol +from ..interfaces import AsyncDispatcher, ConcurrencyBackend from ..models import AsyncRequest, AsyncResponse, Origin from .http2 import HTTP2Connection from .http11 import HTTP11Connection @@ -78,14 +78,15 @@ class HTTPConnection(AsyncDispatcher): else: on_release = functools.partial(self.release_func, self) - reader, writer, protocol = await self.backend.connect( + reader, writer, http_version = await self.backend.connect( host, port, ssl_context, timeout ) - if protocol == Protocol.HTTP_2: + if http_version == "HTTP/2": self.h2_connection = HTTP2Connection( reader, writer, self.backend, on_release=on_release ) else: + assert http_version == "HTTP/1.1" self.h11_connection = HTTP11Connection( reader, writer, self.backend, on_release=on_release ) diff --git a/httpx/interfaces.py b/httpx/interfaces.py index 2b4edf4d..ae5b8e01 100644 --- a/httpx/interfaces.py +++ b/httpx/interfaces.py @@ -17,11 +17,6 @@ from .models import ( ) -class Protocol(str, enum.Enum): - HTTP_11 = "HTTP/1.1" - HTTP_2 = "HTTP/2" - - class AsyncDispatcher: """ Base class for async dispatcher classes, that handle sending the request. @@ -172,7 +167,7 @@ class ConcurrencyBackend: port: int, ssl_context: typing.Optional[ssl.SSLContext], timeout: TimeoutConfig, - ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]: + ) -> typing.Tuple[BaseReader, BaseWriter, str]: raise NotImplementedError() # pragma: no cover def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore: diff --git a/tests/dispatch/utils.py b/tests/dispatch/utils.py index c92fa7a3..b5aac850 100644 --- a/tests/dispatch/utils.py +++ b/tests/dispatch/utils.py @@ -6,14 +6,7 @@ import h2.config import h2.connection import h2.events -from httpx import ( - AsyncioBackend, - BaseReader, - BaseWriter, - Protocol, - Request, - TimeoutConfig, -) +from httpx import AsyncioBackend, BaseReader, BaseWriter, Request, TimeoutConfig class MockHTTP2Backend(AsyncioBackend): @@ -27,9 +20,9 @@ class MockHTTP2Backend(AsyncioBackend): port: int, ssl_context: typing.Optional[ssl.SSLContext], timeout: TimeoutConfig, - ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]: + ) -> typing.Tuple[BaseReader, BaseWriter, str]: self.server = MockHTTP2Server(self.app) - return self.server, self.server, Protocol.HTTP_2 + return self.server, self.server, "HTTP/2" class MockHTTP2Server(BaseReader, BaseWriter):