aiospamc.parser module¶
Parser object for SPAMC/SPAMD requests and responses.
-
exception
aiospamc.parser.
ParseError
(index, message)¶ Bases:
Exception
An exception occurring when parsing.
-
index
¶ int
– Index in the stream the exception occurred.
-
message
¶ str
– User readable message.
-
__init__
(index, message)¶ ParseError constructor.
Parameters: - index (
int
) – Index in the stream the exception occurred. - message (
str
) – User readable message.
- index (
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
aiospamc.parser.
Parser
(string=None)¶ Bases:
object
Parser object for requests and responses.
-
__init__
(string=None)¶ Parser constructor.
Parameters: string ( str
, optional) – The string to parse.
-
advance
(by)¶ Advance the current index by number of bytes.
Parameters: by ( int
) – Number of bytes in the stream to advance.
-
body
()¶ Consumes the rest of the message and returns the contents.
Returns: Return type: bytes
-
compress_value
()¶ Consumes the Compression header value.
Returns: Return type: str
-
consume
(pattern)¶ If the pattern matches, advances the index the length of the match. Returns the regular expression match.
Parameters: pattern ( bytes
) –Returns: Return type: Regular expression match Raises: aiospamc.parser.ParseError
-
content_length_value
()¶ Consumes the Content-length header value.
Returns: Return type: int
-
current
()¶ The remainder of the string that hasn’t been parsed.
Returns: Return type: str
-
end
()¶ Whether the parser has parsed the entire string.
Returns: Return type: bool
-
header
()¶ Consumes the string and returns an instance of
aiospamc.headers.Header
.Returns: Return type: aiospamc.headers.Header
-
headers
()¶ Consumes all headers.
Returns: Return type: list
ofaiospamc.headers.Header
-
match
(pattern)¶ Returns the regular expression matches string at the current index.
Parameters: pattern ( bytes
) –Returns: Return type: Regular expression match
-
message
()¶ Consumes a string until it matches a newline.
Returns: Return type: str
-
message_class_value
()¶ Consumes the Message-class header value.
Returns: Return type: aiospamc.options.MessageClassOption
-
method
()¶ Consumes the method name in a request.
Returns: Return type: str
-
newline
()¶ Consumes a newline sequence (carriage return and line feed).
-
request
()¶ Consumes a SPAMC request.
Returns: Return type: aiospamc.requests.Request
-
response
()¶ Consumes a SPAMD response.
Returns: Return type: aiospamc.responses.Response
-
set_remove_value
()¶ Consumes the value for the DidRemove, DidSet, Remove and Set headers.
Returns: Return type: aiospamc.options.ActionOption
-
static
skip
()¶ Makes the parser function optional by ignore whether it raises a
aiospamc.parser.ParseError
exception or not.Parameters: func (function) – Function to execute.
-
spam_value
()¶ Consumes the Spam header value.
Returns: Has the keys value, score, and threshold. Return type: dict
-
spamc_protocol
()¶ Consumes the string “SPAMC”.
Returns: Return type: str
-
spamd_protocol
()¶ Consumes the string “SPAMD”.
Returns: Return type: str
-
status_code
()¶ Consumes the status code.
Returns: Return type: aiospamc.responses.StatusCode
or int
-
user_value
()¶ Consumes the User header value.
Returns: Return type: str
-
version
()¶ Consumes a version pattern. For example, “1.5”.
Returns: Return type: str
-
whitespace
()¶ Consumes spaces or tabs.
-
-
aiospamc.parser.
checkpoint
(func)¶ A decorator to restore the index if an exception occurred.
-
aiospamc.parser.
parse
(string)¶ Parses a request or response.
Returns: Return type: aiospamc.requests.Request
oraiospamc.responses.Response