aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
downloadydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py')
-rw-r--r--contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py102
1 files changed, 51 insertions, 51 deletions
diff --git a/contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py b/contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py
index 40a9b22292..3a0b04e27a 100644
--- a/contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py
+++ b/contrib/tools/python3/src/Lib/xml/etree/ElementInclude.py
@@ -42,7 +42,7 @@
# --------------------------------------------------------------------
# Licensed to PSF under a Contributor Agreement.
-# See https://www.python.org/psf/license for licensing details.
+# See https://www.python.org/psf/license for licensing details.
##
# Limited XInclude support for the ElementTree package.
@@ -50,28 +50,28 @@
import copy
from . import ElementTree
-from urllib.parse import urljoin
+from urllib.parse import urljoin
XINCLUDE = "{http://www.w3.org/2001/XInclude}"
XINCLUDE_INCLUDE = XINCLUDE + "include"
XINCLUDE_FALLBACK = XINCLUDE + "fallback"
-# For security reasons, the inclusion depth is limited to this read-only value by default.
-DEFAULT_MAX_INCLUSION_DEPTH = 6
-
-
+# For security reasons, the inclusion depth is limited to this read-only value by default.
+DEFAULT_MAX_INCLUSION_DEPTH = 6
+
+
##
# Fatal include error.
class FatalIncludeError(SyntaxError):
pass
-
-class LimitedRecursiveIncludeError(FatalIncludeError):
- pass
-
-
+
+class LimitedRecursiveIncludeError(FatalIncludeError):
+ pass
+
+
##
# Default loader. This loader reads an included resource from disk.
#
@@ -102,33 +102,33 @@ def default_loader(href, parse, encoding=None):
# @param loader Optional resource loader. If omitted, it defaults
# to {@link default_loader}. If given, it should be a callable
# that implements the same interface as <b>default_loader</b>.
-# @param base_url The base URL of the original file, to resolve
-# relative include file references.
-# @param max_depth The maximum number of recursive inclusions.
-# Limited to reduce the risk of malicious content explosion.
-# Pass a negative value to disable the limitation.
-# @throws LimitedRecursiveIncludeError If the {@link max_depth} was exceeded.
+# @param base_url The base URL of the original file, to resolve
+# relative include file references.
+# @param max_depth The maximum number of recursive inclusions.
+# Limited to reduce the risk of malicious content explosion.
+# Pass a negative value to disable the limitation.
+# @throws LimitedRecursiveIncludeError If the {@link max_depth} was exceeded.
# @throws FatalIncludeError If the function fails to include a given
# resource, or if the tree contains malformed XInclude elements.
-# @throws IOError If the function fails to load a given resource.
-# @returns the node or its replacement if it was an XInclude node
-
-def include(elem, loader=None, base_url=None,
- max_depth=DEFAULT_MAX_INCLUSION_DEPTH):
- if max_depth is None:
- max_depth = -1
- elif max_depth < 0:
- raise ValueError("expected non-negative depth or None for 'max_depth', got %r" % max_depth)
-
- if hasattr(elem, 'getroot'):
- elem = elem.getroot()
+# @throws IOError If the function fails to load a given resource.
+# @returns the node or its replacement if it was an XInclude node
+
+def include(elem, loader=None, base_url=None,
+ max_depth=DEFAULT_MAX_INCLUSION_DEPTH):
+ if max_depth is None:
+ max_depth = -1
+ elif max_depth < 0:
+ raise ValueError("expected non-negative depth or None for 'max_depth', got %r" % max_depth)
+
+ if hasattr(elem, 'getroot'):
+ elem = elem.getroot()
if loader is None:
loader = default_loader
-
- _include(elem, loader, base_url, max_depth, set())
-
-
-def _include(elem, loader, base_url, max_depth, _parent_hrefs):
+
+ _include(elem, loader, base_url, max_depth, set())
+
+
+def _include(elem, loader, base_url, max_depth, _parent_hrefs):
# look for xinclude elements
i = 0
while i < len(elem):
@@ -136,24 +136,24 @@ def _include(elem, loader, base_url, max_depth, _parent_hrefs):
if e.tag == XINCLUDE_INCLUDE:
# process xinclude directive
href = e.get("href")
- if base_url:
- href = urljoin(base_url, href)
+ if base_url:
+ href = urljoin(base_url, href)
parse = e.get("parse", "xml")
if parse == "xml":
- if href in _parent_hrefs:
- raise FatalIncludeError("recursive include of %s" % href)
- if max_depth == 0:
- raise LimitedRecursiveIncludeError(
- "maximum xinclude depth reached when including file %s" % href)
- _parent_hrefs.add(href)
+ if href in _parent_hrefs:
+ raise FatalIncludeError("recursive include of %s" % href)
+ if max_depth == 0:
+ raise LimitedRecursiveIncludeError(
+ "maximum xinclude depth reached when including file %s" % href)
+ _parent_hrefs.add(href)
node = loader(href, parse)
if node is None:
raise FatalIncludeError(
"cannot load %r as %r" % (href, parse)
)
- node = copy.copy(node) # FIXME: this makes little sense with recursive includes
- _include(node, loader, href, max_depth - 1, _parent_hrefs)
- _parent_hrefs.remove(href)
+ node = copy.copy(node) # FIXME: this makes little sense with recursive includes
+ _include(node, loader, href, max_depth - 1, _parent_hrefs)
+ _parent_hrefs.remove(href)
if e.tail:
node.tail = (node.tail or "") + e.tail
elem[i] = node
@@ -163,13 +163,13 @@ def _include(elem, loader, base_url, max_depth, _parent_hrefs):
raise FatalIncludeError(
"cannot load %r as %r" % (href, parse)
)
- if e.tail:
- text += e.tail
+ if e.tail:
+ text += e.tail
if i:
node = elem[i-1]
- node.tail = (node.tail or "") + text
+ node.tail = (node.tail or "") + text
else:
- elem.text = (elem.text or "") + text
+ elem.text = (elem.text or "") + text
del elem[i]
continue
else:
@@ -181,5 +181,5 @@ def _include(elem, loader, base_url, max_depth, _parent_hrefs):
"xi:fallback tag must be child of xi:include (%r)" % e.tag
)
else:
- _include(e, loader, base_url, max_depth, _parent_hrefs)
- i += 1
+ _include(e, loader, base_url, max_depth, _parent_hrefs)
+ i += 1