Nested generator based HTML/XML serialization module.
Provides primitives for generating XML using nested generators.
Properties
functools
itertools0
typing0
namespaces0
namespaces = (
('xml', "http://www.w3.org/XML/1998/namespace"),
('xmlns', "http://www.w3.org/2000/xmlns/"),
('schema', "http://www.w3.org/2001/XMLSchema"),
('schema-datatypes', "http://www.w3.org/2001/XMLSchema-datatypes"),
('relaxng', "http://relaxng.org/ns/structure/1.0"),
('schematron', "http://www.ascc.net/xml/schematron"),
('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
('xlink', "http://www.w3.org/1999/xlink"),
('xinclude', "http://www.w3.org/2001/XInclude"),
('xslt', "http://www.w3.org/1999/XSL/Transform"),
('xhtml', "http://www.w3.org/1999/xhtml"),
('svg', "http://www.w3.org/2000/svg"),
('mathml', "http://www.w3.org/1998/Math/MathML"),
('l', "http://if.fault.io/xml/literals"),
)
escape_element_bytes50%
escape_element_bytes(data)
Escape bytes instances for storage inside an XML element. bytes instances are yielded out as there may be a series of CDATA sections, and element works with iterators when dealing with content.
This returns an iterable suitable for use by element.
escape_element_string0
escape_element_string(string)
Escape and encode an arbitrary string for storage inside an XML element body. This depends on escape_element_bytes and has the same limitations with respect to control characters.
This returns an iterable suitable for use by element.
escape_attribute_string188%
escape_attribute_string(string)
Escape the given string for inclusion in an attribute value. Does not encode the result string.
| WARNING | |
This function only escapes ampersands, less-than comparison characters, and quotes. Low-ASCII will not be escaped and must be processed by a distinct function. This should only be used in cases where the source is known to not produce low-ASCII. |
attribute516%str
attribute(identifier, value)
Construct an XML attribute from the identifier and its value.
Does not encode the result string, and attribute values are subjected to the effect of escape_attribute_string.
Returns a str as they are normally interpolated inside encode_element.
empty20%
empty(element_identifier)
Return an iterable to an empty element.
encode_element758%
encode_element(encoding, element_identifier, content, *attribute_sequence, **attributes)
Generate an entire element populating the body by yielding from the given content.
element0
element = functools.partial(encode_element, 'utf-8')
Serialization0
Base class for XML serialization instances. Used to localize encoding bindings and default element prefixes.
After a Serialization instance is initialized, the element and escape attributes will be available for use as they depend on the encoding. Serialization is strictly concerned with the binary emission of a document built for nested iterators.
SerializationProperties
Serialization__init__0
__init__(self)
Initialize the serializer to write XML data in the given encoding.
Serializationdeclaration0
declaration(self, standalone)
Construct and return an ASCII encoded string representing the declaration consistent with the Serialization context.
SerializationdeclarationParameters
Serializationencode20%
encode(self, string)
Encode the given string in the configured encoding with 'xmlcharrefreplace' on errors.
Returns the encoded string in a tuple for placement into element calls.
Serializationempty20%
empty(self, name, *args, **kw)
Construct an empty XML element with the attributes defined by parameters.
Serializationswitch60%
switch(self)
Create another Serialization instance using a different prefix.
Serializationelement20%
element(self, element_name, subnode_iterator, *attributes, **kwattributes)
Serialize an element with the exact element_name with the contents of subnode_iterator as the inner nodes. subnode_iterator must produce bytes encoded objects.
Serializationprefixed20%
prefixed(self, element_name, *args, **kw)
Serialize an element using element, but prefix the element name with prefix configured at xml_prefix.
The configured prefix may or may not be an XML namespace.
Serializationpi0
pi(self, target, data)
Emit an XML Processing Instruction.
Processing Instruction productions are different than element productions as a single string is returned rather than an iterator.
Serializationroot190%
root(self, name, content, *attributes)
Construct the root element of a document.
Serializationliteral20%
literal(self, ordinal)
Create a literal element used to represent a disallowed XML character.
Strict XML processing implementations may disallow many low-ascii characters, even when encoded as an entity. This restriction is problematic as it requires some compensation when working with binary data.
literal provides a way to escape any octet for encoding purposes. The given oridinal will be returned as an element in the l namespace. When serializing XML output that exercises literal, the l namespace must be defined ahead of time.
Serializationtext20%
text(self, *strings)
Emit a text node without escaping contents. Encoding errors will be raised.
Serializationescape20%
escape(self, string)
Escape the given string and encode it in the configured encoding.
Serializationhyperlink20%
hyperlink(self, href)
Emit the default hyperlink attribute representation.