Skip to content

Add urllib3 stubs #6858

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

Merged
merged 3 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"stubs/SQLAlchemy",
"stubs/stripe",
"stubs/ttkthemes",
"stubs/urllib3",
"stubs/vobject"
],
"typeCheckingMode": "basic",
Expand Down
59 changes: 59 additions & 0 deletions stubs/urllib3/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
urllib3.HTTPConnectionPool.__init__
urllib3.HTTPConnectionPool.urlopen
urllib3.HTTPResponse.__init__
urllib3.HTTPSConnectionPool.__init__
urllib3.NullHandler
urllib3.PoolManager.connection_from_host
urllib3.PoolManager.connection_from_url
urllib3.PoolManager.urlopen
urllib3.ProxyManager.__init__
urllib3.ProxyManager.connection_from_host
urllib3.ProxyManager.urlopen
urllib3.Retry.is_forced_retry
urllib3.Retry.sleep
urllib3._collections.HTTPHeaderDict.from_httplib
urllib3._collections.HTTPHeaderDict.getlist
urllib3._collections.RLock
urllib3.connection.HTTPConnection.request
urllib3.connection.HTTPSConnection.__init__
urllib3.connection.VerifiedHTTPSConnection.__init__
urllib3.connection.VerifiedHTTPSConnection.set_cert
urllib3.connectionpool.ConnectionError
urllib3.connectionpool.HTTPConnection.request
urllib3.connectionpool.HTTPConnectionPool.__init__
urllib3.connectionpool.HTTPConnectionPool.urlopen
urllib3.connectionpool.HTTPResponse.__init__
urllib3.connectionpool.HTTPSConnection.__init__
urllib3.connectionpool.HTTPSConnectionPool.__init__
urllib3.connectionpool.ProxyError.__init__
urllib3.connectionpool.RequestMethods.request_encode_url
urllib3.connectionpool.Retry.is_forced_retry
urllib3.connectionpool.Retry.sleep
urllib3.connectionpool.VerifiedHTTPSConnection.__init__
urllib3.connectionpool.VerifiedHTTPSConnection.set_cert
urllib3.exceptions.ProxyError.__init__
urllib3.fields.RequestField.__init__
urllib3.fields.RequestField.from_tuples
urllib3.filepost.RequestField.__init__
urllib3.filepost.RequestField.from_tuples
urllib3.packages.ssl_match_hostname
urllib3.packages.ssl_match_hostname._implementation
urllib3.poolmanager.PoolManager.connection_from_host
urllib3.poolmanager.PoolManager.connection_from_url
urllib3.poolmanager.PoolManager.urlopen
urllib3.poolmanager.ProxyManager.__init__
urllib3.poolmanager.ProxyManager.connection_from_host
urllib3.poolmanager.ProxyManager.urlopen
urllib3.request.RequestMethods.request_encode_url
urllib3.response.HTTPHeaderDict.from_httplib
urllib3.response.HTTPHeaderDict.getlist
urllib3.response.HTTPResponse.__init__
urllib3.response.PY3
urllib3.util.Retry.is_forced_retry
urllib3.util.Retry.sleep
urllib3.util.connection.poll
urllib3.util.connection.select
urllib3.util.retry.Retry.is_forced_retry
urllib3.util.retry.Retry.sleep
urllib3.util.ssl_.create_default_context
urllib3.util.ssl_.ssl_wrap_socket
1 change: 1 addition & 0 deletions stubs/urllib3/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.26.*"
26 changes: 26 additions & 0 deletions stubs/urllib3/urllib3/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging
from typing import Any

from . import connectionpool, filepost, poolmanager, response
from .util import request as _request, retry, timeout, url

__license__: Any

HTTPConnectionPool = connectionpool.HTTPConnectionPool
HTTPSConnectionPool = connectionpool.HTTPSConnectionPool
connection_from_url = connectionpool.connection_from_url
encode_multipart_formdata = filepost.encode_multipart_formdata
PoolManager = poolmanager.PoolManager
ProxyManager = poolmanager.ProxyManager
proxy_from_url = poolmanager.proxy_from_url
HTTPResponse = response.HTTPResponse
make_headers = _request.make_headers
get_host = url.get_host
Timeout = timeout.Timeout
Retry = retry.Retry

class NullHandler(logging.Handler):
def emit(self, record): ...

def add_stderr_logger(level=...): ...
def disable_warnings(category=...): ...
51 changes: 51 additions & 0 deletions stubs/urllib3/urllib3/_collections.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import Any, MutableMapping, NoReturn, TypeVar

_KT = TypeVar("_KT")
_VT = TypeVar("_VT")

class RLock:
def __enter__(self): ...
def __exit__(self, exc_type, exc_value, traceback): ...

class RecentlyUsedContainer(MutableMapping[_KT, _VT]):
ContainerCls: Any
dispose_func: Any
lock: Any
def __init__(self, maxsize=..., dispose_func=...) -> None: ...
def __getitem__(self, key): ...
def __setitem__(self, key, value): ...
def __delitem__(self, key): ...
def __len__(self): ...
def __iter__(self): ...
def clear(self): ...
def keys(self): ...

class HTTPHeaderDict(MutableMapping[str, str]):
def __init__(self, headers=..., **kwargs) -> None: ...
def __setitem__(self, key, val): ...
def __getitem__(self, key): ...
def __delitem__(self, key): ...
def __contains__(self, key): ...
def __eq__(self, other): ...
def __iter__(self) -> NoReturn: ...
def __len__(self) -> int: ...
def __ne__(self, other): ...
values: Any
get: Any
update: Any
iterkeys: Any
itervalues: Any
def pop(self, key, default=...): ...
def discard(self, key): ...
def add(self, key, val): ...
def extend(self, *args, **kwargs): ...
def getlist(self, key): ...
getheaders: Any
getallmatchingheaders: Any
iget: Any
def copy(self): ...
def iteritems(self): ...
def itermerged(self): ...
def items(self): ...
@classmethod
def from_httplib(cls, message, duplicates=...): ...
64 changes: 64 additions & 0 deletions stubs/urllib3/urllib3/connection.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import ssl
import sys
from typing import Any

from . import exceptions, util
from .packages import ssl_match_hostname
from .util import ssl_

if sys.version_info >= (3, 0):
from builtins import ConnectionError as ConnectionError
from http.client import HTTPConnection as _HTTPConnection, HTTPException as HTTPException
else:
from httplib import HTTPConnection as _HTTPConnection, HTTPException as HTTPException
class ConnectionError(Exception): ...

class DummyConnection: ...

BaseSSLError = ssl.SSLError

ConnectTimeoutError = exceptions.ConnectTimeoutError
SystemTimeWarning = exceptions.SystemTimeWarning
SecurityWarning = exceptions.SecurityWarning
match_hostname = ssl_match_hostname.match_hostname
resolve_cert_reqs = ssl_.resolve_cert_reqs
resolve_ssl_version = ssl_.resolve_ssl_version
ssl_wrap_socket = ssl_.ssl_wrap_socket
assert_fingerprint = ssl_.assert_fingerprint
connection = util.connection

port_by_scheme: Any
RECENT_DATE: Any

class HTTPConnection(_HTTPConnection):
default_port: Any
default_socket_options: Any
is_verified: Any
source_address: Any
socket_options: Any
def __init__(self, *args, **kw) -> None: ...
def connect(self): ...

class HTTPSConnection(HTTPConnection):
default_port: Any
key_file: Any
cert_file: Any
def __init__(self, host, port=..., key_file=..., cert_file=..., strict=..., timeout=..., **kw) -> None: ...
sock: Any
def connect(self): ...

class VerifiedHTTPSConnection(HTTPSConnection):
cert_reqs: Any
ca_certs: Any
ssl_version: Any
assert_fingerprint: Any
key_file: Any
cert_file: Any
assert_hostname: Any
def set_cert(self, key_file=..., cert_file=..., cert_reqs=..., ca_certs=..., assert_hostname=..., assert_fingerprint=...): ...
sock: Any
auto_open: Any
is_verified: Any
def connect(self): ...

UnverifiedHTTPSConnection = HTTPSConnection
121 changes: 121 additions & 0 deletions stubs/urllib3/urllib3/connectionpool.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from typing import Any

from . import connection, exceptions, request, response
from .connection import BaseSSLError as BaseSSLError, ConnectionError as ConnectionError, HTTPException as HTTPException
from .packages import ssl_match_hostname
from .util import connection as _connection, retry, timeout, url

ClosedPoolError = exceptions.ClosedPoolError
ProtocolError = exceptions.ProtocolError
EmptyPoolError = exceptions.EmptyPoolError
HostChangedError = exceptions.HostChangedError
LocationValueError = exceptions.LocationValueError
MaxRetryError = exceptions.MaxRetryError
ProxyError = exceptions.ProxyError
ReadTimeoutError = exceptions.ReadTimeoutError
SSLError = exceptions.SSLError
TimeoutError = exceptions.TimeoutError
InsecureRequestWarning = exceptions.InsecureRequestWarning
CertificateError = ssl_match_hostname.CertificateError
port_by_scheme = connection.port_by_scheme
DummyConnection = connection.DummyConnection
HTTPConnection = connection.HTTPConnection
HTTPSConnection = connection.HTTPSConnection
VerifiedHTTPSConnection = connection.VerifiedHTTPSConnection
RequestMethods = request.RequestMethods
HTTPResponse = response.HTTPResponse
is_connection_dropped = _connection.is_connection_dropped
Retry = retry.Retry
Timeout = timeout.Timeout
get_host = url.get_host

xrange: Any
log: Any

class ConnectionPool:
scheme: Any
QueueCls: Any
host: Any
port: Any
def __init__(self, host, port=...) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type, exc_val, exc_tb): ...
def close(self): ...

class HTTPConnectionPool(ConnectionPool, RequestMethods):
scheme: Any
ConnectionCls: Any
strict: Any
timeout: Any
retries: Any
pool: Any
block: Any
proxy: Any
proxy_headers: Any
num_connections: Any
num_requests: Any
conn_kw: Any
def __init__(
self,
host,
port=...,
strict=...,
timeout=...,
maxsize=...,
block=...,
headers=...,
retries=...,
_proxy=...,
_proxy_headers=...,
**conn_kw,
) -> None: ...
def close(self): ...
def is_same_host(self, url): ...
def urlopen(
self,
method,
url,
body=...,
headers=...,
retries=...,
redirect=...,
assert_same_host=...,
timeout=...,
pool_timeout=...,
release_conn=...,
**response_kw,
): ...

class HTTPSConnectionPool(HTTPConnectionPool):
scheme: Any
ConnectionCls: Any
key_file: Any
cert_file: Any
cert_reqs: Any
ca_certs: Any
ssl_version: Any
assert_hostname: Any
assert_fingerprint: Any
def __init__(
self,
host,
port=...,
strict=...,
timeout=...,
maxsize=...,
block=...,
headers=...,
retries=...,
_proxy=...,
_proxy_headers=...,
key_file=...,
cert_file=...,
cert_reqs=...,
ca_certs=...,
ssl_version=...,
assert_hostname=...,
assert_fingerprint=...,
**conn_kw,
) -> None: ...

def connection_from_url(url, **kw): ...
Empty file.
50 changes: 50 additions & 0 deletions stubs/urllib3/urllib3/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import Any

class HTTPError(Exception): ...
class HTTPWarning(Warning): ...

class PoolError(HTTPError):
pool: Any
def __init__(self, pool, message) -> None: ...
def __reduce__(self): ...

class RequestError(PoolError):
url: Any
def __init__(self, pool, url, message) -> None: ...
def __reduce__(self): ...

class SSLError(HTTPError): ...
class ProxyError(HTTPError): ...
class DecodeError(HTTPError): ...
class ProtocolError(HTTPError): ...

ConnectionError: Any

class MaxRetryError(RequestError):
reason: Any
def __init__(self, pool, url, reason=...) -> None: ...

class HostChangedError(RequestError):
retries: Any
def __init__(self, pool, url, retries=...) -> None: ...

class TimeoutStateError(HTTPError): ...
class TimeoutError(HTTPError): ...
class ReadTimeoutError(TimeoutError, RequestError): ...
class ConnectTimeoutError(TimeoutError): ...
class EmptyPoolError(PoolError): ...
class ClosedPoolError(PoolError): ...
class LocationValueError(ValueError, HTTPError): ...

class LocationParseError(LocationValueError):
location: Any
def __init__(self, location) -> None: ...

class ResponseError(HTTPError):
GENERIC_ERROR: Any
SPECIFIC_ERROR: Any

class SecurityWarning(HTTPWarning): ...
class InsecureRequestWarning(SecurityWarning): ...
class SystemTimeWarning(SecurityWarning): ...
class InsecurePlatformWarning(SecurityWarning): ...
Loading