-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add type stub for PySocks #14623
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
Open
Chocobo1
wants to merge
7
commits into
python:main
Choose a base branch
from
Chocobo1:stub_pysocks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add type stub for PySocks #14623
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ca58fd
Add type stub for PySocks
Chocobo1 9c77375
Address review comments
Chocobo1 fe95a03
Address review comments
Chocobo1 0f28010
Address flake8 Y065 error
Chocobo1 50a2e52
back to Any
Chocobo1 f064113
Fix merge_dict typing
Chocobo1 a3ffa7a
address review comment
Chocobo1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = "1.7.1" | ||
upstream_repository = "https://github.com/Anorov/PySocks" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import logging | ||
import socket | ||
import types | ||
from _typeshed import ReadableBuffer | ||
from collections.abc import Callable, Iterable, Mapping | ||
from typing import Any, Final, TypeVar | ||
from typing_extensions import ParamSpec, TypeAlias | ||
|
||
__version__: Final[str] | ||
|
||
log: logging.Logger # undocumented | ||
|
||
_ProxyType: TypeAlias = int | ||
|
||
PROXY_TYPE_SOCKS4: Final[_ProxyType] | ||
SOCKS4: Final[_ProxyType] | ||
PROXY_TYPE_SOCKS5: Final[_ProxyType] | ||
SOCKS5: Final[_ProxyType] | ||
PROXY_TYPE_HTTP: Final[_ProxyType] | ||
HTTP: Final[_ProxyType] | ||
|
||
PROXY_TYPES: Final[dict[str, _ProxyType]] | ||
PRINTABLE_PROXY_TYPES: Final[dict[_ProxyType, str]] | ||
|
||
_T = TypeVar("_T") | ||
_P = ParamSpec("_P") | ||
|
||
def set_self_blocking(function: Callable[_P, _T]) -> Callable[_P, _T]: ... # undocumented | ||
|
||
class ProxyError(IOError): | ||
msg: str | ||
socket_err: socket.error | ||
def __init__(self, msg: str, socket_err: socket.error | None = None) -> None: ... | ||
|
||
class GeneralProxyError(ProxyError): ... | ||
class ProxyConnectionError(ProxyError): ... | ||
class SOCKS5AuthError(ProxyError): ... | ||
class SOCKS5Error(ProxyError): ... | ||
class SOCKS4Error(ProxyError): ... | ||
class HTTPError(ProxyError): ... | ||
|
||
SOCKS4_ERRORS: Final[Mapping[int, str]] | ||
SOCKS5_ERRORS: Final[Mapping[int, str]] | ||
DEFAULT_PORTS: Final[Mapping[_ProxyType, int]] | ||
|
||
_DefaultProxy: TypeAlias = tuple[_ProxyType | None, str | None, int | None, bool, bytes | None, bytes | None] | ||
|
||
def set_default_proxy( | ||
proxy_type: _ProxyType | None = None, | ||
addr: str | None = None, | ||
port: int | None = None, | ||
rdns: bool = True, | ||
username: str | None = None, | ||
password: str | None = None, | ||
) -> None: ... | ||
def setdefaultproxy(*args: Any, **kwargs: Any) -> None: ... | ||
def get_default_proxy() -> _DefaultProxy | None: ... | ||
|
||
getdefaultproxy = get_default_proxy | ||
|
||
def wrap_module(module: types.ModuleType) -> None: ... | ||
|
||
wrapmodule = wrap_module | ||
|
||
_Endpoint: TypeAlias = tuple[str, int] | ||
|
||
def create_connection( | ||
dest_pair: _Endpoint, | ||
timeout: int | None = None, | ||
source_address: _Endpoint | None = None, | ||
proxy_type: _ProxyType | None = None, | ||
proxy_addr: str | None = None, | ||
proxy_port: int | None = None, | ||
proxy_rdns: bool = True, | ||
proxy_username: str | None = None, | ||
proxy_password: str | None = None, | ||
socket_options: ( | ||
Iterable[tuple[int, int, int | ReadableBuffer] | tuple[int, int, None, int]] | None | ||
) = None, # values passing to `socket.setsockopt` method | ||
) -> socksocket: ... | ||
|
||
class _BaseSocket(socket.socket): # undocumented | ||
def __init__(self, *pos: Any, **kw: Any) -> None: ... | ||
Chocobo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
method: object # undocumented | ||
name: object # undocumented | ||
|
||
class socksocket(_BaseSocket): | ||
default_proxy: _DefaultProxy | None # undocumented | ||
proxy: _DefaultProxy # undocumented | ||
proxy_sockname: _Endpoint | None # undocumented | ||
proxy_peername: _Endpoint | None # undocumented | ||
def __init__( | ||
self, family: socket.AddressFamily = ..., type: socket.SocketKind = ..., proto: int = 0, *args: Any, **kwargs: Any | ||
Chocobo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> None: ... | ||
def settimeout(self, timeout: float | None) -> None: ... | ||
def gettimeout(self) -> float | None: ... | ||
def setblocking(self, v: bool) -> None: ... | ||
def set_proxy( | ||
self, | ||
proxy_type: _ProxyType | None = None, | ||
addr: str | None = None, | ||
port: int | None = None, | ||
rdns: bool = True, | ||
username: str | None = None, | ||
password: str | None = None, | ||
) -> None: ... | ||
def setproxy(self, *args: Any, **kwargs: Any) -> None: ... | ||
def bind(self, *pos: Any, **kw: Any) -> None: ... | ||
def sendto(self, bytes: ReadableBuffer, *args: Any, **kwargs: Any) -> int: ... | ||
def send(self, bytes: ReadableBuffer, flags: int = 0, **kwargs: Any) -> int: ... | ||
def recvfrom(self, bufsize: int, flags: int = 0) -> tuple[bytes, _Endpoint]: ... | ||
def recv(self, *pos: Any, **kw: Any) -> bytes: ... | ||
def close(self) -> None: ... | ||
def get_proxy_sockname(self) -> _Endpoint | None: ... | ||
getproxysockname = get_proxy_sockname | ||
def get_proxy_peername(self) -> _Endpoint | None: ... | ||
getproxypeername = get_proxy_peername | ||
def get_peername(self) -> _Endpoint | None: ... | ||
getpeername = get_peername | ||
@set_self_blocking | ||
def connect(self, dest_pair: _Endpoint, catch_errors: bool | None = None) -> None: ... # type: ignore[override] | ||
@set_self_blocking | ||
def connect_ex(self, dest_pair: _Endpoint) -> int: ... # type: ignore[override] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import http.client | ||
import urllib.request | ||
from _typeshed import Incomplete, SupportsKeysAndGetItem | ||
from typing import Any, TypeVar | ||
from typing_extensions import override | ||
|
||
import socks | ||
|
||
_K = TypeVar("_K") | ||
_V = TypeVar("_V") | ||
|
||
def merge_dict(a: dict[_K, _V], b: SupportsKeysAndGetItem[_K, _V]) -> dict[_K, _V]: ... # undocumented | ||
def is_ip(s: str) -> bool: ... # undocumented | ||
|
||
socks4_no_rdns: set[str] # undocumented | ||
|
||
class SocksiPyConnection(http.client.HTTPConnection): # undocumented | ||
proxyargs: tuple[int, str, int | None, bool, str | None, str | None] | ||
sock: socks.socksocket | ||
def __init__( | ||
self, | ||
proxytype: int, | ||
proxyaddr: str, | ||
proxyport: int | None = None, | ||
rdns: bool = True, | ||
username: str | None = None, | ||
password: str | None = None, | ||
*args: Any, | ||
**kwargs: Any, | ||
) -> None: ... | ||
@override | ||
def connect(self) -> None: ... | ||
|
||
class SocksiPyConnectionS(http.client.HTTPSConnection): # undocumented | ||
proxyargs: tuple[int, str, int | None, bool, str | None, str | None] | ||
sock: socks.socksocket | ||
def __init__( | ||
self, | ||
proxytype: int, | ||
proxyaddr: str, | ||
proxyport: int | None = None, | ||
rdns: bool = True, | ||
username: str | None = None, | ||
password: str | None = None, | ||
*args: Any, | ||
**kwargs: Any, | ||
) -> None: ... | ||
@override | ||
def connect(self) -> None: ... | ||
|
||
class SocksiPyHandler(urllib.request.HTTPHandler, urllib.request.HTTPSHandler): | ||
args: tuple[Incomplete, ...] # undocumented | ||
kw: dict[str, Incomplete] # undocumented | ||
def __init__(self, *args: Any, **kwargs: Any) -> None: ... | ||
@override | ||
def http_open(self, req: urllib.request.Request) -> http.client.HTTPResponse: ... # undocumented | ||
@override | ||
def https_open(self, req: urllib.request.Request) -> http.client.HTTPResponse: ... # undocumented |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.