Skip to content

Commit a3f1e98

Browse files
miss-islingtonmbel0serhiy-storchakaAA-Turner
authored
[3.12] gh-101549: fix documentation of xml.etree.ElementInclude (GH-101550) (#117754)
Co-authored-by: Mikhail B <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent a4541a6 commit a3f1e98

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

Doc/library/xml.etree.elementtree.rst

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -835,33 +835,28 @@ Functions
835835

836836
.. module:: xml.etree.ElementInclude
837837

838-
.. function:: xml.etree.ElementInclude.default_loader( href, parse, encoding=None)
839-
:module:
838+
.. function:: default_loader(href, parse, encoding=None)
840839

841-
Default loader. This default loader reads an included resource from disk. *href* is a URL.
842-
*parse* is for parse mode either "xml" or "text". *encoding*
843-
is an optional text encoding. If not given, encoding is ``utf-8``. Returns the
844-
expanded resource. If the parse mode is ``"xml"``, this is an ElementTree
845-
instance. If the parse mode is "text", this is a Unicode string. If the
846-
loader fails, it can return None or raise an exception.
840+
Default loader. This default loader reads an included resource from disk.
841+
*href* is a URL. *parse* is for parse mode either "xml" or "text".
842+
*encoding* is an optional text encoding. If not given, encoding is ``utf-8``.
843+
Returns the expanded resource.
844+
If the parse mode is ``"xml"``, this is an :class:`~xml.etree.ElementTree.Element` instance.
845+
If the parse mode is ``"text"``, this is a string.
846+
If the loader fails, it can return ``None`` or raise an exception.
847847

848848

849-
.. function:: xml.etree.ElementInclude.include( elem, loader=None, base_url=None, \
850-
max_depth=6)
851-
:module:
849+
.. function:: include(elem, loader=None, base_url=None, max_depth=6)
852850

853-
This function expands XInclude directives. *elem* is the root element. *loader* is
854-
an optional resource loader. If omitted, it defaults to :func:`default_loader`.
851+
This function expands XInclude directives in-place in tree pointed by *elem*.
852+
*elem* is either the root :class:`~xml.etree.ElementTree.Element` or an
853+
:class:`~xml.etree.ElementTree.ElementTree` instance to find such element.
854+
*loader* is an optional resource loader. If omitted, it defaults to :func:`default_loader`.
855855
If given, it should be a callable that implements the same interface as
856856
:func:`default_loader`. *base_url* is base URL of the original file, to resolve
857857
relative include file references. *max_depth* is the maximum number of recursive
858-
inclusions. Limited to reduce the risk of malicious content explosion. Pass a
859-
negative value to disable the limitation.
860-
861-
Returns the expanded resource. If the parse mode is
862-
``"xml"``, this is an ElementTree instance. If the parse mode is "text",
863-
this is a Unicode string. If the loader fails, it can return None or
864-
raise an exception.
858+
inclusions. Limited to reduce the risk of malicious content explosion.
859+
Pass ``None`` to disable the limitation.
865860

866861
.. versionchanged:: 3.9
867862
Added the *base_url* and *max_depth* parameters.

Lib/xml/etree/ElementInclude.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class LimitedRecursiveIncludeError(FatalIncludeError):
7979
# @param parse Parse mode. Either "xml" or "text".
8080
# @param encoding Optional text encoding (UTF-8 by default for "text").
8181
# @return The expanded resource. If the parse mode is "xml", this
82-
# is an ElementTree instance. If the parse mode is "text", this
83-
# is a Unicode string. If the loader fails, it can return None
82+
# is an Element instance. If the parse mode is "text", this
83+
# is a string. If the loader fails, it can return None
8484
# or raise an OSError exception.
8585
# @throws OSError If the loader fails to load the resource.
8686

@@ -98,20 +98,21 @@ def default_loader(href, parse, encoding=None):
9898
##
9999
# Expand XInclude directives.
100100
#
101-
# @param elem Root element.
101+
# @param elem Root Element or any ElementTree of a tree to be expanded
102102
# @param loader Optional resource loader. If omitted, it defaults
103103
# to {@link default_loader}. If given, it should be a callable
104104
# that implements the same interface as <b>default_loader</b>.
105105
# @param base_url The base URL of the original file, to resolve
106106
# relative include file references.
107107
# @param max_depth The maximum number of recursive inclusions.
108108
# Limited to reduce the risk of malicious content explosion.
109-
# Pass a negative value to disable the limitation.
109+
# Pass None to disable the limitation.
110110
# @throws LimitedRecursiveIncludeError If the {@link max_depth} was exceeded.
111111
# @throws FatalIncludeError If the function fails to include a given
112112
# resource, or if the tree contains malformed XInclude elements.
113-
# @throws IOError If the function fails to load a given resource.
114-
# @returns the node or its replacement if it was an XInclude node
113+
# @throws OSError If the function fails to load a given resource.
114+
# @throws ValueError If negative {@link max_depth} is passed.
115+
# @returns None. Modifies tree pointed by {@link elem}
115116

116117
def include(elem, loader=None, base_url=None,
117118
max_depth=DEFAULT_MAX_INCLUSION_DEPTH):

0 commit comments

Comments
 (0)