aiospamc.common module

Common classes for the project.

class aiospamc.common.RequestResponseBase(body=None, headers=None)

Bases: object

Base class for requests and responses.

__init__(body=None, headers=None)
Parameters:
  • body (str, optional) – String representation of the body. An instance of the aiospamc.headers.ContentLength will be automatically added.
  • headers (tuple of aiospamc.headers.Header, optional) – Collection of headers to be added. If it contains an instance of aiospamc.headers.Compress then the body is automatically compressed.
add_header(header)

Adds a header to the request. A header with the same name will be overwritten.

Parameters:header (aiospamc.headers.Header) – A header object to be added.
body

Contains the contents of the body.

The getter will return a bytes object.

The setter expects a string. If the aiospamc.headers.Compress header is present then the value of body will be compressed.

The deleter will automatically remove the aiospamc.headers.ContentLength header.

delete_header(header_name)

Deletes the header from the request.

Parameters:header_name (str) – String name of the header.
Raises:KeyError
get_header(header_name)

Gets the header matching the name.

Parameters:header_name (str) – String name of the header.
Returns:A Header object or subclass of it.
Return type:aiospamc.headers.Header
Raises:KeyError