Re-organize directory structure (#4971)

See discussion in #2491

Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
This commit is contained in:
Ivan Levkivskyi
2021-01-27 12:00:39 +00:00
committed by GitHub
parent 869238e587
commit 16ae4c6120
1399 changed files with 601 additions and 97 deletions

74
stdlib/http/__init__.pyi Normal file
View File

@@ -0,0 +1,74 @@
import sys
from enum import IntEnum
from typing_extensions import Literal
class HTTPStatus(IntEnum):
@property
def phrase(self) -> str: ...
@property
def description(self) -> str: ...
CONTINUE: int
SWITCHING_PROTOCOLS: int
PROCESSING: int
OK: int
CREATED: int
ACCEPTED: int
NON_AUTHORITATIVE_INFORMATION: int
NO_CONTENT: int
RESET_CONTENT: int
PARTIAL_CONTENT: int
MULTI_STATUS: int
ALREADY_REPORTED: int
IM_USED: int
MULTIPLE_CHOICES: int
MOVED_PERMANENTLY: int
FOUND: int
SEE_OTHER: int
NOT_MODIFIED: int
USE_PROXY: int
TEMPORARY_REDIRECT: int
PERMANENT_REDIRECT: int
BAD_REQUEST: int
UNAUTHORIZED: int
PAYMENT_REQUIRED: int
FORBIDDEN: int
NOT_FOUND: int
METHOD_NOT_ALLOWED: int
NOT_ACCEPTABLE: int
PROXY_AUTHENTICATION_REQUIRED: int
REQUEST_TIMEOUT: int
CONFLICT: int
GONE: int
LENGTH_REQUIRED: int
PRECONDITION_FAILED: int
REQUEST_ENTITY_TOO_LARGE: int
REQUEST_URI_TOO_LONG: int
UNSUPPORTED_MEDIA_TYPE: int
REQUESTED_RANGE_NOT_SATISFIABLE: int
EXPECTATION_FAILED: int
UNPROCESSABLE_ENTITY: int
LOCKED: int
FAILED_DEPENDENCY: int
UPGRADE_REQUIRED: int
PRECONDITION_REQUIRED: int
TOO_MANY_REQUESTS: int
REQUEST_HEADER_FIELDS_TOO_LARGE: int
INTERNAL_SERVER_ERROR: int
NOT_IMPLEMENTED: int
BAD_GATEWAY: int
SERVICE_UNAVAILABLE: int
GATEWAY_TIMEOUT: int
HTTP_VERSION_NOT_SUPPORTED: int
VARIANT_ALSO_NEGOTIATES: int
INSUFFICIENT_STORAGE: int
LOOP_DETECTED: int
NOT_EXTENDED: int
NETWORK_AUTHENTICATION_REQUIRED: int
if sys.version_info >= (3, 7):
MISDIRECTED_REQUEST: int
if sys.version_info >= (3, 8):
UNAVAILABLE_FOR_LEGAL_REASONS: int
if sys.version_info >= (3, 9):
EARLY_HINTS: Literal[103]
IM_A_TEAPOT: Literal[418]
TOO_EARLY: Literal[425]

211
stdlib/http/client.pyi Normal file
View File

@@ -0,0 +1,211 @@
import email.message
import io
import ssl
import sys
import types
from socket import socket
from typing import (
IO,
Any,
BinaryIO,
Callable,
Dict,
Iterable,
Iterator,
List,
Mapping,
Optional,
Protocol,
Tuple,
Type,
TypeVar,
Union,
overload,
)
_DataType = Union[bytes, IO[Any], Iterable[bytes], str]
_T = TypeVar("_T")
HTTP_PORT: int
HTTPS_PORT: int
CONTINUE: int
SWITCHING_PROTOCOLS: int
PROCESSING: int
OK: int
CREATED: int
ACCEPTED: int
NON_AUTHORITATIVE_INFORMATION: int
NO_CONTENT: int
RESET_CONTENT: int
PARTIAL_CONTENT: int
MULTI_STATUS: int
IM_USED: int
MULTIPLE_CHOICES: int
MOVED_PERMANENTLY: int
FOUND: int
SEE_OTHER: int
NOT_MODIFIED: int
USE_PROXY: int
TEMPORARY_REDIRECT: int
BAD_REQUEST: int
UNAUTHORIZED: int
PAYMENT_REQUIRED: int
FORBIDDEN: int
NOT_FOUND: int
METHOD_NOT_ALLOWED: int
NOT_ACCEPTABLE: int
PROXY_AUTHENTICATION_REQUIRED: int
REQUEST_TIMEOUT: int
CONFLICT: int
GONE: int
LENGTH_REQUIRED: int
PRECONDITION_FAILED: int
REQUEST_ENTITY_TOO_LARGE: int
REQUEST_URI_TOO_LONG: int
UNSUPPORTED_MEDIA_TYPE: int
REQUESTED_RANGE_NOT_SATISFIABLE: int
EXPECTATION_FAILED: int
UNPROCESSABLE_ENTITY: int
LOCKED: int
FAILED_DEPENDENCY: int
UPGRADE_REQUIRED: int
PRECONDITION_REQUIRED: int
TOO_MANY_REQUESTS: int
REQUEST_HEADER_FIELDS_TOO_LARGE: int
INTERNAL_SERVER_ERROR: int
NOT_IMPLEMENTED: int
BAD_GATEWAY: int
SERVICE_UNAVAILABLE: int
GATEWAY_TIMEOUT: int
HTTP_VERSION_NOT_SUPPORTED: int
INSUFFICIENT_STORAGE: int
NOT_EXTENDED: int
NETWORK_AUTHENTICATION_REQUIRED: int
responses: Dict[int, str]
class HTTPMessage(email.message.Message): ...
def parse_headers(fp: io.BufferedIOBase, _class: Callable[[], email.message.Message] = ...) -> HTTPMessage: ...
class HTTPResponse(io.BufferedIOBase, BinaryIO):
msg: HTTPMessage
headers: HTTPMessage
version: int
debuglevel: int
closed: bool
status: int
reason: str
def __init__(self, sock: socket, debuglevel: int = ..., method: Optional[str] = ..., url: Optional[str] = ...) -> None: ...
def read(self, amt: Optional[int] = ...) -> bytes: ...
@overload
def getheader(self, name: str) -> Optional[str]: ...
@overload
def getheader(self, name: str, default: _T) -> Union[str, _T]: ...
def getheaders(self) -> List[Tuple[str, str]]: ...
def fileno(self) -> int: ...
def isclosed(self) -> bool: ...
def __iter__(self) -> Iterator[bytes]: ...
def __enter__(self) -> HTTPResponse: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[types.TracebackType]
) -> Optional[bool]: ...
def info(self) -> email.message.Message: ...
def geturl(self) -> str: ...
def getcode(self) -> int: ...
def begin(self) -> None: ...
# This is an API stub only for the class below, not a class itself.
# urllib.request uses it for a parameter.
class _HTTPConnectionProtocol(Protocol):
if sys.version_info >= (3, 7):
def __call__(
self,
host: str,
port: Optional[int] = ...,
timeout: float = ...,
source_address: Optional[Tuple[str, int]] = ...,
blocksize: int = ...,
) -> HTTPConnection: ...
else:
def __call__(
self, host: str, port: Optional[int] = ..., timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...
) -> HTTPConnection: ...
class HTTPConnection:
timeout: Optional[float]
host: str
port: int
sock: Any
if sys.version_info >= (3, 7):
def __init__(
self,
host: str,
port: Optional[int] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
blocksize: int = ...,
) -> None: ...
else:
def __init__(
self,
host: str,
port: Optional[int] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
) -> None: ...
def request(
self,
method: str,
url: str,
body: Optional[_DataType] = ...,
headers: Mapping[str, str] = ...,
*,
encode_chunked: bool = ...,
) -> None: ...
def getresponse(self) -> HTTPResponse: ...
def set_debuglevel(self, level: int) -> None: ...
def set_tunnel(self, host: str, port: Optional[int] = ..., headers: Optional[Mapping[str, str]] = ...) -> None: ...
def connect(self) -> None: ...
def close(self) -> None: ...
def putrequest(self, method: str, url: str, skip_host: bool = ..., skip_accept_encoding: bool = ...) -> None: ...
def putheader(self, header: str, *argument: str) -> None: ...
def endheaders(self, message_body: Optional[_DataType] = ..., *, encode_chunked: bool = ...) -> None: ...
def send(self, data: _DataType) -> None: ...
class HTTPSConnection(HTTPConnection):
def __init__(
self,
host: str,
port: Optional[int] = ...,
key_file: Optional[str] = ...,
cert_file: Optional[str] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
*,
context: Optional[ssl.SSLContext] = ...,
check_hostname: Optional[bool] = ...,
) -> None: ...
class HTTPException(Exception): ...
error = HTTPException
class NotConnected(HTTPException): ...
class InvalidURL(HTTPException): ...
class UnknownProtocol(HTTPException): ...
class UnknownTransferEncoding(HTTPException): ...
class UnimplementedFileMode(HTTPException): ...
class IncompleteRead(HTTPException): ...
class ImproperConnectionState(HTTPException): ...
class CannotSendRequest(ImproperConnectionState): ...
class CannotSendHeader(ImproperConnectionState): ...
class ResponseNotReady(ImproperConnectionState): ...
class BadStatusLine(HTTPException): ...
class LineTooLong(HTTPException): ...
class RemoteDisconnected(ConnectionResetError, BadStatusLine): ...

129
stdlib/http/cookiejar.pyi Normal file
View File

@@ -0,0 +1,129 @@
import sys
from http.client import HTTPResponse
from os import PathLike
from typing import Dict, Iterable, Iterator, Optional, Sequence, Tuple, TypeVar, Union, overload
from urllib.request import Request
_T = TypeVar("_T")
class LoadError(OSError): ...
class CookieJar(Iterable[Cookie]):
def __init__(self, policy: Optional[CookiePolicy] = ...) -> None: ...
def add_cookie_header(self, request: Request) -> None: ...
def extract_cookies(self, response: HTTPResponse, request: Request) -> None: ...
def set_policy(self, policy: CookiePolicy) -> None: ...
def make_cookies(self, response: HTTPResponse, request: Request) -> Sequence[Cookie]: ...
def set_cookie(self, cookie: Cookie) -> None: ...
def set_cookie_if_ok(self, cookie: Cookie, request: Request) -> None: ...
def clear(self, domain: str = ..., path: str = ..., name: str = ...) -> None: ...
def clear_session_cookies(self) -> None: ...
def __iter__(self) -> Iterator[Cookie]: ...
def __len__(self) -> int: ...
class FileCookieJar(CookieJar):
filename: str
delayload: bool
if sys.version_info >= (3, 8):
def __init__(
self, filename: Union[str, PathLike[str]] = ..., delayload: bool = ..., policy: Optional[CookiePolicy] = ...
) -> None: ...
else:
def __init__(self, filename: str = ..., delayload: bool = ..., policy: Optional[CookiePolicy] = ...) -> None: ...
def save(self, filename: Optional[str] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def load(self, filename: Optional[str] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def revert(self, filename: Optional[str] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
class MozillaCookieJar(FileCookieJar): ...
class LWPCookieJar(FileCookieJar):
def as_lwp_str(self, ignore_discard: bool = ..., ignore_expires: bool = ...) -> str: ... # undocumented
class CookiePolicy:
netscape: bool
rfc2965: bool
hide_cookie2: bool
def set_ok(self, cookie: Cookie, request: Request) -> bool: ...
def return_ok(self, cookie: Cookie, request: Request) -> bool: ...
def domain_return_ok(self, domain: str, request: Request) -> bool: ...
def path_return_ok(self, path: str, request: Request) -> bool: ...
class DefaultCookiePolicy(CookiePolicy):
rfc2109_as_netscape: bool
strict_domain: bool
strict_rfc2965_unverifiable: bool
strict_ns_unverifiable: bool
strict_ns_domain: int
strict_ns_set_initial_dollar: bool
strict_ns_set_path: bool
DomainStrictNoDots: int
DomainStrictNonDomain: int
DomainRFC2965Match: int
DomainLiberal: int
DomainStrict: int
def __init__(
self,
blocked_domains: Optional[Sequence[str]] = ...,
allowed_domains: Optional[Sequence[str]] = ...,
netscape: bool = ...,
rfc2965: bool = ...,
rfc2109_as_netscape: Optional[bool] = ...,
hide_cookie2: bool = ...,
strict_domain: bool = ...,
strict_rfc2965_unverifiable: bool = ...,
strict_ns_unverifiable: bool = ...,
strict_ns_domain: int = ...,
strict_ns_set_initial_dollar: bool = ...,
strict_ns_set_path: bool = ...,
) -> None: ...
def blocked_domains(self) -> Tuple[str, ...]: ...
def set_blocked_domains(self, blocked_domains: Sequence[str]) -> None: ...
def is_blocked(self, domain: str) -> bool: ...
def allowed_domains(self) -> Optional[Tuple[str, ...]]: ...
def set_allowed_domains(self, allowed_domains: Optional[Sequence[str]]) -> None: ...
def is_not_allowed(self, domain: str) -> bool: ...
class Cookie:
version: Optional[int]
name: str
value: Optional[str]
port: Optional[str]
path: str
path_specified: bool
secure: bool
expires: Optional[int]
discard: bool
comment: Optional[str]
comment_url: Optional[str]
rfc2109: bool
port_specified: bool
domain: str # undocumented
domain_specified: bool
domain_initial_dot: bool
def __init__(
self,
version: Optional[int],
name: str,
value: Optional[str], # undocumented
port: Optional[str],
port_specified: bool,
domain: str,
domain_specified: bool,
domain_initial_dot: bool,
path: str,
path_specified: bool,
secure: bool,
expires: Optional[int],
discard: bool,
comment: Optional[str],
comment_url: Optional[str],
rest: Dict[str, str],
rfc2109: bool = ...,
) -> None: ...
def has_nonstandard_attr(self, name: str) -> bool: ...
@overload
def get_nonstandard_attr(self, name: str) -> Optional[str]: ...
@overload
def get_nonstandard_attr(self, name: str, default: _T) -> Union[str, _T]: ...
def set_nonstandard_attr(self, name: str, value: str) -> None: ...
def is_expired(self, now: int = ...) -> bool: ...

39
stdlib/http/cookies.pyi Normal file
View File

@@ -0,0 +1,39 @@
import sys
from typing import Any, Dict, Generic, List, Mapping, Optional, TypeVar, Union, overload
_DataType = Union[str, Mapping[str, Union[str, Morsel[Any]]]]
_T = TypeVar("_T")
@overload
def _quote(str: None) -> None: ...
@overload
def _quote(str: str) -> str: ...
@overload
def _unquote(str: None) -> None: ...
@overload
def _unquote(str: str) -> str: ...
class CookieError(Exception): ...
class Morsel(Dict[str, Any], Generic[_T]):
value: str
coded_value: _T
key: str
if sys.version_info >= (3, 7):
def set(self, key: str, val: str, coded_val: _T) -> None: ...
else:
def set(self, key: str, val: str, coded_val: _T, LegalChars: str = ...) -> None: ...
def isReservedKey(self, K: str) -> bool: ...
def output(self, attrs: Optional[List[str]] = ..., header: str = ...) -> str: ...
def js_output(self, attrs: Optional[List[str]] = ...) -> str: ...
def OutputString(self, attrs: Optional[List[str]] = ...) -> str: ...
class BaseCookie(Dict[str, Morsel[_T]], Generic[_T]):
def __init__(self, input: Optional[_DataType] = ...) -> None: ...
def value_decode(self, val: str) -> _T: ...
def value_encode(self, val: _T) -> str: ...
def output(self, attrs: Optional[List[str]] = ..., header: str = ..., sep: str = ...) -> str: ...
def js_output(self, attrs: Optional[List[str]] = ...) -> str: ...
def load(self, rawdata: _DataType) -> None: ...
def __setitem__(self, key: str, value: Union[str, Morsel[_T]]) -> None: ...
class SimpleCookie(BaseCookie[_T], Generic[_T]): ...

72
stdlib/http/server.pyi Normal file
View File

@@ -0,0 +1,72 @@
import email.message
import socketserver
import sys
from typing import Any, Callable, ClassVar, Dict, List, Mapping, Optional, Sequence, Tuple, Union
if sys.version_info >= (3, 7):
from builtins import _PathLike
class HTTPServer(socketserver.TCPServer):
server_name: str
server_port: int
def __init__(self, server_address: Tuple[str, int], RequestHandlerClass: Callable[..., BaseHTTPRequestHandler]) -> None: ...
if sys.version_info >= (3, 7):
class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
daemon_threads: bool # undocumented
class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
client_address: Tuple[str, int]
server: socketserver.BaseServer
close_connection: bool
requestline: str
command: str
path: str
request_version: str
headers: email.message.Message
server_version: str
sys_version: str
error_message_format: str
error_content_type: str
protocol_version: str
MessageClass: type
responses: Mapping[int, Tuple[str, str]]
weekdayname: ClassVar[Sequence[str]] = ... # Undocumented
monthname: ClassVar[Sequence[Optional[str]]] = ... # Undocumented
def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ...
def handle(self) -> None: ...
def handle_one_request(self) -> None: ...
def handle_expect_100(self) -> bool: ...
def send_error(self, code: int, message: Optional[str] = ..., explain: Optional[str] = ...) -> None: ...
def send_response(self, code: int, message: Optional[str] = ...) -> None: ...
def send_header(self, keyword: str, value: str) -> None: ...
def send_response_only(self, code: int, message: Optional[str] = ...) -> None: ...
def end_headers(self) -> None: ...
def flush_headers(self) -> None: ...
def log_request(self, code: Union[int, str] = ..., size: Union[int, str] = ...) -> None: ...
def log_error(self, format: str, *args: Any) -> None: ...
def log_message(self, format: str, *args: Any) -> None: ...
def version_string(self) -> str: ...
def date_time_string(self, timestamp: Optional[int] = ...) -> str: ...
def log_date_time_string(self) -> str: ...
def address_string(self) -> str: ...
def parse_request(self) -> bool: ... # Undocumented
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
extensions_map: Dict[str, str]
if sys.version_info >= (3, 7):
def __init__(
self,
request: bytes,
client_address: Tuple[str, int],
server: socketserver.BaseServer,
directory: Optional[Union[str, _PathLike[str]]] = ...,
) -> None: ...
else:
def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ...
def do_GET(self) -> None: ...
def do_HEAD(self) -> None: ...
class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
cgi_directories: List[str]
def do_POST(self) -> None: ...