alexapy.aiohttp.http

Functions

alexapy.aiohttp.http.ws_ext_gen(compress: int = 15, isserver: bool = False, server_notakeover: bool = False) str
alexapy.aiohttp.http.ws_ext_parse(extstr: Optional[str], isserver: bool = False) Tuple[int, bool]

Classes

class alexapy.aiohttp.http.StreamWriter(protocol: alexapy.aiohttp.base_protocol.BaseProtocol, loop: asyncio.events.AbstractEventLoop, on_chunk_sent: Optional[Callable[[bytes], Awaitable[None]]] = None, on_headers_sent: Optional[Callable[[multidict._multidict.CIMultiDict], Awaitable[None]]] = None)

Inheritance

Inheritance diagram of StreamWriter

async drain() None

Flush the write buffer.

The intended use is to write

await w.write(data) await w.drain()

enable_chunking() None

Enable HTTP chunked mode

enable_compression(encoding: str = 'deflate', strategy: int = 0) None

Enable HTTP body compression

async write(chunk: bytes, *, drain: bool = True, LIMIT: int = 65536) None

Writes chunk of data to a stream.

write_eof() indicates end of stream. writer can’t be used after write_eof() method being called. write() return drain future.

async write_eof(chunk: bytes = b'') None

Write last chunk.

async write_headers(status_line: str, headers: multidict._multidict.CIMultiDict) None

Write request/response status and headers.

class alexapy.aiohttp.http.HttpVersion(major, minor)

Inheritance

Inheritance diagram of HttpVersion

property major

Alias for field number 0

property minor

Alias for field number 1

class alexapy.aiohttp.http.HeadersParser(max_line_size: int = 8190, max_headers: int = 32768, max_field_size: int = 8190)

Inheritance

Inheritance diagram of HeadersParser

class alexapy.aiohttp.http.HttpParser(protocol: Optional[alexapy.aiohttp.base_protocol.BaseProtocol] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, limit: int = 65536, max_line_size: int = 8190, max_headers: int = 32768, max_field_size: int = 8190, timer: Optional[alexapy.aiohttp.helpers.BaseTimerContext] = None, code: Optional[int] = None, method: Optional[str] = None, readall: bool = False, payload_exception: Optional[Type[BaseException]] = None, response_with_body: bool = True, read_until_eof: bool = False, auto_decompress: bool = True)

Inheritance

Inheritance diagram of HttpParser

parse_headers(lines: List[bytes]) Tuple[multidict._multidict.CIMultiDictProxy, Tuple[Tuple[bytes, bytes], ...], Optional[bool], Optional[str], bool, bool]

Parses RFC 5322 headers from a stream.

Line continuations are supported. Returns list of header name and value pairs. Header name is in upper case.

set_upgraded(val: bool) None

Set connection upgraded (to websocket) mode.

Parameters

val (bool) – new state.

class alexapy.aiohttp.http.HttpRequestParser(protocol: Optional[alexapy.aiohttp.base_protocol.BaseProtocol] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, limit: int = 65536, max_line_size: int = 8190, max_headers: int = 32768, max_field_size: int = 8190, timer: Optional[alexapy.aiohttp.helpers.BaseTimerContext] = None, code: Optional[int] = None, method: Optional[str] = None, readall: bool = False, payload_exception: Optional[Type[BaseException]] = None, response_with_body: bool = True, read_until_eof: bool = False, auto_decompress: bool = True)

Read request status line.

Exception .http_exceptions.BadStatusLine could be raised in case of any errors in status line. Returns RawRequestMessage.

Inheritance

Inheritance diagram of HttpRequestParser

class alexapy.aiohttp.http.HttpResponseParser(protocol: Optional[alexapy.aiohttp.base_protocol.BaseProtocol] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, limit: int = 65536, max_line_size: int = 8190, max_headers: int = 32768, max_field_size: int = 8190, timer: Optional[alexapy.aiohttp.helpers.BaseTimerContext] = None, code: Optional[int] = None, method: Optional[str] = None, readall: bool = False, payload_exception: Optional[Type[BaseException]] = None, response_with_body: bool = True, read_until_eof: bool = False, auto_decompress: bool = True)

Read response status line and headers.

BadStatusLine could be raised in case of any errors in status line. Returns RawResponseMessage.

Inheritance

Inheritance diagram of HttpResponseParser

class alexapy.aiohttp.http.RawRequestMessage(method, path, version, headers, raw_headers, should_close, compression, upgrade, chunked, url)

Inheritance

Inheritance diagram of RawRequestMessage

property chunked

Alias for field number 8

property compression

Alias for field number 6

property headers

Alias for field number 3

property method

Alias for field number 0

property path

Alias for field number 1

property raw_headers

Alias for field number 4

property should_close

Alias for field number 5

property upgrade

Alias for field number 7

property url

Alias for field number 9

property version

Alias for field number 2

class alexapy.aiohttp.http.RawResponseMessage(version, code, reason, headers, raw_headers, should_close, compression, upgrade, chunked)

Inheritance

Inheritance diagram of RawResponseMessage

property chunked

Alias for field number 8

property code

Alias for field number 1

property compression

Alias for field number 6

property headers

Alias for field number 3

property raw_headers

Alias for field number 4

property reason

Alias for field number 2

property should_close

Alias for field number 5

property upgrade

Alias for field number 7

property version

Alias for field number 0

class alexapy.aiohttp.http.WebSocketReader(queue: alexapy.aiohttp.streams.DataQueue[alexapy.aiohttp.http_websocket.WSMessage], max_msg_size: int, compress: bool = True)

Inheritance

Inheritance diagram of WebSocketReader

parse_frame(buf: bytes) List[Tuple[bool, Optional[int], bytearray, Optional[bool]]]

Return the next frame from the socket.

class alexapy.aiohttp.http.WebSocketWriter(protocol: alexapy.aiohttp.base_protocol.BaseProtocol, transport: asyncio.transports.Transport, *, use_mask: bool = False, limit: int = 65536, random: typing.Any = <random.Random object>, compress: int = 0, notakeover: bool = False)

Inheritance

Inheritance diagram of WebSocketWriter

async close(code: int = 1000, message: bytes = b'') None

Close the websocket, sending the specified code and message.

async ping(message: bytes = b'') None

Send ping message.

async pong(message: bytes = b'') None

Send pong message.

async send(message: Union[str, bytes], binary: bool = False, compress: Optional[int] = None) None

Send a frame over the websocket with message as its payload.

class alexapy.aiohttp.http.WSMessage(type, data, extra)

Inheritance

Inheritance diagram of WSMessage

json(*, loads: typing.Callable[[typing.Any], typing.Any] = <function loads>) Any

Return parsed JSON data.

New in version 0.22.

class alexapy.aiohttp.http.WSMsgType(value)

An enumeration.

Inheritance

Inheritance diagram of WSMsgType

class alexapy.aiohttp.http.WSCloseCode(value)

An enumeration.

Inheritance

Inheritance diagram of WSCloseCode

Exceptions

exception alexapy.aiohttp.http.HttpProcessingError(*, code: Optional[int] = None, message: str = '', headers: Optional[multidict._multidict.CIMultiDict] = None)

HTTP error.

Shortcut for raising HTTP errors with custom code, message and headers.

code: HTTP Error code. message: (optional) Error message. headers: (optional) Headers to be sent in response, a list of pairs

Inheritance

Inheritance diagram of HttpProcessingError

exception alexapy.aiohttp.http.WebSocketError(code: int, message: str)

WebSocket protocol parser error.

Inheritance

Inheritance diagram of WebSocketError

Variables

alexapy.aiohttp.http.RESPONSES

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

{<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request received, please continue'),
 <HTTPStatus.SWITCHING_PROTOCOLS: 101>: ('Switching Protocols',
                                         'Switching to new protocol; obey '
                                         'Upgrade header'),
 <HTTPStatus.PROCESSING: 102>: ('Processing', ''),
 <HTTPStatus.OK: 200>: ('OK', 'Request fulfilled, document follows'),
 <HTTPStatus.CREATED: 201>: ('Created', 'Document created, URL follows'),
 <HTTPStatus.ACCEPTED: 202>: ('Accepted',
                              'Request accepted, processing continues '
                              'off-line'),
 <HTTPStatus.NON_AUTHORITATIVE_INFORMATION: 203>: ('Non-Authoritative '
                                                   'Information',
                                                   'Request fulfilled from '
                                                   'cache'),
 <HTTPStatus.NO_CONTENT: 204>: ('No Content',
                                'Request fulfilled, nothing follows'),
 <HTTPStatus.RESET_CONTENT: 205>: ('Reset Content',
                                   'Clear input form for further input'),
 <HTTPStatus.PARTIAL_CONTENT: 206>: ('Partial Content',
                                     'Partial content follows'),
 <HTTPStatus.MULTI_STATUS: 207>: ('Multi-Status', ''),
 <HTTPStatus.ALREADY_REPORTED: 208>: ('Already Reported', ''),
 <HTTPStatus.IM_USED: 226>: ('IM Used', ''),
 <HTTPStatus.MULTIPLE_CHOICES: 300>: ('Multiple Choices',
                                      'Object has several resources -- see URI '
                                      'list'),
 <HTTPStatus.MOVED_PERMANENTLY: 301>: ('Moved Permanently',
                                       'Object moved permanently -- see URI '
                                       'list'),
 <HTTPStatus.FOUND: 302>: ('Found', 'Object moved temporarily -- see URI list'),
 <HTTPStatus.SEE_OTHER: 303>: ('See Other',
                               'Object moved -- see Method and URL list'),
 <HTTPStatus.NOT_MODIFIED: 304>: ('Not Modified',
                                  'Document has not changed since given time'),
 <HTTPStatus.USE_PROXY: 305>: ('Use Proxy',
                               'You must use proxy specified in Location to '
                               'access this resource'),
 <HTTPStatus.TEMPORARY_REDIRECT: 307>: ('Temporary Redirect',
                                        'Object moved temporarily -- see URI '
                                        'list'),
 <HTTPStatus.PERMANENT_REDIRECT: 308>: ('Permanent Redirect',
                                        'Object moved permanently -- see URI '
                                        'list'),
 <HTTPStatus.BAD_REQUEST: 400>: ('Bad Request',
                                 'Bad request syntax or unsupported method'),
 <HTTPStatus.UNAUTHORIZED: 401>: ('Unauthorized',
                                  'No permission -- see authorization schemes'),
 <HTTPStatus.PAYMENT_REQUIRED: 402>: ('Payment Required',
                                      'No payment -- see charging schemes'),
 <HTTPStatus.FORBIDDEN: 403>: ('Forbidden',
                               'Request forbidden -- authorization will not '
                               'help'),
 <HTTPStatus.NOT_FOUND: 404>: ('Not Found', 'Nothing matches the given URI'),
 <HTTPStatus.METHOD_NOT_ALLOWED: 405>: ('Method Not Allowed',
                                        'Specified method is invalid for this '
                                        'resource'),
 <HTTPStatus.NOT_ACCEPTABLE: 406>: ('Not Acceptable',
                                    'URI not available in preferred format'),
 <HTTPStatus.PROXY_AUTHENTICATION_REQUIRED: 407>: ('Proxy Authentication '
                                                   'Required',
                                                   'You must authenticate with '
                                                   'this proxy before '
                                                   'proceeding'),
 <HTTPStatus.REQUEST_TIMEOUT: 408>: ('Request Timeout',
                                     'Request timed out; try again later'),
 <HTTPStatus.CONFLICT: 409>: ('Conflict', 'Request conflict'),
 <HTTPStatus.GONE: 410>: ('Gone',
                          'URI no longer exists and has been permanently '
                          'removed'),
 <HTTPStatus.LENGTH_REQUIRED: 411>: ('Length Required',
                                     'Client must specify Content-Length'),
 <HTTPStatus.PRECONDITION_FAILED: 412>: ('Precondition Failed',
                                         'Precondition in headers is false'),
 <HTTPStatus.REQUEST_ENTITY_TOO_LARGE: 413>: ('Request Entity Too Large',
                                              'Entity is too large'),
 <HTTPStatus.REQUEST_URI_TOO_LONG: 414>: ('Request-URI Too Long',
                                          'URI is too long'),
 <HTTPStatus.UNSUPPORTED_MEDIA_TYPE: 415>: ('Unsupported Media Type',
                                            'Entity body in unsupported '
                                            'format'),
 <HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE: 416>: ('Requested Range Not '
                                                     'Satisfiable',
                                                     'Cannot satisfy request '
                                                     'range'),
 <HTTPStatus.EXPECTATION_FAILED: 417>: ('Expectation Failed',
                                        'Expect condition could not be '
                                        'satisfied'),
 <HTTPStatus.MISDIRECTED_REQUEST: 421>: ('Misdirected Request',
                                         'Server is not able to produce a '
                                         'response'),
 <HTTPStatus.UNPROCESSABLE_ENTITY: 422>: ('Unprocessable Entity', ''),
 <HTTPStatus.LOCKED: 423>: ('Locked', ''),
 <HTTPStatus.FAILED_DEPENDENCY: 424>: ('Failed Dependency', ''),
 <HTTPStatus.UPGRADE_REQUIRED: 426>: ('Upgrade Required', ''),
 <HTTPStatus.PRECONDITION_REQUIRED: 428>: ('Precondition Required',
                                           'The origin server requires the '
                                           'request to be conditional'),
 <HTTPStatus.TOO_MANY_REQUESTS: 429>: ('Too Many Requests',
                                       'The user has sent too many requests in '
                                       'a given amount of time ("rate '
                                       'limiting")'),
 <HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE: 431>: ('Request Header Fields '
                                                     'Too Large',
                                                     'The server is unwilling '
                                                     'to process the request '
                                                     'because its header '
                                                     'fields are too large'),
 <HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS: 451>: ('Unavailable For Legal '
                                                   'Reasons',
                                                   'The server is denying '
                                                   'access to the resource as '
                                                   'a consequence of a legal '
                                                   'demand'),
 <HTTPStatus.INTERNAL_SERVER_ERROR: 500>: ('Internal Server Error',
                                           'Server got itself in trouble'),
 <HTTPStatus.NOT_IMPLEMENTED: 501>: ('Not Implemented',
                                     'Server does not support this operation'),
 <HTTPStatus.BAD_GATEWAY: 502>: ('Bad Gateway',
                                 'Invalid responses from another server/proxy'),
 <HTTPStatus.SERVICE_UNAVAILABLE: 503>: ('Service Unavailable',
                                         'The server cannot process the '
                                         'request due to a high load'),
 <HTTPStatus.GATEWAY_TIMEOUT: 504>: ('Gateway Timeout',
                                     'The gateway server did not receive a '
                                     'timely response'),
 <HTTPStatus.HTTP_VERSION_NOT_SUPPORTED: 505>: ('HTTP Version Not Supported',
                                                'Cannot fulfill request'),
 <HTTPStatus.VARIANT_ALSO_NEGOTIATES: 506>: ('Variant Also Negotiates', ''),
 <HTTPStatus.INSUFFICIENT_STORAGE: 507>: ('Insufficient Storage', ''),
 <HTTPStatus.LOOP_DETECTED: 508>: ('Loop Detected', ''),
 <HTTPStatus.NOT_EXTENDED: 510>: ('Not Extended', ''),
 <HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED: 511>: ('Network Authentication '
                                                     'Required',
                                                     'The client needs to '
                                                     'authenticate to gain '
                                                     'network access')}
alexapy.aiohttp.http.SERVER_SOFTWARE

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

'Python/3.8 aiohttp/3.6.2'
alexapy.aiohttp.http.HttpVersion10

HttpVersion(major, minor)

HttpVersion(major=1, minor=0)
alexapy.aiohttp.http.HttpVersion11

HttpVersion(major, minor)

HttpVersion(major=1, minor=1)
alexapy.aiohttp.http.WS_CLOSED_MESSAGE
WSMessage(type=<WSMsgType.CLOSED: 257>, data=None, extra=None)
alexapy.aiohttp.http.WS_CLOSING_MESSAGE
WSMessage(type=<WSMsgType.CLOSING: 256>, data=None, extra=None)
alexapy.aiohttp.http.WS_KEY

bytes(iterable_of_ints) -> bytes bytes(string, encoding[, errors]) -> bytes bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer bytes(int) -> bytes object of size given by the parameter initialized with null bytes bytes() -> empty bytes object

Construct an immutable array of bytes from:
  • an iterable yielding integers in range(256)

  • a text string encoded using the specified encoding

  • any object implementing the buffer API.

  • an integer

b'258EAFA5-E914-47DA-95CA-C5AB0DC85B11'