Skip to content

Commit 898f6de

Browse files
mbel0serhiy-storchakaAA-Turner
authored
gh-101549: fix documentation of xml.etree.ElementInclude (#101550)
Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent 91d7605 commit 898f6de

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
@@ -840,33 +840,28 @@ Functions
840840

841841
.. module:: xml.etree.ElementInclude
842842

843-
.. function:: xml.etree.ElementInclude.default_loader( href, parse, encoding=None)
844-
:module:
843+
.. function:: default_loader(href, parse, encoding=None)
845844

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

853853

854-
.. function:: xml.etree.ElementInclude.include( elem, loader=None, base_url=None, \
855-
max_depth=6)
856-
:module:
854+
.. function:: include(elem, loader=None, base_url=None, max_depth=6)
857855

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

871866
.. versionchanged:: 3.9
872867
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)