bpo-36227: ElementTree.tostring() default_namespace and xml_declaration arguments (GH-12225)

Add new keyword arguments "default_namespace" and "xml_declaration" to functions ET.tostring() and ET.tostringlist(), as known from ElementTree.write().
This commit is contained in:
Bernt Røskar Brenna 2019-04-14 10:07:02 +02:00 committed by Stefan Behnel
parent 830b43d03c
commit ffca16e25a
4 changed files with 152 additions and 9 deletions

View file

@ -594,6 +594,7 @@ Functions
.. function:: tostring(element, encoding="us-ascii", method="xml", *, \
xml_declaration=None, default_namespace=None,
short_empty_elements=True)
Generates a string representation of an XML element, including all
@ -601,14 +602,19 @@ Functions
the output encoding (default is US-ASCII). Use ``encoding="unicode"`` to
generate a Unicode string (otherwise, a bytestring is generated). *method*
is either ``"xml"``, ``"html"`` or ``"text"`` (default is ``"xml"``).
*short_empty_elements* has the same meaning as in :meth:`ElementTree.write`.
Returns an (optionally) encoded string containing the XML data.
*xml_declaration*, *default_namespace* and *short_empty_elements* has the same
meaning as in :meth:`ElementTree.write`. Returns an (optionally) encoded string
containing the XML data.
.. versionadded:: 3.4
The *short_empty_elements* parameter.
.. versionadded:: 3.8
The *xml_declaration* and *default_namespace* parameters.
.. function:: tostringlist(element, encoding="us-ascii", method="xml", *, \
xml_declaration=None, default_namespace=None,
short_empty_elements=True)
Generates a string representation of an XML element, including all
@ -616,16 +622,19 @@ Functions
the output encoding (default is US-ASCII). Use ``encoding="unicode"`` to
generate a Unicode string (otherwise, a bytestring is generated). *method*
is either ``"xml"``, ``"html"`` or ``"text"`` (default is ``"xml"``).
*short_empty_elements* has the same meaning as in :meth:`ElementTree.write`.
Returns a list of (optionally) encoded strings containing the XML data.
It does not guarantee any specific sequence, except that
``b"".join(tostringlist(element)) == tostring(element)``.
*xml_declaration*, *default_namespace* and *short_empty_elements* has the same
meaning as in :meth:`ElementTree.write`. Returns a list of (optionally) encoded
strings containing the XML data. It does not guarantee any specific sequence,
except that ``b"".join(tostringlist(element)) == tostring(element)``.
.. versionadded:: 3.2
.. versionadded:: 3.4
The *short_empty_elements* parameter.
.. versionadded:: 3.8
The *xml_declaration* and *default_namespace* parameters.
.. function:: XML(text, parser=None)