1.15. serializers
¶
This module provides a standardized interface for serializing objects using
different formats. The Serializers provided by this module are organized by
their format into different classes. The necessary methods for utilizing them
are all classmethod
’s making it unnecessary to create an instance of any
of them.
1.15.1. Functions¶
-
from_elementtree_element
(element, require_type=True)[source]¶ Load a value from an
xml.etree.ElementTree.SubElement
instance. If require_type is True, then the element must specify an acceptable value via the “type” attribute. If require_type is False and no type attribute is specified, the value is returned as a string.Parameters: - element (
xml.etree.ElementTree.Element
) – The element to load a value from. - require_type (bool) – Whether or not to require type information.
Returns: The deserialized value from the element.
- element (
-
to_elementtree_subelement
(parent, tag, value, attrib=None)[source]¶ Serialize value to an
xml.etree.ElementTree.SubElement
with appropriate information describing it’s type. If value is not of a supported type, aTypeError
will be raised.Parameters: - parent (
xml.etree.ElementTree.Element
) – The parent element to associate this subelement with. - tag (str) – The name of the XML tag.
- value – The value to serialize to an XML element.
- attrib (dict) – Optional attributes to include in the element.
Returns: The newly created XML element, representing value.
Return type: - parent (
1.15.2. Classes¶
-
class
JSON
[source]¶
-
class
MsgPack
[source]¶
-
class
Serializer
[source]¶ Bases:
king_phisher.serializers._SerializerMeta
The base class for serializer objects of different formats and protocols. These serializers are extended using a King Phisher-specific protocol for serializing additional types, most notably Python’s
datetime.datetime
type.Note
None of the serializers handle Python 3’s
bytes
type. These objects will be treated as strings and silently converted.