|
41 | 41 |
|
42 | 42 | import json as json_module
|
43 | 43 |
|
44 |
| -if sys.implementation.name == "circuitpython": |
45 |
| - |
46 |
| - def cast(_t, value): |
47 |
| - """No-op shim for the typing.cast() function which is not available in CircuitPython.""" |
48 |
| - return value |
49 |
| - |
50 |
| -else: |
| 44 | +if not sys.implementation.name == "circuitpython": |
51 | 45 | from ssl import SSLContext
|
52 | 46 | from types import ModuleType, TracebackType
|
53 |
| - from typing import Any, Dict, Optional, Tuple, Type, Union, cast |
| 47 | + from typing import Any, Dict, Optional, Tuple, Type, Union |
54 | 48 |
|
55 | 49 | try:
|
56 | 50 | from typing import Protocol
|
@@ -83,14 +77,6 @@ def connect(
|
83 | 77 | kwarg optionally may indicate SSL or not, depending on the underlying interface.
|
84 | 78 | """
|
85 | 79 |
|
86 |
| - class LegacyCircuitPythonSocketType(CommonCircuitPythonSocketType, Protocol): |
87 |
| - """Describes the structure a legacy CircuitPython socket type must have.""" |
88 |
| - |
89 |
| - def recv(self, bufsize: int = ...) -> bytes: |
90 |
| - """Receive data from the socket. The return value is a bytes object representing |
91 |
| - the data received. The maximum amount of data to be received at once is specified |
92 |
| - by bufsize.""" |
93 |
| - |
94 | 80 | class SupportsRecvWithFlags(Protocol):
|
95 | 81 | """Describes a type that posseses a socket recv() method supporting the flags kwarg."""
|
96 | 82 |
|
@@ -128,7 +114,6 @@ def connect(self, address: Union[Tuple[Any, ...], str, bytes]) -> None:
|
128 | 114 | """Connect to a remote socket at the provided address."""
|
129 | 115 |
|
130 | 116 | SocketType = Union[
|
131 |
| - LegacyCircuitPythonSocketType, |
132 | 117 | CircuitPythonSocketType,
|
133 | 118 | StandardPythonSocketType,
|
134 | 119 | ]
|
@@ -188,8 +173,6 @@ def __init__(self, sock: SocketType, session: Optional["Session"] = None) -> Non
|
188 | 173 | self._remaining = None
|
189 | 174 | self._chunked = False
|
190 | 175 |
|
191 |
| - self._backwards_compatible = not hasattr(sock, "recv_into") |
192 |
| - |
193 | 176 | http = self._readto(b" ")
|
194 | 177 | if not http:
|
195 | 178 | if session:
|
@@ -217,13 +200,7 @@ def __exit__(
|
217 | 200 | self.close()
|
218 | 201 |
|
219 | 202 | def _recv_into(self, buf: bytearray, size: int = 0) -> int:
|
220 |
| - if self._backwards_compatible: |
221 |
| - size = len(buf) if size == 0 else size |
222 |
| - b = self.socket.recv(size) |
223 |
| - read_size = len(b) |
224 |
| - buf[:read_size] = b |
225 |
| - return read_size |
226 |
| - return cast("SupportsRecvInto", self.socket).recv_into(buf, size) |
| 203 | + return self.socket.recv_into(buf, size) |
227 | 204 |
|
228 | 205 | def _readto(self, stop: bytes) -> bytearray:
|
229 | 206 | buf = self._receive_buffer
|
@@ -763,6 +740,7 @@ def __init__(self, socket: CircuitPythonSocketType, tls_mode: int) -> None:
|
763 | 740 | self.send = socket.send
|
764 | 741 | self.recv = socket.recv
|
765 | 742 | self.close = socket.close
|
| 743 | + self.recv_into = socket.recv_into |
766 | 744 |
|
767 | 745 | def connect(self, address: Tuple[str, int]) -> None:
|
768 | 746 | """connect wrapper to add non-standard mode parameter"""
|
|
0 commit comments