Skip to content

Commit

Permalink
urllib2: Use addbase to model readable IO
Browse files Browse the repository at this point in the history
<https://docs.python.org/2/library/urllib2.html#urllib2.urlopen>
> urllib2.urlopen(url[,data[,timeout[,cafile[,capath[,cadefault[,context]]]]])
...
> This function returns a file-like object with three additional
> methods:
> - geturl()
> - info()
> - getcode()
...
> Note that None may be returned if no handler handles the request.

First suggested by srittau at
<#2688 (review)>
but then changed to just use `class addbase` inspired by commit
1442cc0 from Michael Brandt.
  • Loading branch information
pmhahn committed Feb 18, 2019
1 parent dcaecd2 commit 625cf79
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions stdlib/2/urllib2.pyi
Expand Up @@ -12,7 +12,7 @@ class URLError(IOError):
class HTTPError(URLError, addinfourl):
code = ... # type: int
headers = ... # type: Dict[str, str]
def __init__(self, url, code, msg, hdrs, fp) -> None: ...
def __init__(self, url, code, msg, hdrs, fp: addinfourl) -> None: ...

class Request(object):
host = ... # type: str
Expand Down Expand Up @@ -49,12 +49,12 @@ class OpenerDirector(object):
addheaders: List[Tuple[str, str]]

def add_handler(self, handler: BaseHandler) -> None: ...
def open(self, fullurl: 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: ...

Expand All @@ -70,16 +70,16 @@ class HTTPErrorProcessor(BaseHandler):
def http_response(self, request, response): ...

class HTTPDefaultErrorHandler(BaseHandler):
def http_error_default(self, req: Request, fp, code, msg, hdrs): ...
def http_error_default(self, req: Request, fp: addinfourl, code, msg, hdrs): ...

class HTTPRedirectHandler(BaseHandler):
max_repeats = ... # type: int
max_redirections = ... # type: int
def redirect_request(self, req: Request, fp, code, msg, headers, newurl): ...
def http_error_301(self, req: Request, fp, code, msg, headers): ...
def http_error_302(self, req: Request, fp, code, msg, headers): ...
def http_error_303(self, req: Request, fp, code, msg, headers): ...
def http_error_307(self, req: Request, fp, code, msg, headers): ...
def redirect_request(self, req: Request, fp: addinfourl, code, msg, headers, newurl): ...
def http_error_301(self, req: Request, fp: addinfourl, code, msg, headers): ...
def http_error_302(self, req: Request, fp: addinfourl, code, msg, headers): ...
def http_error_303(self, req: Request, fp: addinfourl, code, msg, headers): ...
def http_error_307(self, req: Request, fp: addinfourl, code, msg, headers): ...
inf_msg = ... # type: str


Expand All @@ -106,11 +106,11 @@ class AbstractBasicAuthHandler:

class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
auth_header = ... # type: str
def http_error_401(self, req: Request, fp, code, msg, headers): ...
def http_error_401(self, req: Request, fp: addinfourl, code, msg, headers): ...

class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
auth_header = ... # type: str
def http_error_407(self, req: Request, fp, code, msg, headers): ...
def http_error_407(self, req: Request, fp: addinfourl, code, msg, headers): ...

class AbstractDigestAuthHandler:
def __init__(self, passwd: Optional[HTTPPasswordMgr] = ...) -> None: ...
Expand All @@ -127,12 +127,12 @@ class AbstractDigestAuthHandler:
class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
auth_header = ... # type: str
handler_order = ... # type: int
def http_error_401(self, req: Request, fp, code, msg, headers): ...
def http_error_401(self, req: Request, fp: addinfourl, code, msg, headers): ...

class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
auth_header = ... # type: str
handler_order = ... # type: int
def http_error_407(self, req: Request, fp, code, msg, headers): ...
def http_error_407(self, req: Request, fp: addinfourl, code, msg, headers): ...

class AbstractHTTPHandler(BaseHandler): # undocumented
def __init__(self, debuglevel: int = ...) -> None: ...
Expand Down

0 comments on commit 625cf79

Please sign in to comment.