|
| 1 | +import logging |
| 2 | +import socket |
| 3 | +import types |
| 4 | +from _typeshed import ReadableBuffer |
| 5 | +from collections.abc import Callable, Mapping |
| 6 | +from typing import Any, Final, TypeVar |
| 7 | +from typing_extensions import ParamSpec, TypeAlias |
| 8 | + |
| 9 | +__version__: str |
| 10 | + |
| 11 | +log: logging.Logger # undocumented |
| 12 | + |
| 13 | +_ProxyType: TypeAlias = int |
| 14 | + |
| 15 | +PROXY_TYPE_SOCKS4: Final[_ProxyType] |
| 16 | +SOCKS4: Final[_ProxyType] |
| 17 | +PROXY_TYPE_SOCKS5: Final[_ProxyType] |
| 18 | +SOCKS5: Final[_ProxyType] |
| 19 | +PROXY_TYPE_HTTP: Final[_ProxyType] |
| 20 | +HTTP: Final[_ProxyType] |
| 21 | + |
| 22 | +PROXY_TYPES: Final[dict[str, _ProxyType]] |
| 23 | +PRINTABLE_PROXY_TYPES: Final[dict[_ProxyType, str]] |
| 24 | + |
| 25 | +_T = TypeVar("_T") |
| 26 | +_P = ParamSpec("_P") |
| 27 | + |
| 28 | +def set_self_blocking(function: Callable[_P, _T]) -> Callable[_P, _T]: ... # undocumented |
| 29 | + |
| 30 | +class ProxyError(IOError): |
| 31 | + msg: str |
| 32 | + socket_err: socket.error |
| 33 | + def __init__(self, msg: str, socket_err: socket.error | None = None) -> None: ... |
| 34 | + |
| 35 | +class GeneralProxyError(ProxyError): ... |
| 36 | +class ProxyConnectionError(ProxyError): ... |
| 37 | +class SOCKS5AuthError(ProxyError): ... |
| 38 | +class SOCKS5Error(ProxyError): ... |
| 39 | +class SOCKS4Error(ProxyError): ... |
| 40 | +class HTTPError(ProxyError): ... |
| 41 | + |
| 42 | +SOCKS4_ERRORS: Final[Mapping[int, str]] |
| 43 | +SOCKS5_ERRORS: Final[Mapping[int, str]] |
| 44 | +DEFAULT_PORTS: Final[Mapping[_ProxyType, int]] |
| 45 | + |
| 46 | +_DefaultProxy: TypeAlias = tuple[_ProxyType | None, str | None, int | None, bool, bytes | None, bytes | None] |
| 47 | + |
| 48 | +def set_default_proxy( |
| 49 | + proxy_type: _ProxyType | None = None, |
| 50 | + addr: str | None = None, |
| 51 | + port: int | None = None, |
| 52 | + rdns: bool = True, |
| 53 | + username: str | None = None, |
| 54 | + password: str | None = None, |
| 55 | +) -> None: ... |
| 56 | +def setdefaultproxy(*args: Any, **kwargs: Any) -> None: ... |
| 57 | +def get_default_proxy() -> _DefaultProxy | None: ... |
| 58 | + |
| 59 | +getdefaultproxy = get_default_proxy |
| 60 | + |
| 61 | +def wrap_module(module: types.ModuleType) -> None: ... |
| 62 | + |
| 63 | +wrapmodule = wrap_module |
| 64 | + |
| 65 | +_Endpoint: TypeAlias = tuple[str, int] |
| 66 | + |
| 67 | +def create_connection( |
| 68 | + dest_pair: _Endpoint, |
| 69 | + timeout: int | None = None, |
| 70 | + source_address: _Endpoint | None = None, |
| 71 | + proxy_type: _ProxyType | None = None, |
| 72 | + proxy_addr: str | None = None, |
| 73 | + proxy_port: int | None = None, |
| 74 | + proxy_rdns: bool = True, |
| 75 | + proxy_username: str | None = None, |
| 76 | + proxy_password: str | None = None, |
| 77 | + socket_options: Any | None = None, |
| 78 | +) -> socksocket: ... |
| 79 | + |
| 80 | +class _BaseSocket(socket.socket): # undocumented |
| 81 | + def __init__(self, *pos: Any, **kw: Any) -> None: ... |
| 82 | + |
| 83 | +method: Any # undocumented |
| 84 | +name: str # undocumented |
| 85 | + |
| 86 | +class socksocket(_BaseSocket): |
| 87 | + default_proxy: _DefaultProxy | None # undocumented |
| 88 | + proxy: _DefaultProxy # undocumented |
| 89 | + proxy_sockname: _Endpoint | None # undocumented |
| 90 | + proxy_peername: _Endpoint | None # undocumented |
| 91 | + def __init__( |
| 92 | + self, family: socket.AddressFamily = ..., type: socket.SocketKind = ..., proto: int = 0, *args: Any, **kwargs: Any |
| 93 | + ) -> None: ... |
| 94 | + def settimeout(self, timeout: float | None) -> None: ... |
| 95 | + def gettimeout(self) -> float | None: ... |
| 96 | + def setblocking(self, v: bool) -> None: ... |
| 97 | + def set_proxy( |
| 98 | + self, |
| 99 | + proxy_type: _ProxyType | None = None, |
| 100 | + addr: str | None = None, |
| 101 | + port: int | None = None, |
| 102 | + rdns: bool = True, |
| 103 | + username: str | None = None, |
| 104 | + password: str | None = None, |
| 105 | + ) -> None: ... |
| 106 | + def setproxy(self, *args: Any, **kwargs: Any) -> None: ... |
| 107 | + def bind(self, *pos: Any, **kw: Any) -> None: ... |
| 108 | + def sendto(self, bytes: ReadableBuffer, *args: Any, **kwargs: Any) -> int: ... |
| 109 | + def send(self, bytes: ReadableBuffer, flags: int = 0, **kwargs: Any) -> int: ... |
| 110 | + def recvfrom(self, bufsize: int, flags: int = 0) -> tuple[bytes, _Endpoint]: ... |
| 111 | + def recv(self, *pos: Any, **kw: Any) -> bytes: ... |
| 112 | + def close(self) -> None: ... |
| 113 | + def get_proxy_sockname(self) -> _Endpoint | None: ... |
| 114 | + getproxysockname = get_proxy_sockname |
| 115 | + def get_proxy_peername(self) -> _Endpoint | None: ... |
| 116 | + getproxypeername = get_proxy_peername |
| 117 | + def get_peername(self) -> _Endpoint | None: ... |
| 118 | + getpeername = get_peername |
| 119 | + @set_self_blocking |
| 120 | + def connect(self, dest_pair: _Endpoint, catch_errors: bool | None = None) -> None: ... # type: ignore[override] |
| 121 | + @set_self_blocking |
| 122 | + def connect_ex(self, dest_pair: _Endpoint) -> int: ... # type: ignore[override] |
0 commit comments