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

Replace use of deprecated socket.error > OSError #609

Merged
merged 2 commits into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions httpcore/backends/sync.py
Expand Up @@ -20,7 +20,7 @@ def __init__(self, sock: socket.socket) -> None:
self._sock = sock

def read(self, max_bytes: int, timeout: typing.Optional[float] = None) -> bytes:
exc_map = {socket.timeout: ReadTimeout, socket.error: ReadError}
exc_map = {socket.timeout: ReadTimeout, OSError: ReadError}
with map_exceptions(exc_map):
self._sock.settimeout(timeout)
return self._sock.recv(max_bytes)
Expand All @@ -29,7 +29,7 @@ def write(self, buffer: bytes, timeout: typing.Optional[float] = None) -> None:
if not buffer:
return

exc_map = {socket.timeout: WriteTimeout, socket.error: WriteError}
exc_map = {socket.timeout: WriteTimeout, OSError: WriteError}
with map_exceptions(exc_map):
while buffer:
self._sock.settimeout(timeout)
Expand All @@ -45,7 +45,7 @@ def start_tls(
server_hostname: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
) -> NetworkStream:
exc_map = {socket.timeout: ConnectTimeout, socket.error: ConnectError}
exc_map = {socket.timeout: ConnectTimeout, OSError: ConnectError}
with map_exceptions(exc_map):
try:
self._sock.settimeout(timeout)
Expand Down Expand Up @@ -81,7 +81,7 @@ def connect_tcp(
) -> NetworkStream:
address = (host, port)
source_address = None if local_address is None else (local_address, 0)
exc_map = {socket.timeout: ConnectTimeout, socket.error: ConnectError}
exc_map = {socket.timeout: ConnectTimeout, OSError: ConnectError}
with map_exceptions(exc_map):
sock = socket.create_connection(
address, timeout, source_address=source_address
Expand All @@ -91,7 +91,7 @@ def connect_tcp(
def connect_unix_socket(
self, path: str, timeout: typing.Optional[float] = None
) -> NetworkStream: # pragma: nocover
exc_map = {socket.timeout: ConnectTimeout, socket.error: ConnectError}
exc_map = {socket.timeout: ConnectTimeout, OSError: ConnectError}
with map_exceptions(exc_map):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(timeout)
Expand Down