summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-04-10 09:59:16 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-04-10 09:59:16 (GMT)
commit88fdeb45ef86385b5ac212929fbbf69711f9245a (patch)
treeb47ec89f01df6c7ce0518ad8fe5e261f4694fec6 /Lib
parent344d26c7a08896a1eb54f638e80de0d0fadfad39 (diff)
downloadcpython-88fdeb45ef86385b5ac212929fbbf69711f9245a.zip
cpython-88fdeb45ef86385b5ac212929fbbf69711f9245a.tar.gz
cpython-88fdeb45ef86385b5ac212929fbbf69711f9245a.tar.bz2
#2650: re.escape() no longer escapes the "_".
Diffstat (limited to 'Lib')
-rw-r--r--Lib/re.py8
-rw-r--r--Lib/test/test_re.py4
2 files changed, 7 insertions, 5 deletions
diff --git a/Lib/re.py b/Lib/re.py
index abd7ea2..cdf5976 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -215,12 +215,14 @@ def template(pattern, flags=0):
return _compile(pattern, flags|T)
_alphanum_str = frozenset(
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
+ "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
_alphanum_bytes = frozenset(
- b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
+ b"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
def escape(pattern):
- "Escape all non-alphanumeric characters in pattern."
+ """
+ Escape all the characters in pattern except ASCII letters, numbers and '_'.
+ """
if isinstance(pattern, str):
alphanum = _alphanum_str
s = list(pattern)
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index fe8bc34..e3d10f7 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -428,7 +428,7 @@ class ReTests(unittest.TestCase):
self.assertEqual(m.span(), span)
def test_re_escape(self):
- alnum_chars = string.ascii_letters + string.digits
+ alnum_chars = string.ascii_letters + string.digits + '_'
p = ''.join(chr(i) for i in range(256))
for c in p:
if c in alnum_chars:
@@ -441,7 +441,7 @@ class ReTests(unittest.TestCase):
self.assertMatch(re.escape(p), p)
def test_re_escape_byte(self):
- alnum_chars = (string.ascii_letters + string.digits).encode('ascii')
+ alnum_chars = (string.ascii_letters + string.digits + '_').encode('ascii')
p = bytes(range(256))
for i in p:
b = bytes([i])