Implementation of rfc822 serializer and deserializer.
Warning
THIS MODULE DOES NOT HAVE STABLE PUBLIC API
-
class plainbox.impl.secure.rfc822.RFC822Record(data, origin=None, raw_data=None, field_offset_map=None)[source]
Bases: builtins.object
Class for tracking RFC822 records.
This is a simple container for the dictionary of data. The data is
represented by two copies, one original and one after value normalization.
Value normalization strips out excess whitespace and processes the magic
leading dot syntax that is essential for empty newlines.
Comparison is performed on the normalized data only, raw data is stored for
reference but does not differentiate records.
Each instance also holds the origin of the data (location of the
file/stream where it was parsed from).
-
data[source]
The normalized version of the data set (dictionary)
This property exposes the normalized version of the data encapsulated
in this record. Normalization is performed with
normalize_rfc822_value(). Only values are normalized, keys are
left intact.
-
dump(stream)[source]
Dump this record to a stream
-
field_offset_map[source]
The field-to-line-number-offset mapping.
A dictionary mapping field name to offset (in lines) relative to the
origin where that field definition commences.
Note: the return value may be None
-
origin[source]
The origin of the record.
-
raw_data[source]
The raw version of data set (dictionary)
This property exposes the raw (original) version of the data
encapsulated by this record. This data is as it was originally parsed,
including all the whitespace layout.
In some records this may be ‘normal’ data object itself (same object).
-
exception plainbox.impl.secure.rfc822.RFC822SyntaxError(filename, lineno, msg)[source]
Bases: builtins.SyntaxError
SyntaxError subclass for RFC822 parsing functions
-
args
-
filename
exception filename
-
lineno
exception lineno
-
msg
exception msg
-
offset
exception offset
-
print_file_and_line
exception print_file_and_line
-
text
exception text
-
with_traceback()
Exception.with_traceback(tb) –
set self.__traceback__ to tb and return self.
-
plainbox.impl.secure.rfc822.gen_rfc822_records(stream, data_cls=<class 'dict'>, source=None)[source]
Load a sequence of rfc822-like records from a text stream.
Parameters: |
- stream – A file-like object from which to load the rfc822 data
- data_cls – The class of the dictionary-like type to hold the results. This is
mainly there so that callers may pass collections.OrderedDict.
- source – A plainbox.abc.ITextSource subclass instance that describes
where stream data is coming from. If None, it will be inferred from the
stream (if possible). Specialized callers should provider a custom
source object to allow developers to accurately keep track of where
(possibly problematic) RFC822 data is coming from. If this is None and
inferring fails then all of the loaded records will have a None origin.
|
Each record consists of any number of key-value pairs. Subsequent records
are separated by one blank line. A record key may have a multi-line value
if the line starts with whitespace character.
Returns a list of subsequent values as instances RFC822Record class. If
the optional data_cls argument is collections.OrderedDict then the values
retain their original ordering.
-
plainbox.impl.secure.rfc822.load_rfc822_records(stream, data_cls=<class 'dict'>, source=None)[source]
Load a sequence of rfc822-like records from a text stream.
Parameters: |
- stream – A file-like object from which to load the rfc822 data
- data_cls – The class of the dictionary-like type to hold the results. This is
mainly there so that callers may pass collections.OrderedDict.
- source – A plainbox.abc.ITextSource subclass instance that describes
where stream data is coming from. If None, it will be inferred from the
stream (if possible). Specialized callers should provider a custom
source object to allow developers to accurately keep track of where
(possibly problematic) RFC822 data is coming from. If this is None and
inferring fails then all of the loaded records will have a None origin.
|
Each record consists of any number of key-value pairs. Subsequent records
are separated by one blank line. A record key may have a multi-line value
if the line starts with whitespace character.
Returns a list of subsequent values as instances RFC822Record class. If
the optional data_cls argument is collections.OrderedDict then the values
retain their original ordering.
-
plainbox.impl.secure.rfc822.normalize_rfc822_value(value)[source]