From 1cffceb767ea0da01b4d03cce8d97f9bbe3d08b3 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 30 Jun 2021 16:54:02 +0200 Subject: [PATCH] Add httplib2 third-party stubs (#5713) --- pyrightconfig.stricter.json | 1 + stubs/httplib2/@tests/stubtest_allowlist.txt | 2 + stubs/httplib2/METADATA.toml | 1 + stubs/httplib2/httplib2/__init__.pyi | 186 +++++++++++++++++++ stubs/httplib2/httplib2/auth.pyi | 15 ++ stubs/httplib2/httplib2/certs.pyi | 9 + stubs/httplib2/httplib2/error.pyi | 18 ++ stubs/httplib2/httplib2/iri2uri.pyi | 12 ++ stubs/httplib2/httplib2/socks.pyi | 42 +++++ 9 files changed, 286 insertions(+) create mode 100644 stubs/httplib2/@tests/stubtest_allowlist.txt create mode 100644 stubs/httplib2/METADATA.toml create mode 100644 stubs/httplib2/httplib2/__init__.pyi create mode 100644 stubs/httplib2/httplib2/auth.pyi create mode 100644 stubs/httplib2/httplib2/certs.pyi create mode 100644 stubs/httplib2/httplib2/error.pyi create mode 100644 stubs/httplib2/httplib2/iri2uri.pyi create mode 100644 stubs/httplib2/httplib2/socks.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 104695c45..e435c6446 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -33,6 +33,7 @@ "stubs/docutils", "stubs/Flask", "stubs/html5lib", + "stubs/httplib2", "stubs/Jinja2", "stubs/Markdown", "stubs/Pillow", diff --git a/stubs/httplib2/@tests/stubtest_allowlist.txt b/stubs/httplib2/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..6b90fbdac --- /dev/null +++ b/stubs/httplib2/@tests/stubtest_allowlist.txt @@ -0,0 +1,2 @@ +# __getattr__() replaced with actual field in stub +httplib2.Response.dict diff --git a/stubs/httplib2/METADATA.toml b/stubs/httplib2/METADATA.toml new file mode 100644 index 000000000..7918a438b --- /dev/null +++ b/stubs/httplib2/METADATA.toml @@ -0,0 +1 @@ +version = "0.19" diff --git a/stubs/httplib2/httplib2/__init__.pyi b/stubs/httplib2/httplib2/__init__.pyi new file mode 100644 index 000000000..7813440b4 --- /dev/null +++ b/stubs/httplib2/httplib2/__init__.pyi @@ -0,0 +1,186 @@ +import http.client +from collections.abc import Generator +from typing import Any, Dict, TypeVar + +from .error import * + +# Should use _typeshed.Self when google/pytype#952 is fixed. +Self = TypeVar("Self") # noqa Y001 + +__author__: str +__copyright__: str +__contributors__: list[str] +__license__: str +__version__: str + +debuglevel: int +RETRIES: 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): ... + 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 __bool__(self): ... + +class BasicAuthentication(Authentication): + def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ... + def request(self, method, request_uri, headers, content) -> None: ... + +class DigestAuthentication(Authentication): + challenge: Any + A1: Any + def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ... + def request(self, method, request_uri, headers, content, cnonce: Any | None = ...): ... + def response(self, response, content): ... + +class HmacDigestAuthentication(Authentication): + challenge: Any + hashmod: Any + pwhashmod: Any + key: Any + 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): ... + +class WsseAuthentication(Authentication): + def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ... + def request(self, method, request_uri, headers, content) -> None: ... + +class GoogleLoginAuthentication(Authentication): + Auth: str + def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ... + def request(self, method, request_uri, headers, content) -> None: ... + +class FileCache: + cache: Any + safe: Any + 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 + def __init__(self) -> None: ... + def add(self, name, password, domain: str = ...) -> None: ... + def clear(self) -> None: ... + def iter(self, domain) -> Generator[tuple[str, str], None, None]: ... + +class KeyCerts(Credentials): + def add(self, key, cert, domain, password) -> None: ... # type: ignore + def iter(self, domain) -> Generator[tuple[str, str, str], None, None]: ... # type: ignore + +class AllHosts: ... + +class ProxyInfo: + bypass_hosts: Any + def __init__( + self, + proxy_type, + proxy_host, + proxy_port, + proxy_rdns: bool = ..., + proxy_user: Any | None = ..., + proxy_pass: Any | None = ..., + proxy_headers: Any | None = ..., + ) -> None: ... + def astuple(self): ... + def isgood(self): ... + def applies_to(self, hostname): ... + def bypass_host(self, hostname): ... + +class HTTPConnectionWithTimeout(http.client.HTTPConnection): + proxy_info: Any + def __init__(self, host, port: Any | None = ..., timeout: Any | None = ..., proxy_info: Any | None = ...) -> None: ... + sock: Any + 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 + def __init__( + self, + host, + port: Any | None = ..., + key_file: Any | None = ..., + cert_file: Any | None = ..., + timeout: Any | None = ..., + proxy_info: Any | None = ..., + ca_certs: Any | None = ..., + disable_ssl_certificate_validation: bool = ..., + tls_maximum_version: Any | None = ..., + tls_minimum_version: Any | None = ..., + key_password: Any | None = ..., + ) -> None: ... + sock: Any + def connect(self) -> None: ... + +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 + follow_redirects: bool + redirect_codes: Any + optimistic_concurrency_methods: Any + safe_methods: Any + follow_all_redirects: bool + ignore_etag: bool + force_exception_to_status_code: bool + timeout: Any + forward_authorization_headers: bool + def __init__( + self, + cache: Any | None = ..., + timeout: Any | None = ..., + proxy_info=..., + ca_certs: Any | None = ..., + disable_ssl_certificate_validation: bool = ..., + tls_maximum_version: Any | None = ..., + tls_minimum_version: Any | None = ..., + ) -> None: ... + def close(self) -> None: ... + def add_credentials(self, name, password, domain: str = ...) -> None: ... + def add_certificate(self, key, cert, domain, password: Any | None = ...) -> None: ... + def clear_credentials(self) -> None: ... + def request( + self, + uri, + method: str = ..., + body: Any | None = ..., + headers: Any | None = ..., + redirections=..., + connection_type: Any | None = ..., + ): ... + +class Response(Dict[str, Any]): + fromcache: bool + version: int + status: int + reason: str + previous: Any + def __init__(self, info) -> None: ... + @property + def dict(self: Self) -> Self: ... diff --git a/stubs/httplib2/httplib2/auth.pyi b/stubs/httplib2/httplib2/auth.pyi new file mode 100644 index 000000000..d7168f153 --- /dev/null +++ b/stubs/httplib2/httplib2/auth.pyi @@ -0,0 +1,15 @@ +from typing import Any + +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 diff --git a/stubs/httplib2/httplib2/certs.pyi b/stubs/httplib2/httplib2/certs.pyi new file mode 100644 index 000000000..c0a5ce2b9 --- /dev/null +++ b/stubs/httplib2/httplib2/certs.pyi @@ -0,0 +1,9 @@ +from typing import Any + +certifi_available: bool +certifi_where: Any +custom_ca_locater_available: bool +custom_ca_locater_where: Any +BUILTIN_CA_CERTS: Any + +def where(): ... diff --git a/stubs/httplib2/httplib2/error.pyi b/stubs/httplib2/httplib2/error.pyi new file mode 100644 index 000000000..1287702e2 --- /dev/null +++ b/stubs/httplib2/httplib2/error.pyi @@ -0,0 +1,18 @@ +from typing import Any + +class HttpLib2Error(Exception): ... + +class HttpLib2ErrorWithResponse(HttpLib2Error): + response: Any + content: Any + def __init__(self, desc, response, content) -> None: ... + +class RedirectMissingLocation(HttpLib2ErrorWithResponse): ... +class RedirectLimit(HttpLib2ErrorWithResponse): ... +class FailedToDecompressContent(HttpLib2ErrorWithResponse): ... +class UnimplementedDigestAuthOptionError(HttpLib2ErrorWithResponse): ... +class UnimplementedHmacDigestAuthOptionError(HttpLib2ErrorWithResponse): ... +class MalformedHeader(HttpLib2Error): ... +class RelativeURIError(HttpLib2Error): ... +class ServerNotFoundError(HttpLib2Error): ... +class ProxiesUnavailableError(HttpLib2Error): ... diff --git a/stubs/httplib2/httplib2/iri2uri.pyi b/stubs/httplib2/httplib2/iri2uri.pyi new file mode 100644 index 000000000..7365d894e --- /dev/null +++ b/stubs/httplib2/httplib2/iri2uri.pyi @@ -0,0 +1,12 @@ +from typing import Any + +__author__: str +__copyright__: str +__contributors__: list[str] +__version__: str +__license__: str + +escape_range: Any + +def encode(c): ... +def iri2uri(uri): ... diff --git a/stubs/httplib2/httplib2/socks.pyi b/stubs/httplib2/httplib2/socks.pyi new file mode 100644 index 000000000..c65363dee --- /dev/null +++ b/stubs/httplib2/httplib2/socks.pyi @@ -0,0 +1,42 @@ +import socket +from typing import Any + +PROXY_TYPE_SOCKS4: int +PROXY_TYPE_SOCKS5: int +PROXY_TYPE_HTTP: int +PROXY_TYPE_HTTP_NO_TUNNEL: int + +class ProxyError(Exception): ... +class GeneralProxyError(ProxyError): ... +class Socks5AuthError(ProxyError): ... +class Socks5Error(ProxyError): ... +class Socks4Error(ProxyError): ... +class HTTPError(ProxyError): ... + +def setdefaultproxy( + proxytype: Any | None = ..., + addr: Any | None = ..., + port: Any | None = ..., + rdns: bool = ..., + username: Any | None = ..., + password: Any | None = ..., +) -> None: ... +def wrapmodule(module) -> None: ... + +class socksocket(socket.socket): + def __init__(self, family=..., type=..., proto: int = ..., _sock: Any | None = ...) -> None: ... + def sendall(self, content, *args): ... + def setproxy( + self, + proxytype: Any | None = ..., + addr: Any | None = ..., + port: Any | None = ..., + rdns: bool = ..., + username: Any | None = ..., + password: Any | None = ..., + headers: Any | None = ..., + ) -> None: ... + def getproxysockname(self): ... + def getproxypeername(self): ... + def getpeername(self): ... + def connect(self, destpair) -> None: ...