aiospamc.responses module

Contains classes used for responses.

class aiospamc.responses.Response(version, status_code, message, headers=None, body=None)

Bases: aiospamc.common.RequestResponseBase

Class to encapsulate response.

protocol_version

str – Protocol version given by the response.

status_code

aiospamc.responess.Status – Status code give by the response.

message

str – Message accompanying the status code.

body

str or bytes – Contents of the response body.

__init__(version, status_code, message, headers=None, body=None)

Response constructor.

Parameters:
  • version (str) – Version reported by the SPAMD service response.
  • status_code (aiospamc.responses.Status) – Success or error code.
  • message (str) – Message associated with status code.
  • body (str or bytes, 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
class aiospamc.responses.Status

Bases: enum.IntEnum

Enumeration of status codes that the SPAMD will accompany with a response.

Reference: https://svn.apache.org/repos/asf/spamassassin/trunk/spamd/spamd.raw Look for the %resphash variable.

EX_CANTCREAT = 73
EX_CONFIG = 78
EX_DATAERR = 65
EX_IOERR = 74
EX_NOHOST = 68
EX_NOINPUT = 66
EX_NOPERM = 77
EX_NOUSER = 67
EX_OK = 0
EX_OSERR = 71
EX_OSFILE = 72
EX_PROTOCOL = 76
EX_SOFTWARE = 70
EX_TEMPFAIL = 75
EX_TIMEOUT = 79
EX_UNAVAILABLE = 69
EX_USAGE = 64