From fcb63d20288ae7b18a296ce7034bec2e96c2a4ef Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 27 Jan 2016 21:33:26 -0800 Subject: [PATCH 1/4] Add stubs for UserList, UserString, UserDict. --- stdlib/2.7/UserList.pyi | 3 +++ stdlib/2.7/UserString.pyi | 4 ++++ stdlib/2.7/collections.pyi | 7 +------ stdlib/3/collections.pyi | 7 ++++--- third_party/2.7/six/moves/__init__.pyi | 4 ++-- third_party/3/six/moves/__init__.pyi | 6 +++--- 6 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 stdlib/2.7/UserList.pyi create mode 100644 stdlib/2.7/UserString.pyi diff --git a/stdlib/2.7/UserList.pyi b/stdlib/2.7/UserList.pyi new file mode 100644 index 000000000..4f31b93b0 --- /dev/null +++ b/stdlib/2.7/UserList.pyi @@ -0,0 +1,3 @@ +import collections + +class UserList(collections.MutableSequence): ... diff --git a/stdlib/2.7/UserString.pyi b/stdlib/2.7/UserString.pyi new file mode 100644 index 000000000..d2a33c32a --- /dev/null +++ b/stdlib/2.7/UserString.pyi @@ -0,0 +1,4 @@ +import collections + +class UserString(collections.Sequence): ... +class MutableString(UserString, collections.MutableSequence): ... \ No newline at end of file diff --git a/stdlib/2.7/collections.pyi b/stdlib/2.7/collections.pyi index ab40403a6..69f13677a 100644 --- a/stdlib/2.7/collections.pyi +++ b/stdlib/2.7/collections.pyi @@ -2,16 +2,13 @@ # Based on http://docs.python.org/2.7/library/collections.html -# TODO UserDict -# TODO UserList -# TODO UserString # TODO more abstract base classes (interfaces in mypy) # NOTE: These are incomplete! from typing import ( Dict, Generic, TypeVar, Iterable, Tuple, Callable, Mapping, overload, Iterator, Sized, - Optional, List, Set, Sequence, Union, Reversible + Optional, List, Set, Sequence, Union, Reversible, MutableMapping, MutableSequence ) import typing @@ -22,8 +19,6 @@ _VT = TypeVar('_VT') # namedtuple is special-cased in the type checker; the initializer is ignored. namedtuple = object() -MutableMapping = typing.MutableMapping - class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ..., maxlen: int = ...) -> None: ... diff --git a/stdlib/3/collections.pyi b/stdlib/3/collections.pyi index 956cb286f..4939e9268 100644 --- a/stdlib/3/collections.pyi +++ b/stdlib/3/collections.pyi @@ -2,9 +2,6 @@ # Based on http://docs.python.org/3.2/library/collections.html -# TODO UserDict -# TODO UserList -# TODO UserString # TODO more abstract base classes (interfaces in mypy) # These are not exported. @@ -30,6 +27,10 @@ _VT = TypeVar('_VT') # namedtuple is special-cased in the type checker; the initializer is ignored. namedtuple = object() +class UserDict(MutableMapping): ... +class UserList(MutableSequence): ... +class UserString(Sequence): ... +class MutableString(UserString, MutableSequence): ... # Technically, deque only derives from MutableSequence in 3.5. # But in practice it's not worth losing sleep over. diff --git a/third_party/2.7/six/moves/__init__.pyi b/third_party/2.7/six/moves/__init__.pyi index 827ee8a5d..1347e7510 100644 --- a/third_party/2.7/six/moves/__init__.pyi +++ b/third_party/2.7/six/moves/__init__.pyi @@ -14,8 +14,8 @@ from __builtin__ import reduce as reduce from pipes import quote as shlex_quote from StringIO import StringIO as StringIO from UserDict import UserDict as UserDict -## from UserList import UserList as UserList -## from UserString import UserString as UserString +from UserList import UserList as UserList +from UserString import UserString as UserString from __builtin__ import xrange as xrange from itertools import izip as zip from itertools import izip_longest as zip_longest diff --git a/third_party/3/six/moves/__init__.pyi b/third_party/3/six/moves/__init__.pyi index 4f41143e9..49cf9bcab 100644 --- a/third_party/3/six/moves/__init__.pyi +++ b/third_party/3/six/moves/__init__.pyi @@ -16,9 +16,9 @@ from imp import reload as reload_module from functools import reduce as reduce from shlex import quote as shlex_quote from io import StringIO as StringIO -# from collections import UserDict as UserDict -# from collections import UserList as UserList -# from collections import UserString as UserString +from collections import UserDict as UserDict +from collections import UserList as UserList +from collections import UserString as UserString from builtins import range as xrange from builtins import zip as zip from itertools import zip_longest as zip_longest From 0cb13efa282fa4d69cc40b34e43885e672a1aaf6 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 27 Jan 2016 22:08:23 -0800 Subject: [PATCH 2/4] Add python 2 urllib2 stubs. --- stdlib/2.7/urllib2.pyi | 149 +++++++++++++++++++ third_party/2.7/six/moves/urllib/request.pyi | 50 +++---- 2 files changed, 174 insertions(+), 25 deletions(-) create mode 100644 stdlib/2.7/urllib2.pyi diff --git a/stdlib/2.7/urllib2.pyi b/stdlib/2.7/urllib2.pyi new file mode 100644 index 000000000..966e6a8b0 --- /dev/null +++ b/stdlib/2.7/urllib2.pyi @@ -0,0 +1,149 @@ + +from urllib import addinfourl + +class URLError(IOError): ... + +class HTTPError(URLError, addinfourl): ... + +class Request(object): + host = ... # type: str + port = ... # type: str + data = ... # type: str + headers = ... # type: Dict[str, str] + unverifiable = ... # type: bool + type = ... + origin_req_host= ... + unredirected_hdrs = ... + + def __init__(self, url: str, data: str, headers: Dict[str, str], + origin_req_host: str, unverifiable: bool) -> None: ... + def __getattr__(self, attr): ... + def get_method(self) -> str: ... + def add_data(self, data) -> None: ... + def has_data(self) -> bool: ... + def get_data(self) -> str: ... + def get_full_url(self) -> str: ... + def get_type(self): ... + def get_host(self) -> str: ... + def get_selector(self): ... + def set_proxy(self, host, type)-> None: ... + def has_proxy(self) -> bool: ... + def get_origin_req_host(self) -> str: ... + def is_unverifiable(self) -> bool: ... + def add_header(self, key: str, val: str) -> None: ... + def add_unredirected_header(self, key: str, val: str) -> None: ... + def has_header(self, header_name: str) -> bool: ... + def get_header(self, header_name: str, default: str) -> str: ... + def header_items(self): ... + +class OpenerDirector(object): ... + +def urlopen(url, data, timeout): ... +def install_opener(opener): ... +def build_opener(*handlers): ... + +class BaseHandler: + handler_order = ... # int + + def add_parent(self, parent) -> None: ... + def close(self) -> None: ... + def __lt__(self, other) -> bool: ... + +class HTTPErrorProcessor(BaseHandler): + def http_response(self, request, response): ... + +class HTTPDefaultErrorHandler(BaseHandler): + def http_error_default(self, req, fp, code, msg, hdrs): ... + +class HTTPRedirectHandler(BaseHandler): + max_repeats = ... # int + max_redirections = ... # int + def redirect_request(self, req, fp, code, msg, headers, newurl): ... + def http_error_302(self, req, fp, code, msg, headers): ... + http_error_301 = http_error_303 = http_error_307 = http_error_302 + inf_msg = ... # type: str + + +class ProxyHandler(BaseHandler): + def __init__(self, proxies): ... + def proxy_open(self, req, proxy, type): ... + +class HTTPPasswordMgr: + def __init__(self) -> None: ... + def add_password(self, realm, uri, user, passwd): ... + def find_user_password(self, realm, authuri): ... + def reduce_uri(self, uri, default_port: bool): ... + def is_suburi(self, base, test): ... + +class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): ... + +class AbstractBasicAuthHandler: + def __init__(self, password_mgr): ... + def reset_retry_count(self): ... + def http_error_auth_reqed(self, authreq, host, req, headers): ... + def retry_http_basic_auth(self, host, req, realm): ... + +class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + auth_header = ... # type: str + def http_error_401(self, req, fp, code, msg, headers): ... + +class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + auth_header = ... # type: str + def http_error_407(self, req, fp, code, msg, headers): ... + +class AbstractDigestAuthHandler: + def __init__(self, passwd): ... + def reset_retry_count(self): ... + def http_error_auth_reqed(self, auth_header, host, req, headers): ... + def retry_http_digest_auth(self, req, auth): ... + def get_cnonce(self, nonce): ... + def get_authorization(self, req, chal): ... + def get_algorithm_impls(self, algorithm): ... + def get_entity_digest(self, data, chal): ... + +class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + auth_header = ... # str + handler_order = ... # int + def http_error_401(self, req, fp, code, msg, headers): ... + +class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + auth_header = ... # str + handler_order = ... # int + def http_error_407(self, req, fp, code, msg, headers): ... + +class AbstractHTTPHandler(BaseHandler): + def __init__(self, debuglevel: int) -> None: ... + def do_request_(self, request): ... + def do_open(self, http_class, req): ... + +class HTTPHandler(AbstractHTTPHandler): + def http_open(self, req): ... + http_request = AbstractHTTPHandler.do_request_ + +class HTTPSHandler(AbstractHTTPHandler): + def https_open(self, req): ... + https_request = AbstractHTTPHandler.do_request_ + +class HTTPCookieProcessor(BaseHandler): + def __init__(self, cookiejar): ... + def http_request(self, request): ... + def http_response(self, request, response): ... + +class UnknownHandler(BaseHandler): + def unknown_open(self, req): ... + +class FileHandler(BaseHandler): + def file_open(self, req): ... + def get_names(self): ... + def open_local_file(self, req): ... + +class FTPHandler(BaseHandler): + def ftp_open(self, req): ... + def connect_ftp(self, user, passwd, host, port, dirs, timeout): ... + +class CacheFTPHandler(FTPHandler): + def __init__(self): ... + def setTimeout(self, t): ... + def setMaxConns(self, m): ... + def check_cache(self): ... + def clear_cache(self): ... diff --git a/third_party/2.7/six/moves/urllib/request.pyi b/third_party/2.7/six/moves/urllib/request.pyi index 77b2e590b..8c8a8b7df 100644 --- a/third_party/2.7/six/moves/urllib/request.pyi +++ b/third_party/2.7/six/moves/urllib/request.pyi @@ -3,34 +3,34 @@ # # Stubs for six.moves.urllib.request (Python 2.7) -## from urllib2 import urlopen as urlopen -## from urllib2 import install_opener as install_opener -## from urllib2 import build_opener as build_opener +from urllib2 import urlopen as urlopen +from urllib2 import install_opener as install_opener +from urllib2 import build_opener as build_opener from urllib import pathname2url as pathname2url from urllib import url2pathname as url2pathname from urllib import getproxies as getproxies -## from urllib2 import Request as Request -## from urllib2 import OpenerDirector as OpenerDirector -## from urllib2 import HTTPDefaultErrorHandler as HTTPDefaultErrorHandler -## from urllib2 import HTTPRedirectHandler as HTTPRedirectHandler -## from urllib2 import HTTPCookieProcessor as HTTPCookieProcessor -## from urllib2 import ProxyHandler as ProxyHandler -## from urllib2 import BaseHandler as BaseHandler -## from urllib2 import HTTPPasswordMgr as HTTPPasswordMgr -## from urllib2 import HTTPPasswordMgrWithDefaultRealm as HTTPPasswordMgrWithDefaultRealm -## from urllib2 import AbstractBasicAuthHandler as AbstractBasicAuthHandler -## from urllib2 import HTTPBasicAuthHandler as HTTPBasicAuthHandler -## from urllib2 import ProxyBasicAuthHandler as ProxyBasicAuthHandler -## from urllib2 import AbstractDigestAuthHandler as AbstractDigestAuthHandler -## from urllib2 import HTTPDigestAuthHandler as HTTPDigestAuthHandler -## from urllib2 import ProxyDigestAuthHandler as ProxyDigestAuthHandler -## from urllib2 import HTTPHandler as HTTPHandler -## from urllib2 import HTTPSHandler as HTTPSHandler -## from urllib2 import FileHandler as FileHandler -## from urllib2 import FTPHandler as FTPHandler -## from urllib2 import CacheFTPHandler as CacheFTPHandler -## from urllib2 import UnknownHandler as UnknownHandler -## from urllib2 import HTTPErrorProcessor as HTTPErrorProcessor +from urllib2 import Request as Request +from urllib2 import OpenerDirector as OpenerDirector +from urllib2 import HTTPDefaultErrorHandler as HTTPDefaultErrorHandler +from urllib2 import HTTPRedirectHandler as HTTPRedirectHandler +from urllib2 import HTTPCookieProcessor as HTTPCookieProcessor +from urllib2 import ProxyHandler as ProxyHandler +from urllib2 import BaseHandler as BaseHandler +from urllib2 import HTTPPasswordMgr as HTTPPasswordMgr +from urllib2 import HTTPPasswordMgrWithDefaultRealm as HTTPPasswordMgrWithDefaultRealm +from urllib2 import AbstractBasicAuthHandler as AbstractBasicAuthHandler +from urllib2 import HTTPBasicAuthHandler as HTTPBasicAuthHandler +from urllib2 import ProxyBasicAuthHandler as ProxyBasicAuthHandler +from urllib2 import AbstractDigestAuthHandler as AbstractDigestAuthHandler +from urllib2 import HTTPDigestAuthHandler as HTTPDigestAuthHandler +from urllib2 import ProxyDigestAuthHandler as ProxyDigestAuthHandler +from urllib2 import HTTPHandler as HTTPHandler +from urllib2 import HTTPSHandler as HTTPSHandler +from urllib2 import FileHandler as FileHandler +from urllib2 import FTPHandler as FTPHandler +from urllib2 import CacheFTPHandler as CacheFTPHandler +from urllib2 import UnknownHandler as UnknownHandler +from urllib2 import HTTPErrorProcessor as HTTPErrorProcessor from urllib import urlretrieve as urlretrieve from urllib import urlcleanup as urlcleanup from urllib import URLopener as URLopener From 9ad37b5701653910c97ad91e1c0602fa1826e659 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 27 Jan 2016 22:12:16 -0800 Subject: [PATCH 3/4] Add urllib.request.proxy_bypass stubs. --- stdlib/2.7/urllib.pyi | 1 + stdlib/3/urllib/request.pyi | 2 ++ third_party/2.7/six/moves/urllib/request.pyi | 3 +-- third_party/3/six/moves/urllib/request.pyi | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stdlib/2.7/urllib.pyi b/stdlib/2.7/urllib.pyi index 91d7be6e5..080f88a5f 100644 --- a/stdlib/2.7/urllib.pyi +++ b/stdlib/2.7/urllib.pyi @@ -129,6 +129,7 @@ def quote_plus(s: str, safe=...) -> str: ... def urlencode(query: Union[Sequence[Tuple[Any, Any]], Mapping[Any, Any]], doseq=...) -> str: ... def getproxies() -> Mapping[str, str]: ... # type: Any +def proxy_bypass(host): ... # Names in __all__ with no definition: # basejoin diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index fffc13fa5..3aeb20f46 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -11,3 +11,5 @@ class OpenerDirector(): ... # TODO args should be types that extend BaseHandler (types, not instances) def build_opener(*args: Any) -> OpenerDirector: ... def install_opener(opener: OpenerDirector) -> None: ... + +def proxy_bypass(host): ... diff --git a/third_party/2.7/six/moves/urllib/request.pyi b/third_party/2.7/six/moves/urllib/request.pyi index 8c8a8b7df..109cda88f 100644 --- a/third_party/2.7/six/moves/urllib/request.pyi +++ b/third_party/2.7/six/moves/urllib/request.pyi @@ -35,5 +35,4 @@ from urllib import urlretrieve as urlretrieve from urllib import urlcleanup as urlcleanup from urllib import URLopener as URLopener from urllib import FancyURLopener as FancyURLopener -# Don't have type stubs for proxy_bypass in stdlib urllib -# from urllib import proxy_bypass as proxy_bypass +from urllib import proxy_bypass as proxy_bypass diff --git a/third_party/3/six/moves/urllib/request.pyi b/third_party/3/six/moves/urllib/request.pyi index b15ced7ea..1a7537862 100644 --- a/third_party/3/six/moves/urllib/request.pyi +++ b/third_party/3/six/moves/urllib/request.pyi @@ -37,4 +37,4 @@ from urllib.request import build_opener as build_opener # from urllib.request import urlcleanup as urlcleanup # from urllib.request import URLopener as URLopener # from urllib.request import FancyURLopener as FancyURLopener -# from urllib.request import proxy_bypass as proxy_bypass +from urllib.request import proxy_bypass as proxy_bypass From f624349a46dc1682c3ca1025f11f5757de46c2a7 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 27 Jan 2016 22:13:54 -0800 Subject: [PATCH 4/4] Re-enable python 2 urllib.error stubs. --- third_party/2.7/six/moves/urllib/error.pyi | 4 ++-- third_party/2.7/six/moves/urllib_error.pyi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/third_party/2.7/six/moves/urllib/error.pyi b/third_party/2.7/six/moves/urllib/error.pyi index 7f860ae6d..05eda84a7 100644 --- a/third_party/2.7/six/moves/urllib/error.pyi +++ b/third_party/2.7/six/moves/urllib/error.pyi @@ -3,6 +3,6 @@ # # Stubs for six.moves.urllib.error (Python 2.7) -## from urllib2 import URLError as URLError -## from urllib2 import HTTPError as HTTPError +from urllib2 import URLError as URLError +from urllib2 import HTTPError as HTTPError from urllib import ContentTooShortError as ContentTooShortError diff --git a/third_party/2.7/six/moves/urllib_error.pyi b/third_party/2.7/six/moves/urllib_error.pyi index d915d3aa4..4872659b0 100644 --- a/third_party/2.7/six/moves/urllib_error.pyi +++ b/third_party/2.7/six/moves/urllib_error.pyi @@ -4,7 +4,7 @@ # Stubs for six.moves.urllib_error (Python 2.7) from six.moves.urllib.error import ( - ## URLError as URLError, - ## HTTPError as HTTPError, + URLError as URLError, + HTTPError as HTTPError, ContentTooShortError as ContentTooShortError, )