#27364: fix "incorrect" uses of escape character in the stdlib.
And most of the tools.
Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and
Martin Panter.
diff --git a/Lib/xml/etree/ElementPath.py b/Lib/xml/etree/ElementPath.py
index 5de4232..ab6b79a 100644
--- a/Lib/xml/etree/ElementPath.py
+++ b/Lib/xml/etree/ElementPath.py
@@ -59,15 +59,15 @@
import re
xpath_tokenizer_re = re.compile(
- "("
- "'[^']*'|\"[^\"]*\"|"
- "::|"
- "//?|"
- "\.\.|"
- "\(\)|"
- "[/.*:\[\]\(\)@=])|"
- "((?:\{[^}]+\})?[^/\[\]\(\)@=\s]+)|"
- "\s+"
+ r"("
+ r"'[^']*'|\"[^\"]*\"|"
+ r"::|"
+ r"//?|"
+ r"\.\.|"
+ r"\(\)|"
+ r"[/.*:\[\]\(\)@=])|"
+ r"((?:\{[^}]+\})?[^/\[\]\(\)@=\s]+)|"
+ r"\s+"
)
def xpath_tokenizer(pattern, namespaces=None):
@@ -180,7 +180,7 @@
if elem.get(key) == value:
yield elem
return select
- if signature == "-" and not re.match("\-?\d+$", predicate[0]):
+ if signature == "-" and not re.match(r"\-?\d+$", predicate[0]):
# [tag]
tag = predicate[0]
def select(context, result):
@@ -188,7 +188,7 @@
if elem.find(tag) is not None:
yield elem
return select
- if signature == "-='" and not re.match("\-?\d+$", predicate[0]):
+ if signature == "-='" and not re.match(r"\-?\d+$", predicate[0]):
# [tag='value']
tag = predicate[0]
value = predicate[-1]
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 67b7f2b..4b0c661 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1030,7 +1030,7 @@
ValueError is raised if prefix is reserved or is invalid.
"""
- if re.match("ns\d+$", prefix):
+ if re.match(r"ns\d+$", prefix):
raise ValueError("Prefix format reserved for internal use")
for k, v in list(_namespace_map.items()):
if k == uri or v == prefix: