cpython: e295ad9be16d (original) (raw)

Mercurial > cpython

changeset 94716:e295ad9be16d 3.4

Issues #814253, #9179: Warnings now are raised when group references and conditional group references are used in lookbehind assertions in regular expressions. [#814253]

Serhiy Storchaka storchaka@gmail.com
date Sat, 21 Feb 2015 12:08:52 +0200
parents 4dc8b7ed8973
children a291916333ee 1628484c9408
files Doc/library/re.rst Lib/sre_parse.py Lib/test/test_re.py Misc/NEWS
diffstat 4 files changed, 61 insertions(+), 3 deletions(-)[+] [-] Doc/library/re.rst 7 Lib/sre_parse.py 20 Lib/test/test_re.py 33 Misc/NEWS 4

line wrap: on

line diff

--- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -281,7 +281,9 @@ The special characters are: assertion`. (?<=abc)def will find a match in abcdef, since the lookbehind will back up 3 characters and check if the contained pattern matches. The contained pattern must only match strings of some fixed length, meaning that

(?(id/name)yes-pattern|no-pattern)

--- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -69,6 +69,8 @@ class Pattern: self.open = [] self.groups = 1 self.groupdict = {}

+ def opengroup(self, name=None): gid = self.groups self.groups = gid + 1 @@ -352,6 +354,11 @@ def _escape(source, escape, state): if group < state.groups: if not state.checkgroup(group): raise error("cannot refer to open group")

@@ -630,6 +637,11 @@ def _parse(source, state): if gid is None: msg = "unknown group name: {0!r}".format(name) raise error(msg)

@@ -658,7 +670,10 @@ def _parse(source, state): raise error("syntax error") dir = -1 # lookbehind char = sourceget()

@@ -689,6 +704,11 @@ def _parse(source, state): condgroup = int(condname) except ValueError: raise error("bad character in group name")

--- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -557,7 +557,7 @@ class ReTests(unittest.TestCase): self.assertEqual(re.match("a.*b", "a\n\nb", re.DOTALL).group(0), "a\n\nb")

@@ -571,6 +571,37 @@ class ReTests(unittest.TestCase): self.assertEqual(re.match(r"(a)(?!\s\1)", "a b").group(1), "a") self.assertEqual(re.match(r"(a)(?!\s(abc|a))", "a b").group(1), "a")

+

+ def test_ignore_case(self): self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC") self.assertEqual(re.match(b"abc", b"ABC", re.I).group(0), b"ABC")

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,10 @@ Core and Builtins Library ------- +- Issues #814253, #9179: Warnings now are raised when group references and