diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-05 15:49:26 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-05 15:49:26 (GMT) |
commit | b5d0a215536c0b5b7d100f54aad9968b4760122c (patch) | |
tree | 9ee4def94b695a7b20b8a04f299c2ae74fb1a2ed | |
parent | 60a1d3cd152e9340727409ee48372a7cbc31a16f (diff) | |
download | cpython-b5d0a215536c0b5b7d100f54aad9968b4760122c.zip cpython-b5d0a215536c0b5b7d100f54aad9968b4760122c.tar.gz cpython-b5d0a215536c0b5b7d100f54aad9968b4760122c.tar.bz2 |
Issue #25554: Got rid of circular references in regular expression parsing.
-rw-r--r-- | Lib/sre_parse.py | 12 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
2 files changed, 8 insertions, 6 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 67f84e9..f6a8851 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -70,14 +70,14 @@ class Pattern: def __init__(self): self.flags = 0 self.groupdict = {} - self.subpatterns = [None] # group 0 + self.groupwidths = [None] # group 0 self.lookbehindgroups = None @property def groups(self): - return len(self.subpatterns) + return len(self.groupwidths) def opengroup(self, name=None): gid = self.groups - self.subpatterns.append(None) + self.groupwidths.append(None) if self.groups > MAXGROUPS: raise error("too many groups") if name is not None: @@ -88,9 +88,9 @@ class Pattern: self.groupdict[name] = gid return gid def closegroup(self, gid, p): - self.subpatterns[gid] = p + self.groupwidths[gid] = p.getwidth() def checkgroup(self, gid): - return gid < self.groups and self.subpatterns[gid] is not None + return gid < self.groups and self.groupwidths[gid] is not None def checklookbehindgroup(self, gid, source): if self.lookbehindgroups is not None: @@ -195,7 +195,7 @@ class SubPattern: lo = lo + 1 hi = hi + 1 elif op is GROUPREF: - i, j = self.pattern.subpatterns[av].getwidth() + i, j = self.pattern.groupwidths[av] lo = lo + i hi = hi + j elif op is GROUPREF_EXISTS: @@ -54,6 +54,8 @@ Core and Builtins Library ------- +- Issue #25554: Got rid of circular references in regular expression parsing. + - Issue #25510: fileinput.FileInput.readline() now returns b'' instead of '' at the end if the FileInput was opened with binary mode. Patch by Ryosuke Ito. |