6 from _typeshed import Self, WriteableBuffer
7 from socket import socket
8 from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, Mapping, Protocol, Type, TypeVar, Union, overload
10 _DataType = Union[bytes, IO[Any], Iterable[bytes], str]
17 SWITCHING_PROTOCOLS: int
23 NON_AUTHORITATIVE_INFORMATION: int
31 MOVED_PERMANENTLY: int
36 TEMPORARY_REDIRECT: int
43 METHOD_NOT_ALLOWED: int
45 PROXY_AUTHENTICATION_REQUIRED: int
50 PRECONDITION_FAILED: int
51 REQUEST_ENTITY_TOO_LARGE: int
52 REQUEST_URI_TOO_LONG: int
53 UNSUPPORTED_MEDIA_TYPE: int
54 REQUESTED_RANGE_NOT_SATISFIABLE: int
55 EXPECTATION_FAILED: int
56 UNPROCESSABLE_ENTITY: int
58 FAILED_DEPENDENCY: int
60 PRECONDITION_REQUIRED: int
61 TOO_MANY_REQUESTS: int
62 REQUEST_HEADER_FIELDS_TOO_LARGE: int
64 INTERNAL_SERVER_ERROR: int
67 SERVICE_UNAVAILABLE: int
69 HTTP_VERSION_NOT_SUPPORTED: int
70 INSUFFICIENT_STORAGE: int
72 NETWORK_AUTHENTICATION_REQUIRED: int
74 responses: dict[int, str]
76 class HTTPMessage(email.message.Message):
77 def getallmatchingheaders(self, name: str) -> list[str]: ... # undocumented
79 def parse_headers(fp: io.BufferedIOBase, _class: Callable[[], email.message.Message] = ...) -> HTTPMessage: ...
81 class HTTPResponse(io.BufferedIOBase, BinaryIO):
91 chunk_left: int | None
94 def __init__(self, sock: socket, debuglevel: int = ..., method: str | None = ..., url: str | None = ...) -> None: ...
95 def peek(self, n: int = ...) -> bytes: ...
96 def read(self, amt: int | None = ...) -> bytes: ...
97 def read1(self, n: int = ...) -> bytes: ...
98 def readinto(self, b: WriteableBuffer) -> int: ...
99 def readline(self, limit: int = ...) -> bytes: ... # type: ignore
101 def getheader(self, name: str) -> str | None: ...
103 def getheader(self, name: str, default: _T) -> str | _T: ...
104 def getheaders(self) -> list[tuple[str, str]]: ...
105 def fileno(self) -> int: ...
106 def isclosed(self) -> bool: ...
107 def __iter__(self) -> Iterator[bytes]: ...
108 def __enter__(self: Self) -> Self: ...
110 self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
111 ) -> bool | None: ...
112 def info(self) -> email.message.Message: ...
113 def geturl(self) -> str: ...
114 def getcode(self) -> int: ...
115 def begin(self) -> None: ...
117 # This is an API stub only for the class below, not a class itself.
118 # urllib.request uses it for a parameter.
119 class _HTTPConnectionProtocol(Protocol):
120 if sys.version_info >= (3, 7):
124 port: int | None = ...,
125 timeout: float = ...,
126 source_address: tuple[str, int] | None = ...,
127 blocksize: int = ...,
128 ) -> HTTPConnection: ...
131 self, host: str, port: int | None = ..., timeout: float = ..., source_address: tuple[str, int] | None = ...
132 ) -> HTTPConnection: ...
134 class HTTPConnection:
135 auto_open: int # undocumented
137 default_port: int # undocumented
138 response_class: Type[HTTPResponse] # undocumented
139 timeout: float | None
143 if sys.version_info >= (3, 7):
147 port: int | None = ...,
148 timeout: float | None = ...,
149 source_address: tuple[str, int] | None = ...,
150 blocksize: int = ...,
154 self, host: str, port: int | None = ..., timeout: float | None = ..., source_address: tuple[str, int] | None = ...
157 self, method: str, url: str, body: _DataType | None = ..., headers: Mapping[str, str] = ..., *, encode_chunked: bool = ...
159 def getresponse(self) -> HTTPResponse: ...
160 def set_debuglevel(self, level: int) -> None: ...
161 def set_tunnel(self, host: str, port: int | None = ..., headers: Mapping[str, str] | None = ...) -> None: ...
162 def connect(self) -> None: ...
163 def close(self) -> None: ...
164 def putrequest(self, method: str, url: str, skip_host: bool = ..., skip_accept_encoding: bool = ...) -> None: ...
165 def putheader(self, header: str, *argument: str) -> None: ...
166 def endheaders(self, message_body: _DataType | None = ..., *, encode_chunked: bool = ...) -> None: ...
167 def send(self, data: _DataType) -> None: ...
169 class HTTPSConnection(HTTPConnection):
170 if sys.version_info >= (3, 7):
174 port: int | None = ...,
175 key_file: str | None = ...,
176 cert_file: str | None = ...,
177 timeout: float | None = ...,
178 source_address: tuple[str, int] | None = ...,
180 context: ssl.SSLContext | None = ...,
181 check_hostname: bool | None = ...,
182 blocksize: int = ...,
188 port: int | None = ...,
189 key_file: str | None = ...,
190 cert_file: str | None = ...,
191 timeout: float | None = ...,
192 source_address: tuple[str, int] | None = ...,
194 context: ssl.SSLContext | None = ...,
195 check_hostname: bool | None = ...,
198 class HTTPException(Exception): ...
200 error = HTTPException
202 class NotConnected(HTTPException): ...
203 class InvalidURL(HTTPException): ...
205 class UnknownProtocol(HTTPException):
206 def __init__(self, version: str) -> None: ...
208 class UnknownTransferEncoding(HTTPException): ...
209 class UnimplementedFileMode(HTTPException): ...
211 class IncompleteRead(HTTPException):
212 def __init__(self, partial: bytes, expected: int | None = ...) -> None: ...
216 class ImproperConnectionState(HTTPException): ...
217 class CannotSendRequest(ImproperConnectionState): ...
218 class CannotSendHeader(ImproperConnectionState): ...
219 class ResponseNotReady(ImproperConnectionState): ...
221 class BadStatusLine(HTTPException):
222 def __init__(self, line: str) -> None: ...
224 class LineTooLong(HTTPException):
225 def __init__(self, line_type: str) -> None: ...
227 class RemoteDisconnected(ConnectionResetError, BadStatusLine): ...