Skip to content

Commit b66eb8c

Browse files
authored
[httplib2] Improve stubs (#14249)
1 parent 04a0cc6 commit b66eb8c

File tree

6 files changed

+183
-115
lines changed

6 files changed

+183
-115
lines changed

stubs/httplib2/httplib2/__init__.pyi

Lines changed: 101 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,84 @@
1+
import email.message
12
import http.client
3+
import re
4+
from _ssl import _PasswordType
5+
from _typeshed import Incomplete, MaybeNone, StrOrBytesPath
26
from collections.abc import Generator
3-
from typing import Any, ClassVar
7+
from ssl import _SSLMethod
8+
from typing import ClassVar, Final, Literal, TypeVar
49
from typing_extensions import Self
510

611
from .error import *
712

8-
__author__: str
9-
__copyright__: str
10-
__contributors__: list[str]
11-
__license__: str
12-
__version__: str
13+
_T = TypeVar("_T", default=str)
1314

14-
debuglevel: int
15-
RETRIES: int
15+
__author__: Final[str]
16+
__copyright__: Final[str]
17+
__contributors__: Final[list[str]]
18+
__license__: Final[str]
19+
__version__: Final[str]
20+
21+
def has_timeout(timeout: float | None) -> bool: ...
22+
23+
debuglevel: Final[int]
24+
RETRIES: Final[int]
25+
DEFAULT_MAX_REDIRECTS: Final[int]
26+
HOP_BY_HOP: Final[list[str]]
27+
SAFE_METHODS: Final[tuple[str, ...]]
28+
REDIRECT_CODES: Final[frozenset[int]]
29+
CA_CERTS: Final[str]
30+
DEFAULT_TLS_VERSION: Final[_SSLMethod]
31+
URI: Final[re.Pattern[str]]
32+
33+
def parse_uri(uri: str) -> tuple[str | MaybeNone, str | MaybeNone, str | MaybeNone, str | MaybeNone, str | MaybeNone]: ...
34+
def urlnorm(uri: str) -> tuple[str | MaybeNone, str | MaybeNone, str | MaybeNone, str | MaybeNone]: ...
35+
36+
re_url_scheme: Final[re.Pattern[str]]
37+
re_unsafe: Final[re.Pattern[str]]
38+
39+
def safename(filename: str | bytes) -> str: ...
40+
41+
NORMALIZE_SPACE: Final[re.Pattern[str]]
42+
USE_WWW_AUTH_STRICT_PARSING: Final[int]
1643

1744
class Authentication:
18-
path: Any
19-
host: Any
20-
credentials: Any
21-
http: Any
22-
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
23-
def depth(self, request_uri): ...
24-
def inscope(self, host, request_uri): ...
45+
path: Incomplete
46+
host: Incomplete
47+
credentials: Incomplete
48+
http: Incomplete
49+
def __init__(self, credentials, host, request_uri: str, headers, response, content, http) -> None: ...
50+
def depth(self, request_uri: str) -> int: ...
51+
def inscope(self, host: str, request_uri: str) -> bool: ...
2552
def request(self, method, request_uri, headers, content) -> None: ...
26-
def response(self, response, content): ...
27-
def __eq__(self, auth): ...
28-
def __ne__(self, auth): ...
29-
def __lt__(self, auth): ...
30-
def __gt__(self, auth): ...
31-
def __le__(self, auth): ...
32-
def __ge__(self, auth): ...
53+
def response(self, response, content) -> bool: ...
54+
def __eq__(self, auth: object) -> bool: ...
55+
def __ne__(self, auth: object) -> bool: ...
56+
def __lt__(self, auth: object) -> bool: ...
57+
def __gt__(self, auth: object) -> bool: ...
58+
def __le__(self, auth: object) -> bool: ...
59+
def __ge__(self, auth: object) -> bool: ...
3360
def __bool__(self) -> bool: ...
3461

3562
class BasicAuthentication(Authentication):
3663
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
3764
def request(self, method, request_uri, headers, content) -> None: ...
3865

3966
class DigestAuthentication(Authentication):
40-
challenge: Any
41-
A1: Any
67+
challenge: Incomplete
68+
A1: Incomplete
4269
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
4370
def request(self, method, request_uri, headers, content, cnonce=None): ...
44-
def response(self, response, content): ...
71+
def response(self, response, content) -> bool: ...
4572

4673
class HmacDigestAuthentication(Authentication):
47-
challenge: Any
48-
hashmod: Any
49-
pwhashmod: Any
50-
key: Any
74+
challenge: Incomplete
75+
hashmod: Incomplete
76+
pwhashmod: Incomplete
77+
key: Incomplete
5178
__author__: ClassVar[str]
5279
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
5380
def request(self, method, request_uri, headers, content) -> None: ...
54-
def response(self, response, content): ...
81+
def response(self, response, content) -> bool: ...
5582

5683
class WsseAuthentication(Authentication):
5784
def __init__(self, credentials, host, request_uri, headers, response, content, http) -> None: ...
@@ -63,15 +90,15 @@ class GoogleLoginAuthentication(Authentication):
6390
def request(self, method, request_uri, headers, content) -> None: ...
6491

6592
class FileCache:
66-
cache: Any
67-
safe: Any
93+
cache: Incomplete
94+
safe: Incomplete
6895
def __init__(self, cache, safe=...) -> None: ...
6996
def get(self, key): ...
7097
def set(self, key, value) -> None: ...
7198
def delete(self, key) -> None: ...
7299

73100
class Credentials:
74-
credentials: Any
101+
credentials: Incomplete
75102
def __init__(self) -> None: ...
76103
def add(self, name, password, domain: str = "") -> None: ...
77104
def clear(self) -> None: ...
@@ -84,7 +111,7 @@ class KeyCerts(Credentials):
84111
class AllHosts: ...
85112

86113
class ProxyInfo:
87-
bypass_hosts: Any
114+
bypass_hosts: Incomplete
88115
def __init__(
89116
self, proxy_type, proxy_host, proxy_port, proxy_rdns: bool = True, proxy_user=None, proxy_pass=None, proxy_headers=None
90117
) -> None: ...
@@ -93,60 +120,65 @@ class ProxyInfo:
93120
def applies_to(self, hostname): ...
94121
def bypass_host(self, hostname): ...
95122

123+
def proxy_info_from_environment(method: Literal["http", "https"] = "http") -> ProxyInfo | None: ...
124+
def proxy_info_from_url(url: str, method: Literal["http", "https"] = "http", noproxy: str | None = None) -> ProxyInfo: ...
125+
96126
class HTTPConnectionWithTimeout(http.client.HTTPConnection):
97-
proxy_info: Any
127+
proxy_info: Incomplete
98128
def __init__(self, host, port=None, timeout=None, proxy_info=None) -> None: ...
99-
sock: Any
129+
sock: Incomplete
100130
def connect(self) -> None: ...
101131

102132
class HTTPSConnectionWithTimeout(http.client.HTTPSConnection):
103-
disable_ssl_certificate_validation: Any
104-
ca_certs: Any
105-
proxy_info: Any
106-
key_file: Any
107-
cert_file: Any
108-
key_password: Any
133+
disable_ssl_certificate_validation: bool
134+
ca_certs: StrOrBytesPath | None
135+
proxy_info: Incomplete
136+
key_file: StrOrBytesPath | None
137+
cert_file: StrOrBytesPath | None
138+
key_password: _PasswordType | None
109139
def __init__(
110140
self,
111-
host,
112-
port=None,
113-
key_file=None,
114-
cert_file=None,
115-
timeout=None,
141+
host: str,
142+
port: int | None = None,
143+
key_file: StrOrBytesPath | None = None,
144+
cert_file: StrOrBytesPath | None = None,
145+
timeout: float | None = None,
116146
proxy_info=None,
117-
ca_certs=None,
147+
ca_certs: StrOrBytesPath | None = None,
118148
disable_ssl_certificate_validation: bool = False,
119149
tls_maximum_version=None,
120150
tls_minimum_version=None,
121-
key_password=None,
151+
key_password: _PasswordType | None = None,
122152
) -> None: ...
123-
sock: Any
153+
sock: Incomplete
124154
def connect(self) -> None: ...
125155

156+
SCHEME_TO_CONNECTION: Final[dict[Literal["http", "https"], type[http.client.HTTPConnection]]]
157+
126158
class Http:
127-
proxy_info: Any
128-
ca_certs: Any
129-
disable_ssl_certificate_validation: Any
130-
tls_maximum_version: Any
131-
tls_minimum_version: Any
132-
connections: Any
133-
cache: Any
134-
credentials: Any
135-
certificates: Any
136-
authorizations: Any
159+
proxy_info: Incomplete
160+
ca_certs: Incomplete
161+
disable_ssl_certificate_validation: bool
162+
tls_maximum_version: Incomplete
163+
tls_minimum_version: Incomplete
164+
connections: Incomplete
165+
cache: FileCache
166+
credentials: Credentials
167+
certificates: KeyCerts
168+
authorizations: list[Authentication]
137169
follow_redirects: bool
138-
redirect_codes: Any
139-
optimistic_concurrency_methods: Any
140-
safe_methods: Any
170+
redirect_codes: frozenset[int]
171+
optimistic_concurrency_methods: list[str]
172+
safe_methods: list[str]
141173
follow_all_redirects: bool
142174
ignore_etag: bool
143175
force_exception_to_status_code: bool
144-
timeout: Any
176+
timeout: float | None
145177
forward_authorization_headers: bool
146178
def __init__(
147179
self,
148-
cache=None,
149-
timeout=None,
180+
cache: str | FileCache | None = None,
181+
timeout: float | None = None,
150182
proxy_info=...,
151183
ca_certs=None,
152184
disable_ssl_certificate_validation: bool = False,
@@ -159,13 +191,13 @@ class Http:
159191
def clear_credentials(self) -> None: ...
160192
def request(self, uri, method: str = "GET", body=None, headers=None, redirections=5, connection_type=None): ...
161193

162-
class Response(dict[str, Any]):
194+
class Response(dict[str, str | _T]):
163195
fromcache: bool
164196
version: int
165197
status: int
166198
reason: str
167-
previous: Any
168-
def __init__(self, info) -> None: ...
199+
previous: Response[_T] | None
200+
def __init__(self, info: http.client.HTTPResponse | email.message.Message | dict[str, _T]) -> None: ...
169201
@property
170202
def dict(self) -> Self: ...
171203

stubs/httplib2/httplib2/auth.pyi

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
from typing import Any
1+
import re
2+
from _typeshed import Incomplete
3+
from collections.abc import Callable
4+
from typing import Final
25

3-
UNQUOTE_PAIRS: Any
4-
unquote: Any
5-
tchar: Any
6-
token: Any
7-
token68: Any
8-
quoted_string: Any
9-
auth_param_name: Any
10-
auth_param: Any
11-
params: Any
12-
scheme: Any
13-
challenge: Any
14-
authentication_info: Any
15-
www_authenticate: Any
16-
downcaseTokens: Any
6+
UNQUOTE_PAIRS: Final[re.Pattern[str]]
7+
unquote: Callable[..., str]
8+
tchar: Final[str]
9+
token: Incomplete # types from pyparsing library
10+
token68: Incomplete
11+
quoted_string: Incomplete
12+
auth_param_name: Incomplete
13+
auth_param: Incomplete
14+
params: Incomplete
15+
scheme: Incomplete
16+
challenge: Incomplete
17+
authentication_info: Incomplete
18+
www_authenticate: Incomplete
19+
downcaseTokens: Incomplete

stubs/httplib2/httplib2/certs.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from typing import Any
1+
from collections.abc import Callable
2+
from typing import Final
23

34
certifi_available: bool
4-
certifi_where: Any
5+
certifi_where: Callable[[], str] | None
56
custom_ca_locater_available: bool
6-
custom_ca_locater_where: Any
7-
BUILTIN_CA_CERTS: Any
7+
custom_ca_locater_where: Callable[..., str] | None
8+
BUILTIN_CA_CERTS: Final[str]
89

9-
def where(): ...
10+
def where() -> str: ...

stubs/httplib2/httplib2/error.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from typing import Any
1+
from _typeshed import Incomplete
2+
3+
from httplib2 import Response
24

35
class HttpLib2Error(Exception): ...
46

57
class HttpLib2ErrorWithResponse(HttpLib2Error):
6-
response: Any
7-
content: Any
8-
def __init__(self, desc, response, content) -> None: ...
8+
response: Response | dict[str, Incomplete] | None
9+
content: str | bytes | None
10+
def __init__(
11+
self, desc: str | None, response: Response | dict[str, Incomplete] | None, content: str | bytes | None
12+
) -> None: ...
913

1014
class RedirectMissingLocation(HttpLib2ErrorWithResponse): ...
1115
class RedirectLimit(HttpLib2ErrorWithResponse): ...
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from typing import Any
1+
from typing import Final, TypeVar
22

3-
__author__: str
4-
__copyright__: str
5-
__contributors__: list[str]
6-
__version__: str
7-
__license__: str
3+
_T = TypeVar("_T")
84

9-
escape_range: Any
5+
__author__: Final[str]
6+
__copyright__: Final[str]
7+
__contributors__: Final[list[str]]
8+
__version__: Final[str]
9+
__license__: Final[str]
1010

11-
def encode(c): ...
12-
def iri2uri(uri): ...
11+
escape_range: list[tuple[int, int]]
12+
13+
def encode(c: str) -> str: ...
14+
def iri2uri(uri: _T) -> _T: ...

0 commit comments

Comments
 (0)