Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve http #248

Merged
merged 4 commits into from
Jun 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 189 additions & 77 deletions stdlib/3/http/client.pyi
Original file line number Diff line number Diff line change
@@ -1,101 +1,213 @@
# Stubs for http.client (Python 3.4)

from typing import Any, Dict
from typing import (
Any, Dict, IO, Iterable, List, Iterator, Mapping, Optional, Tuple, TypeVar,
Union,
overload,
)
import email.message
import io
import sys
import ssl
import types

_DataType = Union[bytes, IO[Any], Iterable[bytes], str]
_T = TypeVar('_T')

HTTP_PORT = ... # type: int
HTTPS_PORT = ... # type: int

CONTINUE = ... # type: int
SWITCHING_PROTOCOLS = ... # type: int
PROCESSING = ... # type: int

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

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

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
PRECONDITION_REQUIRED = ... # type: int
TOO_MANY_REQUESTS = ... # type: int
REQUEST_HEADER_FIELDS_TOO_LARGE = ... # type: int

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
NETWORK_AUTHENTICATION_REQUIRED = ... # type: int

responses = ... # type: Dict[int, str]

class HTTPMessage(email.message.Message):
def getallmatchingheaders(self, name): ...

class HTTPResponse(io.RawIOBase):
fp = ... # type: Any
debuglevel = ... # type: Any
headers = ... # 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=..., method=..., url=...) -> None: ...
code = ... # type: Any
def begin(self): ...
def close(self): ...
def flush(self): ...
def readable(self): ...
def isclosed(self): ...
def read(self, amt=...): ...
def readinto(self, b): ...
def fileno(self): ...
def getheader(self, name, default=...): ...
def getheaders(self): ...
def __iter__(self): ...
def info(self): ...
def geturl(self): ...
def getcode(self): ...
class HTTPMessage(email.message.Message): ...

# TODO uncomment when mypy handle conditionals
#if sys.version_info >= (3, 5):
# class HTTPResponse(io.BufferedIOBase):
# msg = ... # type: HTTPMessage
# version = ... # type: int
# debuglevel = ... # type: int
# closed = ... # type: bool
# status = ... # type: int
# reason = ... # type: str
# def read(self, amt: Optional[int] = ...) -> bytes: ...
# def readinto(self, b: bytearray) -> int: ...
# @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 __iter__(self) -> Iterator[bytes]: ...
# def __enter__(self) -> 'HTTPResponse': ...
# def __exit__(self, exc_type: Optional[type],
# exc_val: Optional[Exception],
# exc_tb: Optional[types.TracebackType]) -> bool: ...
#else:
# class HTTPResponse:
# msg = ... # type: HTTPMessage
# version = ... # type: int
# debuglevel = ... # type: int
# closed = ... # type: bool
# status = ... # type: int
# reason = ... # type: str
# def read(self, amt: Optional[int] = ...) -> bytes: ...
# if sys.version_info >= (3, 3):
# def readinto(self, b: bytearray) -> int: ...
# @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 __iter__(self) -> Iterator[bytes]: ...
# def __enter__(self) -> 'HTTPResponse': ...
# def __exit__(self, exc_type: Optional[type],
# exc_val: Optional[Exception],
# exc_tb: Optional[types.TracebackType]) -> bool: ...
class HTTPResponse(io.BufferedIOBase):
msg = ... # type: HTTPMessage
version = ... # type: int
debuglevel = ... # type: int
closed = ... # type: bool
status = ... # type: int
reason = ... # type: str
def read(self, amt: Optional[int] = ...) -> bytes: ...
def readinto(self, b: bytearray) -> int: ...
@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 __iter__(self) -> Iterator[bytes]: ...
def __enter__(self) -> 'HTTPResponse': ...
def __exit__(self, exc_type: Optional[type],
exc_val: Optional[Exception],
exc_tb: Optional[types.TracebackType]) -> bool: ...

class HTTPConnection:
response_class = ... # type: Any
default_port = ... # type: Any
auto_open = ... # type: Any
debuglevel = ... # type: Any
mss = ... # type: Any
timeout = ... # type: Any
source_address = ... # type: Any
sock = ... # type: Any
def __init__(self, host, port=..., timeout=..., source_address=...) -> None: ...
def set_tunnel(self, host, port=..., headers=...): ...
def set_debuglevel(self, level): ...
def connect(self): ...
def close(self): ...
def send(self, data): ...
def putrequest(self, method, url, skip_host=..., skip_accept_encoding=...): ...
def putheader(self, header, *values): ...
def endheaders(self, message_body=...): ...
def request(self, method, url, body=..., headers=...): ...
def getresponse(self): ...
if sys.version_info >= (3, 4):
def __init__(self, # type: ignore
host: str, port: Optional[int] = ...,
timeout: int = ...,
source_address: Optional[Tuple[str, int]] = ...) \
-> None: ...
else:
def __init__(self, # type: ignore
host: str, port: Optional[int] = ...,
strict: bool = ..., timeout: int = ...,
source_address: Optional[Tuple[str, int]] = ...) \
-> None: ...
def request(self, method: str, url: str,
body: Optional[_DataType] = ...,
headers: Mapping[str, str] = ...) -> 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, request: str, selector: str, skip_host: bool = ...,
skip_accept_encoding: bool = ...) -> None: ...
def putheader(self, header: str, *argument: str) -> None: ...
def endheaders(self, message_body: Optional[_DataType] = ...) -> None: ...
def send(self, data: _DataType) -> None: ...

class HTTPSConnection(HTTPConnection):
default_port = ... # type: Any
key_file = ... # type: Any
cert_file = ... # type: Any
def __init__(self, host, port=..., key_file=..., cert_file=..., timeout=...,
source_address=..., *, context=..., check_hostname=...): ...
sock = ... # type: Any
def connect(self): ...
if sys.version_info >= (3, 4):
def __init__(self, # type: ignore
host: str, port: Optional[int] = ...,
key_file: Optional[str] = ...,
cert_file: Optional[str] = ...,
timeout: int = ...,
source_address: Optional[Tuple[str, int]] = ...,
*, context: Optional[ssl.SSLContext] = ...,
check_hostname: Optional[bool] = ...) -> None: ...
else:
def __init__(self, # type: ignore
host: str, port: Optional[int] = ...,
key_file: Optional[str] = ...,
cert_file: Optional[str] = ...,
strict: bool = ..., timeout: int = ...,
source_address: Optional[Tuple[str, int]] = ...,
*, context: Optional[ssl.SSLContext] = ...,
check_hostname: Optional[bool] = ...) -> 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 UnknownProtocol(HTTPException): ...
class UnknownTransferEncoding(HTTPException): ...
class UnimplementedFileMode(HTTPException): ...

class IncompleteRead(HTTPException):
args = ... # type: Any
partial = ... # type: Any
expected = ... # type: Any
def __init__(self, partial, expected=...) -> None: ...
class IncompleteRead(HTTPException): ...

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: ...
class BadStatusLine(HTTPException): ...
class LineTooLong(HTTPException): ...

error = HTTPException
if sys.version_info >= (3, 5):
class RemoteDisconnected(ConnectionResetError, BadStatusLine): ...
Loading