Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove backwards compatibility #135

Merged
merged 4 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@

import json as json_module

if sys.implementation.name == "circuitpython":

def cast(_t, value):
"""No-op shim for the typing.cast() function which is not available in CircuitPython."""
return value

else:
if not sys.implementation.name == "circuitpython":
from ssl import SSLContext
from types import ModuleType, TracebackType
from typing import Any, Dict, Optional, Tuple, Type, Union, cast
from typing import Any, Dict, Optional, Tuple, Type, Union

try:
from typing import Protocol
Expand Down Expand Up @@ -83,14 +77,6 @@ def connect(
kwarg optionally may indicate SSL or not, depending on the underlying interface.
"""

class LegacyCircuitPythonSocketType(CommonCircuitPythonSocketType, Protocol):
"""Describes the structure a legacy CircuitPython socket type must have."""

def recv(self, bufsize: int = ...) -> bytes:
"""Receive data from the socket. The return value is a bytes object representing
the data received. The maximum amount of data to be received at once is specified
by bufsize."""

class SupportsRecvWithFlags(Protocol):
"""Describes a type that posseses a socket recv() method supporting the flags kwarg."""

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

SocketType = Union[
LegacyCircuitPythonSocketType,
CircuitPythonSocketType,
StandardPythonSocketType,
]
Expand Down Expand Up @@ -188,8 +173,6 @@ def __init__(self, sock: SocketType, session: Optional["Session"] = None) -> Non
self._remaining = None
self._chunked = False

self._backwards_compatible = not hasattr(sock, "recv_into")

http = self._readto(b" ")
if not http:
if session:
Expand Down Expand Up @@ -217,13 +200,7 @@ def __exit__(
self.close()

def _recv_into(self, buf: bytearray, size: int = 0) -> int:
if self._backwards_compatible:
size = len(buf) if size == 0 else size
b = self.socket.recv(size)
read_size = len(b)
buf[:read_size] = b
return read_size
return cast("SupportsRecvInto", self.socket).recv_into(buf, size)
return self.socket.recv_into(buf, size)

def _readto(self, stop: bytes) -> bytearray:
buf = self._receive_buffer
Expand Down Expand Up @@ -763,6 +740,7 @@ def __init__(self, socket: CircuitPythonSocketType, tls_mode: int) -> None:
self.send = socket.send
self.recv = socket.recv
self.close = socket.close
self.recv_into = socket.recv_into

def connect(self, address: Tuple[str, int]) -> None:
"""connect wrapper to add non-standard mode parameter"""
Expand Down
47 changes: 0 additions & 47 deletions tests/legacy_mocket.py

This file was deleted.

208 changes: 0 additions & 208 deletions tests/legacy_test.py

This file was deleted.