aiospamc.parser module¶
Parser combinators for the SPAMC/SPAMD protocol.
-
class
aiospamc.parser.
Body
¶ Bases:
aiospamc.parser.Parser
Matches the remaining stream as the body of the request/response.
-
class
aiospamc.parser.
Boolean
¶ Bases:
aiospamc.parser.Parser
Matches and returns a bool.
-
class
aiospamc.parser.
CompressHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.Compress
header and returns an instance if successful.
-
class
aiospamc.parser.
ContentLengthHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.ContentLength
header and returns an instance if successful.
-
class
aiospamc.parser.
CustomHeader
¶ Bases:
aiospamc.parser.Parser
Matches a custom header and returns an instance of
aiospamc.headers.XHeader
if successful.
-
class
aiospamc.parser.
DidRemoveHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.DidRemove
header and returns an instance if successful.
-
class
aiospamc.parser.
DidSetHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.DidSet
header and returns an instance if successful.
-
class
aiospamc.parser.
Digits
¶ Bases:
aiospamc.parser.Parser
Matches a sequence of digits and returns a string.
-
class
aiospamc.parser.
Discard
(parser)¶ Bases:
aiospamc.parser.Parser
Shortcut for
Replace
which replaces with aNone
value.Parameters: parser ( aiospamc.parser.Parser
) –
-
class
aiospamc.parser.
Failure
(error, remaining)¶ Bases:
object
Contains error message and location the where the parser failed.
-
error
¶ str
– Error message.
-
remaining
¶ aiospamc.parser.Stream
– Remaining stream to parse.
-
__init__
(error, remaining)¶ Failure object constructor.
Parameters: - error (
str
) – Error message. - remaining (
aiospamc.parser.Stream
) – Remaining stream to parse.
- error (
-
-
class
aiospamc.parser.
FalseValue
¶ Bases:
aiospamc.parser.Parser
Matches the string “false” or “False” and returns the boolean value.
-
class
aiospamc.parser.
Float
¶ Bases:
aiospamc.parser.Parser
Matches a floating point number and returns a float.
-
class
aiospamc.parser.
Header
(name, value)¶ Bases:
aiospamc.parser.Parser
Matches a header format, name and value separated by a colon and terminated by a newline.
-
class
aiospamc.parser.
Headers
¶ Bases:
aiospamc.parser.Parser
Matches headers and returns an instance if successful.
-
class
aiospamc.parser.
Integer
¶ Bases:
aiospamc.parser.Parser
Matches a sequence of digits and returns an integer.
-
class
aiospamc.parser.
Map
(parser, func)¶ Bases:
aiospamc.parser.Parser
Applies the referenced function to the value returned from the parser.
-
parser
¶
-
func
¶ callable
-
-
class
aiospamc.parser.
Match
(match)¶ Bases:
aiospamc.parser.Parser
Matches a regular expression. Returns the regular expression result as the value if successful.
Parameters: match ( bytes
) – Regular expression to match.
-
class
aiospamc.parser.
MessageClassHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.MessageClass
header and returns an instance if successful.
-
class
aiospamc.parser.
MessageClassOption
¶ Bases:
aiospamc.parser.Parser
Matches ‘spam’ or ‘ham’ and returns an instance of
aiospamc.options.MessageClassOption
.
-
class
aiospamc.parser.
Newline
¶ Bases:
aiospamc.parser.Parser
Matches newline sequence and returns regular expression result.
-
class
aiospamc.parser.
Number
¶ Bases:
aiospamc.parser.Parser
Matches either an integer or a float.
-
class
aiospamc.parser.
OneOrMore
(parser)¶ Bases:
aiospamc.parser.Parser
Matches one or more repetitions of the parser.
Parameters: parser ( aiospamc.parser.Parser
) –
-
class
aiospamc.parser.
Optional
(parser)¶ Bases:
aiospamc.parser.Parser
If the parser is found then the value is returned, if not then a
None
value is returned.Parameters: parser ( aiospamc.parser.Parser
) –
-
class
aiospamc.parser.
Or
(left, right)¶ Bases:
aiospamc.parser.Parser
Matches the left or right parser.
-
right
¶
-
-
class
aiospamc.parser.
Parser
¶ Bases:
object
Parser base class. Overloads operators for ease of writing parsers.
The following lists the operator and the effect it has:
Operator Effect -A Matches A, but discards the result ~A Optionally matches A A | B Logical OR A >> B Sequence of A then B A ^ B Logical XOR
-
class
aiospamc.parser.
RemoveHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.Remove
header and returns an instance if successful.
-
class
aiospamc.parser.
Replace
(parser, replace)¶ Bases:
aiospamc.parser.Parser
If parser returns a successful result then it’s replaced with the value given.
Parameters: - parser (
aiospamc.parser.Parser
) – - replace – Value to replace a successful result with.
- parser (
-
class
aiospamc.parser.
Request
¶ Bases:
aiospamc.parser.Parser
Matches a SPAMC request and returns an instance of
aiospamc.requests.Request
.
-
class
aiospamc.parser.
RequestMethod
¶ Bases:
aiospamc.parser.Parser
Matches a request method.
-
class
aiospamc.parser.
Response
¶ Bases:
aiospamc.parser.Parser
Matches a SPAMD response and returns an instance of
aiospamc.responses.Response
.
-
class
aiospamc.parser.
SAParser
¶ Bases:
aiospamc.parser.Parser
Start rule for the parser. Returns an instance of either
aiospamc.requests.Request
oraiospamc.responses.Response
.
-
class
aiospamc.parser.
Sequence
(left, right)¶ Bases:
aiospamc.parser.Parser
Matches the left and then the right parser in sequence.
-
right
¶
-
-
class
aiospamc.parser.
SetHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.Set
header and returns an instance if successful.
-
class
aiospamc.parser.
SetRemoveValue
¶ Bases:
aiospamc.parser.Parser
Matches a value for the
aiospamc.headers.DidRemove
,aiospamc.headers.DidSet
,aiospamc.headers.Remove
, oraiospamc.headers.Set
.
-
class
aiospamc.parser.
SpamHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.Spam
header and returns an instance if successful.
-
class
aiospamc.parser.
Str
(match)¶ Bases:
aiospamc.parser.Parser
Matches a regular expression and casts it to a string.
Parameters: match ( bytes
) – Regular expression to match.
-
class
aiospamc.parser.
Stream
(stream, index)¶ Bases:
tuple
-
count
(value) → integer -- return number of occurrences of value¶
-
index
¶ Alias for field number 1
-
stream
¶ Alias for field number 0
-
-
class
aiospamc.parser.
Success
(value, remaining)¶ Bases:
object
Contains successful result and location for a parser.
-
value
¶ Result of a successful parse.
-
remaining
¶ aiospamc.parser.Stream
– Remaining stream to parse.
-
__init__
(value, remaining)¶ Success object constructor.
Parameters: - value – Result of a successful parse.
- remaining (
aiospamc.parser.Stream
) – Remaining stream to parse.
-
-
class
aiospamc.parser.
TrueValue
¶ Bases:
aiospamc.parser.Parser
Matches the string “true” or “True” and returns the boolean value.
-
class
aiospamc.parser.
UserHeader
¶ Bases:
aiospamc.parser.Parser
Matches a
aiospamc.headers.User
header and returns an instance if successful.
-
class
aiospamc.parser.
Version
¶ Bases:
aiospamc.parser.Parser
Matches a version code and returns a string.
-
class
aiospamc.parser.
Whitespace
¶ Bases:
aiospamc.parser.Parser
Matches sequence of whitespace and returns regular expression result.
-
class
aiospamc.parser.
Xor
(left, right)¶ Bases:
aiospamc.parser.Parser
Matches only either the left or right parser.
-
right
¶
-
-
class
aiospamc.parser.
ZeroOrMore
(parser)¶ Bases:
aiospamc.parser.Parser
Matches zero or more repetitions of the parser.
Parameters: parser ( aiospamc.parser.Parser
) –
-
aiospamc.parser.
concat
(container)¶ Concatenates items within a collection into a string.
-
aiospamc.parser.
flatten
(container)¶ Flattens nested lists into one list.
-
aiospamc.parser.
remove_empty
(container)¶ Removes None and empty strings from the container.