Skip to content

Commit

Permalink
Replace use of deprecated socket.error > OSError (#609)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Christie <tom@tomchristie.com>
  • Loading branch information
michaeloliverx and tomchristie committed Nov 17, 2022
1 parent 5d2eed0 commit c316f63
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit c316f63

Please sign in to comment.