Skip to content
Permalink
Browse files

urllib2: handle headers as Mapping

Internally mimetools.Message is used, which is a dict-like object, but
> All header matching is done independent of upper or lower case

<https://docs.python.org/2/library/urllib2.html#urllib2.BaseHandler.http_error_default>
> fp will be a file-like object with the HTTP error body
> code will be the three-digit code of the error
> msg will be the user-visible explanation of the code
> hdrs will be a mapping object with the headers of the error
  • Loading branch information...
pmhahn committed Dec 12, 2018
1 parent 625cf79 commit 2b4fcd657613a089437df21eaf00ff248a010a32
Showing with 13 additions and 13 deletions.
  1. +13 −13 stdlib/2/urllib2.pyi
@@ -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: addinfourl) -> 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
@@ -70,16 +70,16 @@ class HTTPErrorProcessor(BaseHandler):
def http_response(self, request, response): ...

class HTTPDefaultErrorHandler(BaseHandler):
def http_error_default(self, req: Request, fp: addinfourl, 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: 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): ...
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


@@ -101,16 +101,16 @@ class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): ...
class AbstractBasicAuthHandler:
def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ...
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): ...
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: Request, fp: addinfourl, 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: Request, fp: addinfourl, 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: ...
@@ -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: addinfourl, 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: Request, fp: addinfourl, 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: ...

0 comments on commit 2b4fcd6

Please sign in to comment.
You can’t perform that action at this time.