MCPcopy Index your code
hub / github.com/python/cpython / C14NWriterTarget

Class C14NWriterTarget

Lib/xml/etree/ElementTree.py:1794–2049  ·  view source on GitHub ↗

Canonicalization writer target for the XMLParser. Serialises parse events to XML C14N 2.0. The *write* function is used for writing out the resulting data stream as text (not bytes). To write to a file, open it in text mode with encoding "utf-8" and pass its ``.write`` method

Source from the content-addressed store, hash-verified

1792
1793
1794class C14NWriterTarget:
1795 """
1796 Canonicalization writer target for the XMLParser.
1797
1798 Serialises parse events to XML C14N 2.0.
1799
1800 The *write* function is used for writing out the resulting data stream
1801 as text (not bytes). To write to a file, open it in text mode with encoding
1802 "utf-8" and pass its ``.write`` method.
1803
1804 Configuration options:
1805
1806 - *with_comments*: set to true to include comments
1807 - *strip_text*: set to true to strip whitespace before and after text content
1808 - *rewrite_prefixes*: set to true to replace namespace prefixes by "n{number}"
1809 - *qname_aware_tags*: a set of qname aware tag names in which prefixes
1810 should be replaced in text content
1811 - *qname_aware_attrs*: a set of qname aware attribute names in which prefixes
1812 should be replaced in text content
1813 - *exclude_attrs*: a set of attribute names that should not be serialised
1814 - *exclude_tags*: a set of tag names that should not be serialised
1815 """
1816 def __init__(self, write, *,
1817 with_comments=False, strip_text=False, rewrite_prefixes=False,
1818 qname_aware_tags=None, qname_aware_attrs=None,
1819 exclude_attrs=None, exclude_tags=None):
1820 self._write = write
1821 self._data = []
1822 self._with_comments = with_comments
1823 self._strip_text = strip_text
1824 self._exclude_attrs = set(exclude_attrs) if exclude_attrs else None
1825 self._exclude_tags = set(exclude_tags) if exclude_tags else None
1826
1827 self._rewrite_prefixes = rewrite_prefixes
1828 if qname_aware_tags:
1829 self._qname_aware_tags = set(qname_aware_tags)
1830 else:
1831 self._qname_aware_tags = None
1832 if qname_aware_attrs:
1833 self._find_qname_aware_attrs = set(qname_aware_attrs).intersection
1834 else:
1835 self._find_qname_aware_attrs = None
1836
1837 # Stack with globally and newly declared namespaces as (uri, prefix) pairs.
1838 self._declared_ns_stack = [[
1839 ("http://www.w3.org/XML/1998/namespace", "xml"),
1840 ]]
1841 # Stack with user declared namespace prefixes as (uri, prefix) pairs.
1842 self._ns_stack = []
1843 if not rewrite_prefixes:
1844 self._ns_stack.append(list(_namespace_map.items()))
1845 self._ns_stack.append([])
1846 self._prefix_map = {}
1847 self._preserve_space = [False]
1848 self._pending_start = None
1849 self._root_seen = False
1850 self._root_done = False
1851 self._ignored_depth = 0

Callers 1

canonicalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…