Skip to content

Commit

Permalink
🚑 emergency fix for python-socks broken integration due to upstream c…
Browse files Browse the repository at this point in the history
…hanges (#192)
  • Loading branch information
Ousret authored Dec 29, 2024
1 parent 4a9d322 commit 9cdb54c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.12.905 (2024-12-29)
=====================

- Fixed error due to an internal change in python-socks 2.6
- Pinned python-socks upper bound to 2.5.3 pending further improvement into our integration.

2.12.904 (2024-12-22)
=====================

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ zstd = [
]
secure = []
socks = [
"python-socks>=2.0,<3.0",
"python-socks>=2.0,<=2.5.3",
]
qh3 = [
"qh3>=1.2.0,<2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is protected via CODEOWNERS
from __future__ import annotations

__version__ = "2.12.904"
__version__ = "2.12.905"
24 changes: 12 additions & 12 deletions src/urllib3/contrib/_socks_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
import socket
import typing

from python_socks import _abc as abc # type: ignore
from python_socks import _abc as abc

# look the other way if unpleasant. No choice for now.
# will start discussions once we have a solid traffic.
from python_socks._connectors.abc import AsyncConnector # type: ignore
from python_socks._connectors.socks4_async import Socks4AsyncConnector # type: ignore
from python_socks._connectors.socks5_async import Socks5AsyncConnector # type: ignore
from python_socks._errors import ProxyError, ProxyTimeoutError # type: ignore
from python_socks._helpers import parse_proxy_url # type: ignore
from python_socks._protocols.errors import ReplyError # type: ignore
from python_socks._types import ProxyType # type: ignore
from python_socks._connectors.abc import AsyncConnector
from python_socks._connectors.socks4_async import Socks4AsyncConnector
from python_socks._connectors.socks5_async import Socks5AsyncConnector
from python_socks._errors import ProxyError, ProxyTimeoutError
from python_socks._helpers import parse_proxy_url
from python_socks._protocols.errors import ReplyError
from python_socks._types import ProxyType

from .ssa import AsyncSocket
from .ssa._timeout import timeout as timeout_


class Resolver(abc.AsyncResolver): # type: ignore[misc]
class Resolver(abc.AsyncResolver):
def __init__(self, loop: asyncio.AbstractEventLoop):
self._loop = loop

Expand Down Expand Up @@ -77,7 +77,7 @@ def create_connector(
raise ValueError(f"Invalid proxy type: {proxy_type}")


class AsyncioProxy(abc.AsyncProxy): # type: ignore[misc]
class AsyncioProxy:
def __init__(
self,
proxy_type: ProxyType,
Expand Down Expand Up @@ -130,7 +130,7 @@ async def _connect(
resolver=self._resolver,
)
await connector.connect(
stream=_socket,
stream=_socket, # type: ignore[arg-type]
host=dest_host,
port=dest_port,
)
Expand All @@ -141,7 +141,7 @@ async def _connect(
raise
except ReplyError as e:
_socket.close()
raise ProxyError(e, error_code=e.error_code)
raise ProxyError(e, error_code=e.error_code) # type: ignore[no-untyped-call]
except Exception: # Defensive:
_socket.close()
raise
Expand Down
12 changes: 6 additions & 6 deletions src/urllib3/contrib/socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
BYPASS_SOCKS_LEGACY: bool = False

try:
from python_socks import ( # type: ignore[import-untyped]
from python_socks import (
ProxyConnectionError,
ProxyError,
ProxyTimeoutError,
ProxyType,
)
from python_socks.sync import Proxy # type: ignore[import-untyped]
from python_socks.sync import Proxy

from ._socks_override import AsyncioProxy
except ImportError:
Expand Down Expand Up @@ -162,7 +162,7 @@ def _new_conn(self) -> socket:
assert self._socks_options["proxy_port"] is not None

p = Proxy(
proxy_type=self._socks_options["socks_version"],
proxy_type=self._socks_options["socks_version"], # type: ignore[arg-type]
host=self._socks_options["proxy_host"],
port=int(self._socks_options["proxy_port"]),
username=self._socks_options["username"],
Expand All @@ -182,11 +182,11 @@ def _new_conn(self) -> socket:
timing_hook=lambda _: setattr(self, "_connect_timings", _),
)

return p.connect( # type: ignore[no-any-return]
return p.connect(
self.host,
self.port,
self.timeout,
_socket,
_socket=_socket,
)
except (SocketTimeout, ProxyTimeoutError) as e:
raise ConnectTimeoutError(
Expand Down Expand Up @@ -320,7 +320,7 @@ async def _new_conn(self) -> AsyncSocket: # type: ignore[override]
assert self._socks_options["proxy_port"] is not None

p = AsyncioProxy(
proxy_type=self._socks_options["socks_version"],
proxy_type=self._socks_options["socks_version"], # type: ignore[arg-type]
host=self._socks_options["proxy_host"],
port=int(self._socks_options["proxy_port"]),
username=self._socks_options["username"],
Expand Down

0 comments on commit 9cdb54c

Please sign in to comment.