Skip to content

Commit

Permalink
Delete some legacy runtime checks
Browse files Browse the repository at this point in the history
  • Loading branch information
romis2012 committed Dec 27, 2024
1 parent 173a739 commit 619590a
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions python_socks/async_/asyncio/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,13 @@ async def _connect(self, dest_host, dest_port, _socket=None) -> socket.socket:
)

return _socket
except asyncio.CancelledError: # pragma: no cover
# https://bugs.python.org/issue30064
# https://bugs.python.org/issue34795
if self._can_be_closed_safely():
await stream.close()
raise
except ReplyError as e:
await stream.close()
raise ProxyError(e, error_code=e.error_code)
except Exception: # pragma: no cover
except (asyncio.CancelledError, Exception): # pragma: no cover
await stream.close()
raise

def _can_be_closed_safely(self): # pragma: no cover
def is_proactor_event_loop():
try:
# pylint:disable-next=import-outside-toplevel
from asyncio import ProactorEventLoop
except ImportError:
return False
return isinstance(self._loop, ProactorEventLoop)

def is_uvloop_event_loop():
try:
# pylint:disable-next=import-outside-toplevel
from uvloop import Loop # type:ignore[import-not-found]
except ImportError:
return False
return isinstance(self._loop, Loop)

return sys.version_info[:2] >= (3, 8) or is_proactor_event_loop() or is_uvloop_event_loop()

@property
def proxy_host(self):
return self._proxy_host
Expand Down

0 comments on commit 619590a

Please sign in to comment.