[httplib2] Improve stubs (#14249)

This commit is contained in:
Semyon Moroz
2025-06-21 17:47:55 +00:00
committed by GitHub
parent 04a0cc67f1
commit b66eb8c0e7
6 changed files with 184 additions and 116 deletions
+101 -69
View File
@@ -1,35 +1,62 @@
import email.message
import http.client
import re
from _ssl import _PasswordType
from _typeshed import Incomplete, MaybeNone, StrOrBytesPath
from collections.abc import Generator
from typing import Any, ClassVar
from ssl import _SSLMethod
from typing import ClassVar, Final, Literal, TypeVar
from typing_extensions import Self
from .error import *
__author__: str
__copyright__: str
__contributors__: list[str]
__license__: str
__version__: str
_T = TypeVar("_T", default=str)
debuglevel: int
RETRIES: int
__author__: Final[str]
__copyright__: Final[str]
__contributors__: Final[list[str]]
__license__: Final[str]
__version__: Final[str]
def has_timeout(timeout: float | None) -> bool: ...
debuglevel: Final[int]
RETRIES: Final[int]
DEFAULT_MAX_REDIRECTS: Final[int]
HOP_BY_HOP: Final[list[str]]
SAFE_METHODS: Final[tuple[str, ...]]
REDIRECT_CODES: Final[frozenset[int]]
CA_CERTS: Final[str]
DEFAULT_TLS_VERSION: Final[_SSLMethod]
URI: Final[re.Pattern[str]]
def parse_uri(uri: str) -> tuple[str | MaybeNone, str | MaybeNone, str | MaybeNone, str | MaybeNone, str | MaybeNone]: ...
def urlnorm(uri: str) -> tuple[str | MaybeNone, str | MaybeNone, str | MaybeNone, str | MaybeNone]: ...
re_url_scheme: Final[re.Pattern[str]]
re_unsafe: Final[re.Pattern[str]]
def safename(filename: str | bytes) -> str: ...
NORMALIZE_SPACE: Final[re.Pattern[str]]
USE_WWW_AUTH_STRICT_PARSING: Final[int]
class Authentication:
path: Any
host: Any
credentials: Any
http: Any
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
def depth(self, request_uri): ...
def inscope(self, host, request_uri): ...
path: Incomplete
host: Incomplete
credentials: Incomplete
http: Incomplete
def __init__(self, credentials, host, request_uri: str, headers, response, content, http) -> None: ...
def depth(self, request_uri: str) -> int: ...
def inscope(self, host: str, request_uri: str) -> bool: ...
def request(self, method, request_uri, headers, content) -> None: ...
def response(self, response, content): ...
def __eq__(self, auth): ...
def __ne__(self, auth): ...
def __lt__(self, auth): ...
def __gt__(self, auth): ...
def __le__(self, auth): ...
def __ge__(self, auth): ...
def response(self, response, content) -> bool: ...
def __eq__(self, auth: object) -> bool: ...
def __ne__(self, auth: object) -> bool: ...
def __lt__(self, auth: object) -> bool: ...
def __gt__(self, auth: object) -> bool: ...
def __le__(self, auth: object) -> bool: ...
def __ge__(self, auth: object) -> bool: ...
def __bool__(self) -> bool: ...
class BasicAuthentication(Authentication):
@@ -37,21 +64,21 @@ class BasicAuthentication(Authentication):
def request(self, method, request_uri, headers, content) -> None: ...
class DigestAuthentication(Authentication):
challenge: Any
A1: Any
challenge: Incomplete
A1: Incomplete
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
def request(self, method, request_uri, headers, content, cnonce=None): ...
def response(self, response, content): ...
def response(self, response, content) -> bool: ...
class HmacDigestAuthentication(Authentication):
challenge: Any
hashmod: Any
pwhashmod: Any
key: Any
challenge: Incomplete
hashmod: Incomplete
pwhashmod: Incomplete
key: Incomplete
__author__: ClassVar[str]
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
def request(self, method, request_uri, headers, content) -> None: ...
def response(self, response, content): ...
def response(self, response, content) -> bool: ...
class WsseAuthentication(Authentication):
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
@@ -63,15 +90,15 @@ class GoogleLoginAuthentication(Authentication):
def request(self, method, request_uri, headers, content) -> None: ...
class FileCache:
cache: Any
safe: Any
cache: Incomplete
safe: Incomplete
def __init__(self, cache, safe=...) -> None: ...
def get(self, key): ...
def set(self, key, value) -> None: ...
def delete(self, key) -> None: ...
class Credentials:
credentials: Any
credentials: Incomplete
def __init__(self) -> None: ...
def add(self, name, password, domain: str = "") -> None: ...
def clear(self) -> None: ...
@@ -84,7 +111,7 @@ class KeyCerts(Credentials):
class AllHosts: ...
class ProxyInfo:
bypass_hosts: Any
bypass_hosts: Incomplete
def __init__(
self, proxy_type, proxy_host, proxy_port, proxy_rdns: bool = True, proxy_user=None, proxy_pass=None, proxy_headers=None
) -> None: ...
@@ -93,60 +120,65 @@ class ProxyInfo:
def applies_to(self, hostname): ...
def bypass_host(self, hostname): ...
def proxy_info_from_environment(method: Literal["http", "https"] = "http") -> ProxyInfo | None: ...
def proxy_info_from_url(url: str, method: Literal["http", "https"] = "http", noproxy: str | None = None) -> ProxyInfo: ...
class HTTPConnectionWithTimeout(http.client.HTTPConnection):
proxy_info: Any
proxy_info: Incomplete
def __init__(self, host, port=None, timeout=None, proxy_info=None) -> None: ...
sock: Any
sock: Incomplete
def connect(self) -> None: ...
class HTTPSConnectionWithTimeout(http.client.HTTPSConnection):
disable_ssl_certificate_validation: Any
ca_certs: Any
proxy_info: Any
key_file: Any
cert_file: Any
key_password: Any
disable_ssl_certificate_validation: bool
ca_certs: StrOrBytesPath | None
proxy_info: Incomplete
key_file: StrOrBytesPath | None
cert_file: StrOrBytesPath | None
key_password: _PasswordType | None
def __init__(
self,
host,
port=None,
key_file=None,
cert_file=None,
timeout=None,
host: str,
port: int | None = None,
key_file: StrOrBytesPath | None = None,
cert_file: StrOrBytesPath | None = None,
timeout: float | None = None,
proxy_info=None,
ca_certs=None,
ca_certs: StrOrBytesPath | None = None,
disable_ssl_certificate_validation: bool = False,
tls_maximum_version=None,
tls_minimum_version=None,
key_password=None,
key_password: _PasswordType | None = None,
) -> None: ...
sock: Any
sock: Incomplete
def connect(self) -> None: ...
SCHEME_TO_CONNECTION: Final[dict[Literal["http", "https"], type[http.client.HTTPConnection]]]
class Http:
proxy_info: Any
ca_certs: Any
disable_ssl_certificate_validation: Any
tls_maximum_version: Any
tls_minimum_version: Any
connections: Any
cache: Any
credentials: Any
certificates: Any
authorizations: Any
proxy_info: Incomplete
ca_certs: Incomplete
disable_ssl_certificate_validation: bool
tls_maximum_version: Incomplete
tls_minimum_version: Incomplete
connections: Incomplete
cache: FileCache
credentials: Credentials
certificates: KeyCerts
authorizations: list[Authentication]
follow_redirects: bool
redirect_codes: Any
optimistic_concurrency_methods: Any
safe_methods: Any
redirect_codes: frozenset[int]
optimistic_concurrency_methods: list[str]
safe_methods: list[str]
follow_all_redirects: bool
ignore_etag: bool
force_exception_to_status_code: bool
timeout: Any
timeout: float | None
forward_authorization_headers: bool
def __init__(
self,
cache=None,
timeout=None,
cache: str | FileCache | None = None,
timeout: float | None = None,
proxy_info=...,
ca_certs=None,
disable_ssl_certificate_validation: bool = False,
@@ -159,13 +191,13 @@ class Http:
def clear_credentials(self) -> None: ...
def request(self, uri, method: str = "GET", body=None, headers=None, redirections=5, connection_type=None): ...
class Response(dict[str, Any]):
class Response(dict[str, str | _T]):
fromcache: bool
version: int
status: int
reason: str
previous: Any
def __init__(self, info) -> None: ...
previous: Response[_T] | None
def __init__(self, info: http.client.HTTPResponse | email.message.Message | dict[str, _T]) -> None: ...
@property
def dict(self) -> Self: ...
+18 -15
View File
@@ -1,16 +1,19 @@
from typing import Any
import re
from _typeshed import Incomplete
from collections.abc import Callable
from typing import Final
UNQUOTE_PAIRS: Any
unquote: Any
tchar: Any
token: Any
token68: Any
quoted_string: Any
auth_param_name: Any
auth_param: Any
params: Any
scheme: Any
challenge: Any
authentication_info: Any
www_authenticate: Any
downcaseTokens: Any
UNQUOTE_PAIRS: Final[re.Pattern[str]]
unquote: Callable[..., str]
tchar: Final[str]
token: Incomplete # types from pyparsing library
token68: Incomplete
quoted_string: Incomplete
auth_param_name: Incomplete
auth_param: Incomplete
params: Incomplete
scheme: Incomplete
challenge: Incomplete
authentication_info: Incomplete
www_authenticate: Incomplete
downcaseTokens: Incomplete
+6 -5
View File
@@ -1,9 +1,10 @@
from typing import Any
from collections.abc import Callable
from typing import Final
certifi_available: bool
certifi_where: Any
certifi_where: Callable[[], str] | None
custom_ca_locater_available: bool
custom_ca_locater_where: Any
BUILTIN_CA_CERTS: Any
custom_ca_locater_where: Callable[..., str] | None
BUILTIN_CA_CERTS: Final[str]
def where(): ...
def where() -> str: ...
+8 -4
View File
@@ -1,11 +1,15 @@
from typing import Any
from _typeshed import Incomplete
from httplib2 import Response
class HttpLib2Error(Exception): ...
class HttpLib2ErrorWithResponse(HttpLib2Error):
response: Any
content: Any
def __init__(self, desc, response, content) -> None: ...
response: Response | dict[str, Incomplete] | None
content: str | bytes | None
def __init__(
self, desc: str | None, response: Response | dict[str, Incomplete] | None, content: str | bytes | None
) -> None: ...
class RedirectMissingLocation(HttpLib2ErrorWithResponse): ...
class RedirectLimit(HttpLib2ErrorWithResponse): ...
+11 -9
View File
@@ -1,12 +1,14 @@
from typing import Any
from typing import Final, TypeVar
__author__: str
__copyright__: str
__contributors__: list[str]
__version__: str
__license__: str
_T = TypeVar("_T")
escape_range: Any
__author__: Final[str]
__copyright__: Final[str]
__contributors__: Final[list[str]]
__version__: Final[str]
__license__: Final[str]
def encode(c): ...
def iri2uri(uri): ...
escape_range: list[tuple[int, int]]
def encode(c: str) -> str: ...
def iri2uri(uri: _T) -> _T: ...
+40 -14
View File
@@ -1,9 +1,15 @@
import socket
from _typeshed import Incomplete, ReadableBuffer
from types import ModuleType
from typing import Final, Literal
from typing_extensions import TypeAlias
PROXY_TYPE_SOCKS4: int
PROXY_TYPE_SOCKS5: int
PROXY_TYPE_HTTP: int
PROXY_TYPE_HTTP_NO_TUNNEL: int
_ProxyType: TypeAlias = Literal[1, 2, 3, 4]
PROXY_TYPE_SOCKS4: Final[_ProxyType]
PROXY_TYPE_SOCKS5: Final[_ProxyType]
PROXY_TYPE_HTTP: Final[_ProxyType]
PROXY_TYPE_HTTP_NO_TUNNEL: Final[_ProxyType]
class ProxyError(Exception): ...
class GeneralProxyError(ProxyError): ...
@@ -12,16 +18,36 @@ class Socks5Error(ProxyError): ...
class Socks4Error(ProxyError): ...
class HTTPError(ProxyError): ...
def setdefaultproxy(proxytype=None, addr=None, port=None, rdns: bool = True, username=None, password=None) -> None: ...
def wrapmodule(module) -> None: ...
def setdefaultproxy(
proxytype: _ProxyType | None = None,
addr: str | None = None,
port: int | None = None,
rdns: bool = True,
username: str | None = None,
password: str | None = None,
) -> None: ...
def wrapmodule(module: ModuleType) -> None: ...
class socksocket(socket.socket):
def __init__(self, family=..., type=..., proto: int = 0, _sock=None) -> None: ...
def sendall(self, content, *args): ...
def setproxy(
self, proxytype=None, addr=None, port=None, rdns: bool = True, username=None, password=None, headers=None
def __init__(
self,
family: socket.AddressFamily | int = ...,
type: socket.SocketKind | int = ...,
proto: int = 0,
_sock: int | None = None,
) -> None: ...
def getproxysockname(self): ...
def getproxypeername(self): ...
def getpeername(self): ...
def connect(self, destpair) -> None: ...
def sendall(self, content: ReadableBuffer, flags: int = ...) -> None: ... # type: ignore[override]
def setproxy(
self,
proxytype: _ProxyType | None = None,
addr: str | None = None,
port: int | None = None,
rdns: bool = True,
username: str | None = None,
password: str | None = None,
headers: dict[str, str] | None = None,
) -> None: ...
def getproxysockname(self) -> tuple[str | bytes, Incomplete] | None: ...
def getproxypeername(self) -> socket._RetAddress: ...
def getpeername(self) -> tuple[str | bytes, Incomplete] | None: ...
def connect(self, destpair: list[str | bytes | int] | tuple[str | bytes, int]) -> None: ... # type: ignore[override]