Files
typeshed/stdlib/2/httplib.pyi
Michael Brandt 1442cc02bf Add stubs for HTTP Handler classes in py2/urllib2 & py3/urllib.request (#2710)
* HTTP Handler class annotations for py2/urllib2 & py3/urllib.request

Add full annotations for the following classes:

* Python 2:

    * `urllib2.AbstractHTTPHandler`
    * `urllib2.HTTPHandler`
    * `urllib2.HTTPsHandler`

* Python 3:

    * `urllib.request.AbstractHTTPHandler`
    * `urllib.request.HTTPHandler`
    * `urllib.request.HTTPsHandler`

This information is largely undocumented, and was obtained by directly examining
the Python source code:

* Python 2 (v2.7.15) - https://github.com/python/cpython/blob/v2.7.15/Lib/urllib2.py#L1115-L1243
* Python 3 (v3.7.1) - https://github.com/python/cpython/blob/v3.7.1/Lib/urllib/request.py#L1224-L1364

`urllib2.AbstractHTTPHandler.do_open` takes as a parameter either
`HTTPConnection` or `HTTPSConnection`--one of the classes, not an instance of
either--and constructs an object using only a few of the parameters that either
constructor could use. `HTTPConnectionProtocol` in `stdlib/2/httplib.pyi`
follows a similar patten to `HTTPConnectionProtocol` added to
`stdlib/3/http/client.pyi` in pull request #2582 to describe the type of the
`http_class` that is passed to `do_open`.
2019-02-11 11:25:02 +01:00

206 lines
7.1 KiB
Python

# Stubs for httplib (Python 2)
#
# Generated by stubgen and manually massaged a bit.
# Needs lots more work!
from typing import Any, Dict, Optional, Protocol
import mimetools
import ssl
class HTTPMessage(mimetools.Message):
def addcontinue(self, key: str, more: str) -> None: ...
dict = ... # type: Dict[str, str]
def addheader(self, key: str, value: str) -> None: ...
unixfrom = ... # type: str
headers = ... # type: Any
status = ... # type: str
seekable = ... # type: bool
def readheaders(self) -> None: ...
class HTTPResponse:
fp = ... # type: Any
debuglevel = ... # type: Any
strict = ... # type: Any
msg = ... # type: Any
version = ... # type: Any
status = ... # type: Any
reason = ... # type: Any
chunked = ... # type: Any
chunk_left = ... # type: Any
length = ... # type: Any
will_close = ... # type: Any
def __init__(self, sock, debuglevel: int = ..., strict: int = ..., method: Optional[Any] = ...,
buffering: bool = ...) -> None: ...
def begin(self): ...
def close(self): ...
def isclosed(self): ...
def read(self, amt: Optional[Any] = ...): ...
def fileno(self): ...
def getheader(self, name, default: Optional[Any] = ...): ...
def getheaders(self): ...
# This is an API stub only for HTTPConnection and HTTPSConnection, as used in
# urllib2.AbstractHTTPHandler.do_open, which takes either the class
# HTTPConnection or the class HTTPSConnection, *not* an instance of either
# class. do_open does not use all of the parameters of HTTPConnection.__init__
# or HTTPSConnection.__init__, so HTTPConnectionProtocol only implements the
# parameters that do_open does use.
class HTTPConnectionProtocol(Protocol):
def __call__(self, host: str, timeout: int = ..., **http_con_args: Any) -> HTTPConnection: ...
class HTTPConnection:
response_class = ... # type: Any
default_port = ... # type: Any
auto_open = ... # type: Any
debuglevel = ... # type: Any
strict = ... # type: Any
timeout = ... # type: Any
source_address = ... # type: Any
sock = ... # type: Any
host: str = ...
port: int = ...
def __init__(self, host, port: Optional[Any] = ..., strict: Optional[Any] = ..., timeout=...,
source_address: Optional[Any] = ...) -> None: ...
def set_tunnel(self, host, port: Optional[Any] = ..., headers: Optional[Any] = ...): ...
def set_debuglevel(self, level): ...
def connect(self): ...
def close(self): ...
def send(self, data): ...
def putrequest(self, method, url, skip_host: int = ..., skip_accept_encoding: int = ...): ...
def putheader(self, header, *values): ...
def endheaders(self, message_body: Optional[Any] = ...): ...
def request(self, method, url, body: Optional[Any] = ..., headers=...): ...
def getresponse(self, buffering: bool = ...): ...
class HTTP:
debuglevel = ... # type: Any
def __init__(self, host: str = ..., port: Optional[Any] = ..., strict: Optional[Any] = ...) -> None: ...
def connect(self, host: Optional[Any] = ..., port: Optional[Any] = ...): ...
def getfile(self): ...
file = ... # type: Any
headers = ... # type: Any
def getreply(self, buffering: bool = ...): ...
def close(self): ...
class HTTPSConnection(HTTPConnection):
default_port = ... # type: Any
key_file = ... # type: Any
cert_file = ... # type: Any
def __init__(self, host, port: Optional[Any] = ..., key_file: Optional[Any] = ..., cert_file: Optional[Any] = ...,
strict: Optional[Any] = ..., timeout=..., source_address: Optional[Any] = ...,
context: Optional[Any] = ...) -> None: ...
sock = ... # type: Any
def connect(self): ...
class HTTPS(HTTP):
key_file = ... # type: Any
cert_file = ... # type: Any
def __init__(self, host: str = ..., port: Optional[Any] = ..., key_file: Optional[Any] = ..., cert_file: Optional[Any] = ..., strict: Optional[Any] = ..., context: Optional[Any] = ...) -> None: ...
class HTTPException(Exception): ...
class NotConnected(HTTPException): ...
class InvalidURL(HTTPException): ...
class UnknownProtocol(HTTPException):
args = ... # type: Any
version = ... # type: Any
def __init__(self, version) -> None: ...
class UnknownTransferEncoding(HTTPException): ...
class UnimplementedFileMode(HTTPException): ...
class IncompleteRead(HTTPException):
args = ... # type: Any
partial = ... # type: Any
expected = ... # type: Any
def __init__(self, partial, expected: Optional[Any] = ...) -> None: ...
class ImproperConnectionState(HTTPException): ...
class CannotSendRequest(ImproperConnectionState): ...
class CannotSendHeader(ImproperConnectionState): ...
class ResponseNotReady(ImproperConnectionState): ...
class BadStatusLine(HTTPException):
args = ... # type: Any
line = ... # type: Any
def __init__(self, line) -> None: ...
class LineTooLong(HTTPException):
def __init__(self, line_type) -> None: ...
error = ... # type: Any
class LineAndFileWrapper:
def __init__(self, line, file) -> None: ...
def __getattr__(self, attr): ...
def read(self, amt: Optional[Any] = ...): ...
def readline(self): ...
def readlines(self, size: Optional[Any] = ...): ...
# Constants
responses = ... # type: Dict[int, str]
HTTP_PORT = ... # type: int
HTTPS_PORT = ... # type: int
# status codes
# informational
CONTINUE = ... # type: int
SWITCHING_PROTOCOLS = ... # type: int
PROCESSING = ... # type: int
# successful
OK = ... # type: int
CREATED = ... # type: int
ACCEPTED = ... # type: int
NON_AUTHORITATIVE_INFORMATION = ... # type: int
NO_CONTENT = ... # type: int
RESET_CONTENT = ... # type: int
PARTIAL_CONTENT = ... # type: int
MULTI_STATUS = ... # type: int
IM_USED = ... # type: int
# redirection
MULTIPLE_CHOICES = ... # type: int
MOVED_PERMANENTLY = ... # type: int
FOUND = ... # type: int
SEE_OTHER = ... # type: int
NOT_MODIFIED = ... # type: int
USE_PROXY = ... # type: int
TEMPORARY_REDIRECT = ... # type: int
# client error
BAD_REQUEST = ... # type: int
UNAUTHORIZED = ... # type: int
PAYMENT_REQUIRED = ... # type: int
FORBIDDEN = ... # type: int
NOT_FOUND = ... # type: int
METHOD_NOT_ALLOWED = ... # type: int
NOT_ACCEPTABLE = ... # type: int
PROXY_AUTHENTICATION_REQUIRED = ... # type: int
REQUEST_TIMEOUT = ... # type: int
CONFLICT = ... # type: int
GONE = ... # type: int
LENGTH_REQUIRED = ... # type: int
PRECONDITION_FAILED = ... # type: int
REQUEST_ENTITY_TOO_LARGE = ... # type: int
REQUEST_URI_TOO_LONG = ... # type: int
UNSUPPORTED_MEDIA_TYPE = ... # type: int
REQUESTED_RANGE_NOT_SATISFIABLE = ... # type: int
EXPECTATION_FAILED = ... # type: int
UNPROCESSABLE_ENTITY = ... # type: int
LOCKED = ... # type: int
FAILED_DEPENDENCY = ... # type: int
UPGRADE_REQUIRED = ... # type: int
# server error
INTERNAL_SERVER_ERROR = ... # type: int
NOT_IMPLEMENTED = ... # type: int
BAD_GATEWAY = ... # type: int
SERVICE_UNAVAILABLE = ... # type: int
GATEWAY_TIMEOUT = ... # type: int
HTTP_VERSION_NOT_SUPPORTED = ... # type: int
INSUFFICIENT_STORAGE = ... # type: int
NOT_EXTENDED = ... # type: int