util.persistence.serializeXML2 module¶
A more compact XML serialization: like XMLSerializationStrategy, but a property whose
value is simple – a bool, int, float, or a str of fewer than
XML2SerializationStrategy.MAX_PACKED_STR characters – is written in one
tag:
<property key="filetype" type="str" value=".xml" />
rather than:
<property key="filetype">
<object type="str" value=".xml" />
</property>
A reference to an object written elsewhere in the file (a _Reference) is packed too, as its id:
<property key="db" ref="4453244544" />
Anything else (lists, dicts, other Serializable objects, long strings, None) is written as before. It reads both forms, so it reads what XMLSerializationStrategy writes; it always writes the short form.
- class util.persistence.serializeXML2.XML2SerializationStrategy¶
Bases:
XMLSerializationStrategyThe compact XML strategy (see the module doc): the default strategy.
- preferred: bool = False¶
Not chosen for the “.xml” extension: XML3SerializationStrategy is (it reads what this writes).
- PACKED_TYPES = ('bool', 'int', 'float', 'str')¶
The (type attribute values of the) simple types written packed into their property tag.
- MAX_PACKED_STR = 60¶
Strings at least this long are written in their own tag.
- ATTR_REF = 'ref'¶
The attribute of a property tag holding the id of the object it refers to (see _Reference).
- REF_ID = 'referenceID'¶
The property of a _Reference holding the id.
- classmethod protocolName() str¶
- Returns:
- Return type:
str
- classmethod protocolVersion() str¶
- Returns:
- Return type:
str
- classmethod _refID(value: Element) str | None¶
If value (an encoded object) is a _Reference, its id (as text); else None.
- Parameters:
value (Element)
- Returns:
- Return type:
Optional[str]
- _abc_impl = <_abc._abc_data object>¶
- classmethod _packable(value: Element) bool¶
Whether value (an encoded object) is simple enough to pack into its property tag.
- Parameters:
value (Element)
- Returns:
- Return type:
bool
- classmethod _unpacked(prop: Element) Element | None¶
The value of property prop: its child, or, if it’s packed, the object tag it stands for (made from its type and value, or its reference id).
- Parameters:
prop (Element)
- Returns:
- Return type:
Optional[Element]
- _setKVPair(elem: Element, key: Element | str, value: Element) None¶
- Parameters:
elem (Element)
key (Element | str)
value (Element)
- _getKVPair(elem: Element, key: str) Element | None¶
- Parameters:
elem (Element)
key (str)
- Returns:
- Return type:
Optional[Element]
- _getKVPairs(elem: Element) list[tuple[Element, Element]] | dict[str, Element]¶
- Parameters:
elem (Element)
- Returns:
- Return type:
list[tuple[Element, Element]] | dict[str, Element]