diff --git a/stdlib/2/urllib2.pyi b/stdlib/2/urllib2.pyi index 51758f2f3..bee73f1cc 100644 --- a/stdlib/2/urllib2.pyi +++ b/stdlib/2/urllib2.pyi @@ -1,6 +1,6 @@ import ssl -from typing import Any, AnyStr, Dict, List, Union, Optional, Mapping, Callable, Sequence, Tuple, Type +from typing import Any, AnyStr, Dict, List, Union, Optional, Mapping, Callable, Sequence, Text, Tuple, Type from urllib import addinfourl from httplib import HTTPConnectionProtocol, HTTPResponse @@ -11,8 +11,8 @@ class URLError(IOError): class HTTPError(URLError, addinfourl): code = ... # type: int - headers = ... # type: Dict[str, str] - def __init__(self, url, code, msg, hdrs, fp) -> None: ... + headers: Mapping[str, str] + def __init__(self, url, code: int, msg: str, hdrs: Mapping[str, str], fp: addinfourl) -> None: ... class Request(object): host = ... # type: str @@ -22,7 +22,7 @@ class Request(object): unverifiable = ... # type: bool type = ... # type: Optional[str] origin_req_host = ... - unredirected_hdrs = ... + unredirected_hdrs: Dict[str, str] def __init__(self, url: str, data: Optional[str] = ..., headers: Dict[str, str] = ..., origin_req_host: Optional[str] = ..., unverifiable: bool = ...) -> None: ... @@ -46,13 +46,15 @@ class Request(object): def header_items(self): ... class OpenerDirector(object): + addheaders: List[Tuple[str, str]] + def add_handler(self, handler: BaseHandler) -> None: ... - def open(self, url: Union[Request, _string], data: Optional[_string] = ..., timeout: Optional[float] = ...): ... + def open(self, fullurl: Union[Request, _string], data: Optional[_string] = ..., timeout: Optional[float] = ...) -> Optional[addinfourl]: ... def error(self, proto: _string, *args: Any): ... def urlopen(url: Union[Request, _string], data: Optional[_string] = ..., timeout: Optional[float] = ..., cafile: Optional[_string] = ..., capath: Optional[_string] = ..., cadefault: bool = ..., - context: Optional[ssl.SSLContext] = ...): ... + context: Optional[ssl.SSLContext] = ...) -> Optional[addinfourl]: ... def install_opener(opener: OpenerDirector) -> None: ... def build_opener(*handlers: Union[BaseHandler, Type[BaseHandler]]) -> OpenerDirector: ... @@ -68,27 +70,29 @@ class HTTPErrorProcessor(BaseHandler): def http_response(self, request, response): ... class HTTPDefaultErrorHandler(BaseHandler): - def http_error_default(self, req, fp, code, msg, hdrs): ... + def http_error_default(self, req: Request, fp: addinfourl, code: int, msg: str, hdrs: Mapping[str, str]): ... class HTTPRedirectHandler(BaseHandler): max_repeats = ... # type: int max_redirections = ... # type: int - def redirect_request(self, req, fp, code, msg, headers, newurl): ... - def http_error_301(self, req, fp, code, msg, headers): ... - def http_error_302(self, req, fp, code, msg, headers): ... - def http_error_303(self, req, fp, code, msg, headers): ... - def http_error_307(self, req, fp, code, msg, headers): ... + def redirect_request(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str], newurl): ... + def http_error_301(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... + def http_error_302(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... + def http_error_303(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... + def http_error_307(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... inf_msg = ... # type: str class ProxyHandler(BaseHandler): - def __init__(self, proxies: Optional[Any] = ...): ... - def proxy_open(self, req, proxy, type): ... + proxies: Mapping[str, str] + + def __init__(self, proxies: Optional[Mapping[str, str]] = ...): ... + def proxy_open(self, req: Request, proxy, type): ... class HTTPPasswordMgr: def __init__(self) -> None: ... - def add_password(self, realm: _string, uri: Union[_string, Sequence[_string]], user: _string, passwd: _string) -> None: ... - def find_user_password(self, realm: _string, authuri: _string) -> Tuple[Any, Any]: ... + def add_password(self, realm: Optional[Text], uri: Union[Text, Sequence[Text]], user: Text, passwd: Text) -> None: ... + def find_user_password(self, realm: Optional[Text], authuri: Text) -> Tuple[Any, Any]: ... def reduce_uri(self, uri: _string, default_port: bool = ...) -> Tuple[Any, Any]: ... def is_suburi(self, base: _string, test: _string) -> bool: ... @@ -96,19 +100,21 @@ class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): ... class AbstractBasicAuthHandler: def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ... - def http_error_auth_reqed(self, authreq, host, req, headers): ... - def retry_http_basic_auth(self, host, req, realm): ... + def add_password(self, realm: Optional[Text], uri: Union[Text, Sequence[Text]], user: Text, passwd: Text) -> None: ... + def http_error_auth_reqed(self, authreq, host, req: Request, headers: Mapping[str, str]): ... + def retry_http_basic_auth(self, host, req: Request, realm): ... class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): auth_header = ... # type: str - def http_error_401(self, req, fp, code, msg, headers): ... + def http_error_401(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): auth_header = ... # type: str - def http_error_407(self, req, fp, code, msg, headers): ... + def http_error_407(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... class AbstractDigestAuthHandler: def __init__(self, passwd: Optional[HTTPPasswordMgr] = ...) -> None: ... + def add_password(self, realm: Optional[Text], uri: Union[Text, Sequence[Text]], user: Text, passwd: Text) -> None: ... def reset_retry_count(self) -> None: ... def http_error_auth_reqed(self, auth_header: str, host: str, req: Request, headers: Mapping[str, str]) -> None: ... @@ -121,12 +127,12 @@ class AbstractDigestAuthHandler: class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): auth_header = ... # type: str handler_order = ... # type: int - def http_error_401(self, req, fp, code, msg, headers): ... + def http_error_401(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): auth_header = ... # type: str handler_order = ... # type: int - def http_error_407(self, req, fp, code, msg, headers): ... + def http_error_407(self, req: Request, fp: addinfourl, code: int, msg: str, headers: Mapping[str, str]): ... class AbstractHTTPHandler(BaseHandler): # undocumented def __init__(self, debuglevel: int = ...) -> None: ... @@ -148,25 +154,25 @@ class HTTPSHandler(AbstractHTTPHandler): class HTTPCookieProcessor(BaseHandler): def __init__(self, cookiejar: Optional[Any] = ...): ... - def http_request(self, request): ... - def http_response(self, request, response): ... + def http_request(self, request: Request): ... + def http_response(self, request: Request, response): ... class UnknownHandler(BaseHandler): - def unknown_open(self, req): ... + def unknown_open(self, req: Request): ... class FileHandler(BaseHandler): - def file_open(self, req): ... + def file_open(self, req: Request): ... def get_names(self): ... - def open_local_file(self, req): ... + def open_local_file(self, req: Request): ... class FTPHandler(BaseHandler): - def ftp_open(self, req): ... + def ftp_open(self, req: Request): ... def connect_ftp(self, user, passwd, host, port, dirs, timeout): ... class CacheFTPHandler(FTPHandler): def __init__(self) -> None: ... def setTimeout(self, t: Optional[float]): ... - def setMaxConns(self, m): ... + def setMaxConns(self, m: int): ... def check_cache(self): ... def clear_cache(self): ...