MCPcopy Index your code
hub / github.com/RustPython/RustPython / canonicalize

Function canonicalize

Lib/xml/etree/ElementTree.py:1757–1784  ·  view source on GitHub ↗

Convert XML to its C14N 2.0 serialised form. If *out* is provided, it must be a file or file-like object that receives the serialised canonical XML output (text, not bytes) through its ``.write()`` method. To write to a file, open it in text mode with encoding "utf-8". If *out* is

(xml_data=None, *, out=None, from_file=None, **options)

Source from the content-addressed store, hash-verified

1755# C14N 2.0
1756
1757def canonicalize(xml_data=None, *, out=None, from_file=None, **options):
1758 """Convert XML to its C14N 2.0 serialised form.
1759
1760 If *out* is provided, it must be a file or file-like object that receives
1761 the serialised canonical XML output (text, not bytes) through its ``.write()``
1762 method. To write to a file, open it in text mode with encoding "utf-8".
1763 If *out* is not provided, this function returns the output as text string.
1764
1765 Either *xml_data* (an XML string) or *from_file* (a file path or
1766 file-like object) must be provided as input.
1767
1768 The configuration options are the same as for the ``C14NWriterTarget``.
1769 """
1770 if xml_data is None and from_file is None:
1771 raise ValueError("Either 'xml_data' or 'from_file' must be provided as input")
1772 sio = None
1773 if out is None:
1774 sio = out = io.StringIO()
1775
1776 parser = XMLParser(target=C14NWriterTarget(out.write, **options))
1777
1778 if xml_data is not None:
1779 parser.feed(xml_data)
1780 parser.close()
1781 elif from_file is not None:
1782 parse(from_file, parser=parser)
1783
1784 return sio.getvalue() if sio is not None else None
1785
1786
1787_looks_like_prefix_name = re.compile(r'^\w+:\w+$', re.UNICODE).match

Callers 2

mainFunction · 0.85
linkFunction · 0.85

Calls 6

feedMethod · 0.95
closeMethod · 0.95
XMLParserClass · 0.85
C14NWriterTargetClass · 0.85
parseFunction · 0.70
getvalueMethod · 0.45

Tested by

no test coverage detected