aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/xml/etree/ElementPath.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/xml/etree/ElementPath.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/xml/etree/ElementPath.py')
-rw-r--r--contrib/tools/python3/src/Lib/xml/etree/ElementPath.py206
1 files changed, 103 insertions, 103 deletions
diff --git a/contrib/tools/python3/src/Lib/xml/etree/ElementPath.py b/contrib/tools/python3/src/Lib/xml/etree/ElementPath.py
index 7f7606c631..880ea7bd99 100644
--- a/contrib/tools/python3/src/Lib/xml/etree/ElementPath.py
+++ b/contrib/tools/python3/src/Lib/xml/etree/ElementPath.py
@@ -48,7 +48,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.
##
# Implementation module for XPath support. There's usually no reason
@@ -71,29 +71,29 @@ xpath_tokenizer_re = re.compile(
)
def xpath_tokenizer(pattern, namespaces=None):
- default_namespace = namespaces.get('') if namespaces else None
- parsing_attribute = False
+ default_namespace = namespaces.get('') if namespaces else None
+ parsing_attribute = False
for token in xpath_tokenizer_re.findall(pattern):
- ttype, tag = token
- if tag and tag[0] != "{":
- if ":" in tag:
+ ttype, tag = token
+ if tag and tag[0] != "{":
+ if ":" in tag:
prefix, uri = tag.split(":", 1)
- try:
- if not namespaces:
- raise KeyError
- yield ttype, "{%s}%s" % (namespaces[prefix], uri)
- except KeyError:
- raise SyntaxError("prefix %r not found in prefix map" % prefix) from None
- elif default_namespace and not parsing_attribute:
- yield ttype, "{%s}%s" % (default_namespace, tag)
- else:
- yield token
- parsing_attribute = False
+ try:
+ if not namespaces:
+ raise KeyError
+ yield ttype, "{%s}%s" % (namespaces[prefix], uri)
+ except KeyError:
+ raise SyntaxError("prefix %r not found in prefix map" % prefix) from None
+ elif default_namespace and not parsing_attribute:
+ yield ttype, "{%s}%s" % (default_namespace, tag)
+ else:
+ yield token
+ parsing_attribute = False
else:
yield token
- parsing_attribute = ttype == '@'
+ parsing_attribute = ttype == '@'
+
-
def get_parent_map(context):
parent_map = context.parent_map
if parent_map is None:
@@ -103,69 +103,69 @@ def get_parent_map(context):
parent_map[e] = p
return parent_map
-
-def _is_wildcard_tag(tag):
- return tag[:3] == '{*}' or tag[-2:] == '}*'
-
-
-def _prepare_tag(tag):
- _isinstance, _str = isinstance, str
- if tag == '{*}*':
- # Same as '*', but no comments or processing instructions.
- # It can be a surprise that '*' includes those, but there is no
- # justification for '{*}*' doing the same.
- def select(context, result):
- for elem in result:
- if _isinstance(elem.tag, _str):
- yield elem
- elif tag == '{}*':
- # Any tag that is not in a namespace.
- def select(context, result):
- for elem in result:
- el_tag = elem.tag
- if _isinstance(el_tag, _str) and el_tag[0] != '{':
- yield elem
- elif tag[:3] == '{*}':
- # The tag in any (or no) namespace.
- suffix = tag[2:] # '}name'
- no_ns = slice(-len(suffix), None)
- tag = tag[3:]
- def select(context, result):
- for elem in result:
- el_tag = elem.tag
- if el_tag == tag or _isinstance(el_tag, _str) and el_tag[no_ns] == suffix:
- yield elem
- elif tag[-2:] == '}*':
- # Any tag in the given namespace.
- ns = tag[:-1]
- ns_only = slice(None, len(ns))
- def select(context, result):
- for elem in result:
- el_tag = elem.tag
- if _isinstance(el_tag, _str) and el_tag[ns_only] == ns:
- yield elem
- else:
- raise RuntimeError(f"internal parser error, got {tag}")
- return select
-
-
+
+def _is_wildcard_tag(tag):
+ return tag[:3] == '{*}' or tag[-2:] == '}*'
+
+
+def _prepare_tag(tag):
+ _isinstance, _str = isinstance, str
+ if tag == '{*}*':
+ # Same as '*', but no comments or processing instructions.
+ # It can be a surprise that '*' includes those, but there is no
+ # justification for '{*}*' doing the same.
+ def select(context, result):
+ for elem in result:
+ if _isinstance(elem.tag, _str):
+ yield elem
+ elif tag == '{}*':
+ # Any tag that is not in a namespace.
+ def select(context, result):
+ for elem in result:
+ el_tag = elem.tag
+ if _isinstance(el_tag, _str) and el_tag[0] != '{':
+ yield elem
+ elif tag[:3] == '{*}':
+ # The tag in any (or no) namespace.
+ suffix = tag[2:] # '}name'
+ no_ns = slice(-len(suffix), None)
+ tag = tag[3:]
+ def select(context, result):
+ for elem in result:
+ el_tag = elem.tag
+ if el_tag == tag or _isinstance(el_tag, _str) and el_tag[no_ns] == suffix:
+ yield elem
+ elif tag[-2:] == '}*':
+ # Any tag in the given namespace.
+ ns = tag[:-1]
+ ns_only = slice(None, len(ns))
+ def select(context, result):
+ for elem in result:
+ el_tag = elem.tag
+ if _isinstance(el_tag, _str) and el_tag[ns_only] == ns:
+ yield elem
+ else:
+ raise RuntimeError(f"internal parser error, got {tag}")
+ return select
+
+
def prepare_child(next, token):
tag = token[1]
- if _is_wildcard_tag(tag):
- select_tag = _prepare_tag(tag)
- def select(context, result):
- def select_child(result):
- for elem in result:
- yield from elem
- return select_tag(context, select_child(result))
- else:
- if tag[:2] == '{}':
- tag = tag[2:] # '{}tag' == 'tag'
- def select(context, result):
- for elem in result:
- for e in elem:
- if e.tag == tag:
- yield e
+ if _is_wildcard_tag(tag):
+ select_tag = _prepare_tag(tag)
+ def select(context, result):
+ def select_child(result):
+ for elem in result:
+ yield from elem
+ return select_tag(context, select_child(result))
+ else:
+ if tag[:2] == '{}':
+ tag = tag[2:] # '{}tag' == 'tag'
+ def select(context, result):
+ for elem in result:
+ for e in elem:
+ if e.tag == tag:
+ yield e
return select
def prepare_star(next, token):
@@ -190,24 +190,24 @@ def prepare_descendant(next, token):
tag = token[1]
else:
raise SyntaxError("invalid descendant")
-
- if _is_wildcard_tag(tag):
- select_tag = _prepare_tag(tag)
- def select(context, result):
- def select_child(result):
- for elem in result:
- for e in elem.iter():
- if e is not elem:
- yield e
- return select_tag(context, select_child(result))
- else:
- if tag[:2] == '{}':
- tag = tag[2:] # '{}tag' == 'tag'
- def select(context, result):
- for elem in result:
- for e in elem.iter(tag):
- if e is not elem:
- yield e
+
+ if _is_wildcard_tag(tag):
+ select_tag = _prepare_tag(tag)
+ def select(context, result):
+ def select_child(result):
+ for elem in result:
+ for e in elem.iter():
+ if e is not elem:
+ yield e
+ return select_tag(context, select_child(result))
+ else:
+ if tag[:2] == '{}':
+ tag = tag[2:] # '{}tag' == 'tag'
+ def select(context, result):
+ for elem in result:
+ for e in elem.iter(tag):
+ if e is not elem:
+ yield e
return select
def prepare_parent(next, token):
@@ -345,11 +345,11 @@ def iterfind(elem, path, namespaces=None):
# compile selector pattern
if path[-1:] == "/":
path = path + "*" # implicit all (FIXME: keep this?)
-
- cache_key = (path,)
- if namespaces:
- cache_key += tuple(sorted(namespaces.items()))
-
+
+ cache_key = (path,)
+ if namespaces:
+ cache_key += tuple(sorted(namespaces.items()))
+
try:
selector = _cache[cache_key]
except KeyError: