]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Rename BaseTCPStream/TCPStream to BaseSocketStream/SocketStream (#517)
authorJonas Lundberg <jonas@5monkeys.se>
Fri, 8 Nov 2019 16:09:38 +0000 (17:09 +0100)
committerFlorimond Manca <florimond.manca@gmail.com>
Fri, 8 Nov 2019 16:09:38 +0000 (17:09 +0100)
httpx/__init__.py
httpx/concurrency/asyncio.py
httpx/concurrency/base.py
httpx/concurrency/trio.py
httpx/dispatch/http11.py
httpx/dispatch/http2.py
httpx/dispatch/proxy_http.py
tests/dispatch/utils.py

index 6859964f8aca3d0017bb3bc1426ef4566490b30b..5eb85162c5c3a1358f9dd0035653465e5762000a 100644 (file)
@@ -5,7 +5,7 @@ from .concurrency.asyncio import AsyncioBackend
 from .concurrency.base import (
     BaseBackgroundManager,
     BasePoolSemaphore,
-    BaseTCPStream,
+    BaseSocketStream,
     ConcurrencyBackend,
 )
 from .config import (
@@ -114,7 +114,7 @@ __all__ = [
     "TooManyRedirects",
     "WriteTimeout",
     "AsyncDispatcher",
-    "BaseTCPStream",
+    "BaseSocketStream",
     "ConcurrencyBackend",
     "Dispatcher",
     "URL",
index 4aeb7ca53dc3f9864381a9ffde1830d3c8ad3a3d..010d8215a8b15a3df80f76eed24ead276b970a91 100644 (file)
@@ -12,7 +12,7 @@ from .base import (
     BaseEvent,
     BasePoolSemaphore,
     BaseQueue,
-    BaseTCPStream,
+    BaseSocketStream,
     ConcurrencyBackend,
     TimeoutFlag,
 )
@@ -41,7 +41,7 @@ def ssl_monkey_patch() -> None:
     MonkeyPatch.write = _fixed_write
 
 
-class TCPStream(BaseTCPStream):
+class SocketStream(BaseSocketStream):
     def __init__(
         self,
         stream_reader: asyncio.StreamReader,
@@ -52,11 +52,11 @@ class TCPStream(BaseTCPStream):
         self.stream_writer = stream_writer
         self.timeout = timeout
 
-        self._inner: typing.Optional[TCPStream] = None
+        self._inner: typing.Optional[SocketStream] = None
 
     async def start_tls(
         self, hostname: str, ssl_context: ssl.SSLContext, timeout: TimeoutConfig
-    ) -> BaseTCPStream:
+    ) -> "SocketStream":
         loop = asyncio.get_event_loop()
         if not hasattr(loop, "start_tls"):  # pragma: no cover
             raise NotImplementedError(
@@ -83,8 +83,8 @@ class TCPStream(BaseTCPStream):
             transport=transport, protocol=protocol, reader=stream_reader, loop=loop
         )
 
-        ssl_stream = TCPStream(stream_reader, stream_writer, self.timeout)
-        # When we return a new TCPStream with new StreamReader/StreamWriter instances,
+        ssl_stream = SocketStream(stream_reader, stream_writer, self.timeout)
+        # When we return a new SocketStream with new StreamReader/StreamWriter instances
         # we need to keep references to the old StreamReader/StreamWriter so that they
         # are not garbage collected and closed while we're still using them.
         ssl_stream._inner = self
@@ -229,7 +229,7 @@ class AsyncioBackend(ConcurrencyBackend):
         port: int,
         ssl_context: typing.Optional[ssl.SSLContext],
         timeout: TimeoutConfig,
-    ) -> BaseTCPStream:
+    ) -> SocketStream:
         try:
             stream_reader, stream_writer = await asyncio.wait_for(  # type: ignore
                 asyncio.open_connection(hostname, port, ssl=ssl_context),
@@ -238,7 +238,7 @@ class AsyncioBackend(ConcurrencyBackend):
         except asyncio.TimeoutError:
             raise ConnectTimeout()
 
-        return TCPStream(
+        return SocketStream(
             stream_reader=stream_reader, stream_writer=stream_writer, timeout=timeout
         )
 
index a23d89bd30a90113777afcf88e3dc223b7afb703..9d5bffde3eef585a0b1b875ad3c13a062c001e88 100644 (file)
@@ -37,9 +37,9 @@ class TimeoutFlag:
         self.raise_on_write_timeout = True
 
 
-class BaseTCPStream:
+class BaseSocketStream:
     """
-    A TCP stream with read/write operations. Abstracts away any asyncio-specific
+    A socket stream with read/write operations. Abstracts away any asyncio-specific
     interfaces into a more generic base class, that we can use with alternate
     backends, or for stand-alone test cases.
     """
@@ -49,7 +49,7 @@ class BaseTCPStream:
 
     async def start_tls(
         self, hostname: str, ssl_context: ssl.SSLContext, timeout: TimeoutConfig
-    ) -> "BaseTCPStream":
+    ) -> "BaseSocketStream":
         raise NotImplementedError()  # pragma: no cover
 
     async def read(
@@ -121,7 +121,7 @@ class ConcurrencyBackend:
         port: int,
         ssl_context: typing.Optional[ssl.SSLContext],
         timeout: TimeoutConfig,
-    ) -> BaseTCPStream:
+    ) -> BaseSocketStream:
         raise NotImplementedError()  # pragma: no cover
 
     def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:
index da8e38a0ef768509c5f8cc4f72383a10051d4f01..5d3b50dfbba420e6f3cfecdd62547ae92be52666 100644 (file)
@@ -13,7 +13,7 @@ from .base import (
     BaseEvent,
     BasePoolSemaphore,
     BaseQueue,
-    BaseTCPStream,
+    BaseSocketStream,
     ConcurrencyBackend,
     TimeoutFlag,
 )
@@ -23,7 +23,7 @@ def _or_inf(value: typing.Optional[float]) -> float:
     return value if value is not None else float("inf")
 
 
-class TCPStream(BaseTCPStream):
+class SocketStream(BaseSocketStream):
     def __init__(
         self,
         stream: typing.Union[trio.SocketStream, trio.SSLStream],
@@ -36,7 +36,7 @@ class TCPStream(BaseTCPStream):
 
     async def start_tls(
         self, hostname: str, ssl_context: ssl.SSLContext, timeout: TimeoutConfig
-    ) -> BaseTCPStream:
+    ) -> "SocketStream":
         # Check that the write buffer is empty. We should never start a TLS stream
         # while there is still pending data to write.
         assert self.write_buffer == b""
@@ -52,7 +52,7 @@ class TCPStream(BaseTCPStream):
         if cancel_scope.cancelled_caught:
             raise ConnectTimeout()
 
-        return TCPStream(ssl_stream, self.timeout)
+        return SocketStream(ssl_stream, self.timeout)
 
     def get_http_version(self) -> str:
         if not isinstance(self.stream, trio.SSLStream):
@@ -177,7 +177,7 @@ class TrioBackend(ConcurrencyBackend):
         port: int,
         ssl_context: typing.Optional[ssl.SSLContext],
         timeout: TimeoutConfig,
-    ) -> TCPStream:
+    ) -> SocketStream:
         connect_timeout = _or_inf(timeout.connect_timeout)
 
         with trio.move_on_after(connect_timeout) as cancel_scope:
@@ -189,7 +189,7 @@ class TrioBackend(ConcurrencyBackend):
         if cancel_scope.cancelled_caught:
             raise ConnectTimeout()
 
-        return TCPStream(stream=stream, timeout=timeout)
+        return SocketStream(stream=stream, timeout=timeout)
 
     async def run_in_threadpool(
         self, func: typing.Callable, *args: typing.Any, **kwargs: typing.Any
index fba58f731f806caa0eaa4b06e2131991d2888c8e..b1781bffa46379de839fc3e45ef361d0904fb7bc 100644 (file)
@@ -2,7 +2,7 @@ import typing
 
 import h11
 
-from ..concurrency.base import BaseTCPStream, ConcurrencyBackend, TimeoutFlag
+from ..concurrency.base import BaseSocketStream, ConcurrencyBackend, TimeoutFlag
 from ..config import TimeoutConfig, TimeoutTypes
 from ..models import AsyncRequest, AsyncResponse
 from ..utils import get_logger
@@ -31,7 +31,7 @@ class HTTP11Connection:
 
     def __init__(
         self,
-        stream: BaseTCPStream,
+        stream: BaseSocketStream,
         backend: ConcurrencyBackend,
         on_release: typing.Optional[OnReleaseCallback] = None,
     ):
index c76f99f7ce6e2758bf14fdcc1f6df7f948325b8f..5c6643103d5f3cb9867f7c62db805935de395642 100644 (file)
@@ -5,7 +5,12 @@ import h2.connection
 import h2.events
 from h2.settings import SettingCodes, Settings
 
-from ..concurrency.base import BaseEvent, BaseTCPStream, ConcurrencyBackend, TimeoutFlag
+from ..concurrency.base import (
+    BaseEvent,
+    BaseSocketStream,
+    ConcurrencyBackend,
+    TimeoutFlag,
+)
 from ..config import TimeoutConfig, TimeoutTypes
 from ..exceptions import ProtocolError
 from ..models import AsyncRequest, AsyncResponse
@@ -19,7 +24,7 @@ class HTTP2Connection:
 
     def __init__(
         self,
-        stream: BaseTCPStream,
+        stream: BaseSocketStream,
         backend: ConcurrencyBackend,
         on_release: typing.Callable = None,
     ):
index f6d52e58a677627480c4c52fa7d37c222913ebd1..8ad0ca85972bf6e1cbdec060e40462c1c63f0d96 100644 (file)
@@ -179,7 +179,7 @@ class HTTPProxy(ConnectionPool):
         stream = http_connection.stream
 
         # If we need to start TLS again for the target server
-        # we need to pull the TCP stream off the internal
+        # we need to pull the socket stream off the internal
         # HTTP connection object and run start_tls()
         if origin.is_ssl:
             ssl_config = SSLConfig(cert=self.cert, verify=self.verify)
index 3b0d5340000c99e9b6a4240707af3f893846c5aa..e2916c7b00721ac08aa60a506f3afe7df4fd6edf 100644 (file)
@@ -5,7 +5,7 @@ import h2.config
 import h2.connection
 import h2.events
 
-from httpx import AsyncioBackend, BaseTCPStream, Request, TimeoutConfig
+from httpx import AsyncioBackend, BaseSocketStream, Request, TimeoutConfig
 from tests.concurrency import sleep
 
 
@@ -21,7 +21,7 @@ class MockHTTP2Backend:
         port: int,
         ssl_context: typing.Optional[ssl.SSLContext],
         timeout: TimeoutConfig,
-    ) -> BaseTCPStream:
+    ) -> BaseSocketStream:
         self.server = MockHTTP2Server(self.app, backend=self.backend)
         return self.server
 
@@ -30,7 +30,7 @@ class MockHTTP2Backend:
         return getattr(self.backend, name)
 
 
-class MockHTTP2Server(BaseTCPStream):
+class MockHTTP2Server(BaseSocketStream):
     def __init__(self, app, backend):
         config = h2.config.H2Configuration(client_side=False)
         self.conn = h2.connection.H2Connection(config=config)
@@ -43,7 +43,7 @@ class MockHTTP2Server(BaseTCPStream):
         self.returning = {}
         self.settings_changed = []
 
-    # TCP stream interface
+    # Socket stream interface
 
     def get_http_version(self) -> str:
         return "HTTP/2"
@@ -178,7 +178,7 @@ class MockRawSocketBackend:
         port: int,
         ssl_context: typing.Optional[ssl.SSLContext],
         timeout: TimeoutConfig,
-    ) -> BaseTCPStream:
+    ) -> BaseSocketStream:
         self.received_data.append(
             b"--- CONNECT(%s, %d) ---" % (hostname.encode(), port)
         )
@@ -189,13 +189,13 @@ class MockRawSocketBackend:
         return getattr(self.backend, name)
 
 
-class MockRawSocketStream(BaseTCPStream):
+class MockRawSocketStream(BaseSocketStream):
     def __init__(self, backend: MockRawSocketBackend):
         self.backend = backend
 
     async def start_tls(
         self, hostname: str, ssl_context: ssl.SSLContext, timeout: TimeoutConfig
-    ) -> BaseTCPStream:
+    ) -> BaseSocketStream:
         self.backend.received_data.append(b"--- START_TLS(%s) ---" % hostname.encode())
         return MockRawSocketStream(self.backend)