mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-03 01:53:24 +08:00
Add missing methods in urllib.request (#4571)
This commit is contained in:
@@ -4,7 +4,24 @@ import sys
|
||||
from email.message import Message
|
||||
from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol
|
||||
from http.cookiejar import CookieJar
|
||||
from typing import IO, Any, Callable, ClassVar, Dict, List, Mapping, NoReturn, Optional, Sequence, Tuple, TypeVar, Union, overload
|
||||
from typing import (
|
||||
IO,
|
||||
Any,
|
||||
Callable,
|
||||
ClassVar,
|
||||
Dict,
|
||||
List,
|
||||
Mapping,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Pattern,
|
||||
Sequence,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
from urllib.error import HTTPError
|
||||
from urllib.response import addinfourl
|
||||
|
||||
_T = TypeVar("_T")
|
||||
@@ -65,12 +82,14 @@ class Request:
|
||||
@overload
|
||||
def get_header(self, header_name: str, default: _T) -> Union[str, _T]: ...
|
||||
def header_items(self) -> List[Tuple[str, str]]: ...
|
||||
def has_proxy(self) -> bool: ...
|
||||
|
||||
class OpenerDirector:
|
||||
addheaders: List[Tuple[str, str]]
|
||||
def add_handler(self, handler: BaseHandler) -> None: ...
|
||||
def open(self, fullurl: Union[str, Request], data: Optional[bytes] = ..., timeout: Optional[float] = ...) -> _UrlopenRet: ...
|
||||
def error(self, proto: str, *args: Any) -> _UrlopenRet: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
class BaseHandler:
|
||||
handler_order: ClassVar[int]
|
||||
@@ -79,9 +98,15 @@ class BaseHandler:
|
||||
def close(self) -> None: ...
|
||||
def http_error_nnn(self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]) -> _UrlopenRet: ...
|
||||
|
||||
class HTTPDefaultErrorHandler(BaseHandler): ...
|
||||
class HTTPDefaultErrorHandler(BaseHandler):
|
||||
def http_error_default(
|
||||
self, req: Request, fp: IO[bytes], code: int, msg: str, hdrs: Mapping[str, str]
|
||||
) -> HTTPError: ... # undocumented
|
||||
|
||||
class HTTPRedirectHandler(BaseHandler):
|
||||
max_redirections: ClassVar[int] # undocumented
|
||||
max_repeats: ClassVar[int] # undocumented
|
||||
inf_msg: ClassVar[str] # undocumented
|
||||
def redirect_request(
|
||||
self, req: Request, fp: IO[str], code: int, msg: str, headers: Mapping[str, str], newurl: str
|
||||
) -> Optional[Request]: ...
|
||||
@@ -101,14 +126,21 @@ class HTTPRedirectHandler(BaseHandler):
|
||||
class HTTPCookieProcessor(BaseHandler):
|
||||
cookiejar: CookieJar
|
||||
def __init__(self, cookiejar: Optional[CookieJar] = ...) -> None: ...
|
||||
def http_request(self, request: Request) -> Request: ... # undocumented
|
||||
def http_response(self, request: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented
|
||||
def https_request(self, request: Request) -> Request: ... # undocumented
|
||||
def https_response(self, request: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented
|
||||
|
||||
class ProxyHandler(BaseHandler):
|
||||
def __init__(self, proxies: Optional[Dict[str, str]] = ...) -> None: ...
|
||||
def proxy_open(self, req: Request, proxy: str, type: str) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
# TODO add a method for every (common) proxy protocol
|
||||
|
||||
class HTTPPasswordMgr:
|
||||
def add_password(self, realm: str, uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ...
|
||||
def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ...
|
||||
def is_suburi(self, base: str, test: str) -> bool: ... # undocumented
|
||||
def reduce_uri(self, uri: str, default_port: bool = ...) -> str: ... # undocumented
|
||||
|
||||
class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr):
|
||||
def add_password(self, realm: Optional[str], uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ...
|
||||
@@ -122,15 +154,23 @@ class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm):
|
||||
def is_authenticated(self, authuri: str) -> bool: ...
|
||||
|
||||
class AbstractBasicAuthHandler:
|
||||
rx: ClassVar[Pattern] # undocumented
|
||||
def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ...
|
||||
def http_error_auth_reqed(self, authreq: str, host: str, req: Request, headers: Mapping[str, str]) -> None: ...
|
||||
def http_request(self, req: Request) -> Request: ... # undocumented
|
||||
def http_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented
|
||||
def https_request(self, req: Request) -> Request: ... # undocumented
|
||||
def https_response(self, req: Request, response: HTTPResponse) -> HTTPResponse: ... # undocumented
|
||||
def retry_http_basic_auth(self, host: str, req: Request, realm: str) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
|
||||
class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
|
||||
auth_header: ClassVar[str] # undocumented
|
||||
def http_error_401(
|
||||
self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]
|
||||
) -> Optional[_UrlopenRet]: ...
|
||||
|
||||
class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
|
||||
auth_header: ClassVar[str]
|
||||
def http_error_407(
|
||||
self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]
|
||||
) -> Optional[_UrlopenRet]: ...
|
||||
@@ -146,11 +186,13 @@ class AbstractDigestAuthHandler:
|
||||
def get_entity_digest(self, data: Optional[bytes], chal: Mapping[str, str]) -> Optional[str]: ...
|
||||
|
||||
class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
|
||||
auth_header: ClassVar[str] # undocumented
|
||||
def http_error_401(
|
||||
self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]
|
||||
) -> Optional[_UrlopenRet]: ...
|
||||
|
||||
class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
|
||||
auth_header: ClassVar[str] # undocumented
|
||||
def http_error_407(
|
||||
self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]
|
||||
) -> Optional[_UrlopenRet]: ...
|
||||
@@ -173,17 +215,33 @@ class HTTPSHandler(AbstractHTTPHandler):
|
||||
def https_request(self, request: Request) -> Request: ... # undocumented
|
||||
|
||||
class FileHandler(BaseHandler):
|
||||
names: ClassVar[Optional[Tuple[str, ...]]] # undocumented
|
||||
def file_open(self, req: Request) -> addinfourl: ...
|
||||
def get_names(self) -> Tuple[str, ...]: ... # undocumented
|
||||
def open_local_file(self, req: Request) -> addinfourl: ... # undocumented
|
||||
|
||||
class DataHandler(BaseHandler):
|
||||
def data_open(self, req: Request) -> addinfourl: ...
|
||||
|
||||
class ftpwrapper: # undocumented
|
||||
def __init__(
|
||||
self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: Optional[float] = ..., persistent: bool = ...
|
||||
) -> None: ...
|
||||
|
||||
class FTPHandler(BaseHandler):
|
||||
def ftp_open(self, req: Request) -> addinfourl: ...
|
||||
def connect_ftp(
|
||||
self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float
|
||||
) -> ftpwrapper: ... # undocumented
|
||||
|
||||
class CacheFTPHandler(FTPHandler):
|
||||
def setTimeout(self, t: float) -> None: ...
|
||||
def setMaxConns(self, m: int) -> None: ...
|
||||
def check_cache(self) -> None: ... # undocumented
|
||||
def clear_cache(self) -> None: ... # undocumented
|
||||
def connect_ftp(
|
||||
self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: float
|
||||
) -> ftpwrapper: ... # undocumented
|
||||
|
||||
class UnknownHandler(BaseHandler):
|
||||
def unknown_open(self, req: Request) -> NoReturn: ...
|
||||
@@ -222,6 +280,73 @@ class URLopener:
|
||||
reporthook: Optional[Callable[[int, int, int], None]] = ...,
|
||||
data: Optional[bytes] = ...,
|
||||
) -> Tuple[str, Optional[Message]]: ...
|
||||
def addheader(self, *args: Tuple[str, str]) -> None: ... # undocumented
|
||||
def cleanup(self) -> None: ... # undocumented
|
||||
def close(self) -> None: ... # undocumented
|
||||
def http_error(
|
||||
self, url: str, fp: IO[bytes], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ...
|
||||
) -> _UrlopenRet: ... # undocumented
|
||||
def http_error_default(
|
||||
self, url: str, fp: IO[bytes], errcode: int, errmsg: str, headers: Mapping[str, str]
|
||||
) -> _UrlopenRet: ... # undocumented
|
||||
def open_data(self, url: str, data: Optional[bytes] = ...) -> addinfourl: ... # undocumented
|
||||
def open_file(self, url: str) -> addinfourl: ... # undocumented
|
||||
def open_ftp(self, url: str) -> addinfourl: ... # undocumented
|
||||
def open_http(self, url: str, data: Optional[bytes] = ...) -> _UrlopenRet: ... # undocumented
|
||||
def open_https(self, url: str, data: Optional[bytes] = ...) -> _UrlopenRet: ... # undocumented
|
||||
def open_local_file(self, url: str) -> addinfourl: ... # undocumented
|
||||
def open_unknown_proxy(self, proxy: str, fullurl: str, data: Optional[bytes] = ...) -> None: ... # undocumented
|
||||
|
||||
class FancyURLopener(URLopener):
|
||||
def prompt_user_passwd(self, host: str, realm: str) -> Tuple[str, str]: ...
|
||||
def get_user_passwd(self, host: str, realm: str, clear_cache: int = ...) -> Tuple[str, str]: ... # undocumented
|
||||
def http_error_301(
|
||||
self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ...
|
||||
) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented
|
||||
def http_error_302(
|
||||
self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ...
|
||||
) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented
|
||||
def http_error_303(
|
||||
self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ...
|
||||
) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented
|
||||
def http_error_307(
|
||||
self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes] = ...
|
||||
) -> Optional[Union[_UrlopenRet, addinfourl]]: ... # undocumented
|
||||
def http_error_401(
|
||||
self,
|
||||
url: str,
|
||||
fp: IO[str],
|
||||
errcode: int,
|
||||
errmsg: str,
|
||||
headers: Mapping[str, str],
|
||||
data: Optional[bytes] = ...,
|
||||
retry: bool = ...,
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
def http_error_407(
|
||||
self,
|
||||
url: str,
|
||||
fp: IO[str],
|
||||
errcode: int,
|
||||
errmsg: str,
|
||||
headers: Mapping[str, str],
|
||||
data: Optional[bytes] = ...,
|
||||
retry: bool = ...,
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
def http_error_default(
|
||||
self, url: str, fp: IO[bytes], errcode: int, errmsg: str, headers: Mapping[str, str]
|
||||
) -> addinfourl: ... # undocumented
|
||||
def redirect_internal(
|
||||
self, url: str, fp: IO[str], errcode: int, errmsg: str, headers: Mapping[str, str], data: Optional[bytes]
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
def retry_http_basic_auth(
|
||||
self, url: str, realm: str, data: Optional[bytes] = ...
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
def retry_https_basic_auth(
|
||||
self, url: str, realm: str, data: Optional[bytes] = ...
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
def retry_proxy_http_basic_auth(
|
||||
self, url: str, realm: str, data: Optional[bytes] = ...
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
def retry_proxy_https_basic_auth(
|
||||
self, url: str, realm: str, data: Optional[bytes] = ...
|
||||
) -> Optional[_UrlopenRet]: ... # undocumented
|
||||
|
||||
Reference in New Issue
Block a user