Skip to content
Myr

Drop Protocol str enum class in favor of plain old strings (#251)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Drop Protocol str enum class in favor of plain old strings * Drop unused import

authored by Tom Christie · committed by GitHub · parents c1ec1c3, 7408c44 · Browse files · 5 files+11 added−26 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−26 removed

  • tests:+3 added−10 removed
  • other:+8 added−16 removed

5 files+11 added−26 removed

modified:httpx/concurrency/asyncio.py+3 added-4 removed
20 unmodified lines
21 BasePoolSemaphore,22 BaseReader,23 BaseWriter,24 ConcurrencyBackend,25 Protocol,25)2627SSL_MONKEY_PATCH_APPLIED = False28
171 unmodified lines
200 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 lines
219 ident = ssl_object.selected_npn_protocol()220221 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"224226 return reader, writer, protocol225 return reader, writer, http_version226227 async def run_in_threadpool(228 self, func: typing.Callable, *args: typing.Any, **kwargs: typing.Any229 ) -> typing.Any:
44 unmodified lines
modified:httpx/dispatch/connection.py+4 added-3 removed
8 unmodified lines
9 TimeoutConfig,10 TimeoutTypes,11 VerifyTypes,12)13from ..interfaces import AsyncDispatcher, ConcurrencyBackend, Protocol13from ..interfaces import AsyncDispatcher, ConcurrencyBackend14from ..models import AsyncRequest, AsyncResponse, Origin15from .http2 import HTTP2Connection16from .http11 import HTTP11Connection17
59 unmodified lines
77 on_release = None78 else:79 on_release = functools.partial(self.release_func, self)8081 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 lines
modified:httpx/__init__.py-2 removed
36 unmodified lines
37 BaseReader,38 BaseWriter,39 ConcurrencyBackend,40 Dispatcher,41 Protocol,41)42from .models import (43 URL,44 AsyncRequest,
62 unmodified lines
107 "BaseReader",108 "BaseWriter",109 "ConcurrencyBackend",110 "Dispatcher",112 "Protocol",111 "URL",112 "URLTypes",113 "StatusCode",114 "codes",
19 unmodified lines
modified:httpx/interfaces.py+1 added-7 removed
1import enum1import ssl2import typing3from types import TracebackType4
10 unmodified lines
15 URLTypes,16)171820class Protocol(str, enum.Enum):21 HTTP_11 = "HTTP/1.1"22 HTTP_2 = "HTTP/2"232419class AsyncDispatcher:20 """21 Base class for async dispatcher classes, that handle sending the request.22
142 unmodified lines
165 hostname: str,166 port: int,167 ssl_context: typing.Optional[ssl.SSLContext],168 timeout: TimeoutConfig,175 ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:169 ) -> typing.Tuple[BaseReader, BaseWriter, str]:170 raise NotImplementedError() # pragma: no cover171172 def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:173 raise NotImplementedError() # pragma: no cover
51 unmodified lines
modified:tests/dispatch/utils.py+3 added-10 removed
4 unmodified lines
5import h2.config6import h2.connection7import h2.events89from httpx import (10 AsyncioBackend,11 BaseReader,12 BaseWriter,13 Protocol,14 Request,15 TimeoutConfig,16)9from httpx import AsyncioBackend, BaseReader, BaseWriter, Request, TimeoutConfig101112class MockHTTP2Backend(AsyncioBackend):13 def __init__(self, app):
5 unmodified lines
19 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"262728class MockHTTP2Server(BaseReader, BaseWriter):29 """
86 unmodified lines