Skip to content

Commit e09c3bd

Browse files
authored
Merge pull request #135 from FoamyGuy/remove_backward_compat
remove backwards compatibility
2 parents 1259b73 + c5e1a4c commit e09c3bd

File tree

3 files changed

+4
-281
lines changed

3 files changed

+4
-281
lines changed

adafruit_requests.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@
4141

4242
import json as json_module
4343

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":
5145
from ssl import SSLContext
5246
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
5448

5549
try:
5650
from typing import Protocol
@@ -83,14 +77,6 @@ def connect(
8377
kwarg optionally may indicate SSL or not, depending on the underlying interface.
8478
"""
8579

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-
9480
class SupportsRecvWithFlags(Protocol):
9581
"""Describes a type that posseses a socket recv() method supporting the flags kwarg."""
9682

@@ -128,7 +114,6 @@ def connect(self, address: Union[Tuple[Any, ...], str, bytes]) -> None:
128114
"""Connect to a remote socket at the provided address."""
129115

130116
SocketType = Union[
131-
LegacyCircuitPythonSocketType,
132117
CircuitPythonSocketType,
133118
StandardPythonSocketType,
134119
]
@@ -188,8 +173,6 @@ def __init__(self, sock: SocketType, session: Optional["Session"] = None) -> Non
188173
self._remaining = None
189174
self._chunked = False
190175

191-
self._backwards_compatible = not hasattr(sock, "recv_into")
192-
193176
http = self._readto(b" ")
194177
if not http:
195178
if session:
@@ -217,13 +200,7 @@ def __exit__(
217200
self.close()
218201

219202
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)
227204

228205
def _readto(self, stop: bytes) -> bytearray:
229206
buf = self._receive_buffer
@@ -763,6 +740,7 @@ def __init__(self, socket: CircuitPythonSocketType, tls_mode: int) -> None:
763740
self.send = socket.send
764741
self.recv = socket.recv
765742
self.close = socket.close
743+
self.recv_into = socket.recv_into
766744

767745
def connect(self, address: Tuple[str, int]) -> None:
768746
"""connect wrapper to add non-standard mode parameter"""

tests/legacy_mocket.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/legacy_test.py

Lines changed: 0 additions & 208 deletions
This file was deleted.

0 commit comments

Comments
 (0)