summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/sre_compile.py8
-rw-r--r--Lib/sre_parse.py2
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index e5c501e..36986eb 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -298,8 +298,14 @@ def compile(p, flags=0):
assert p.pattern.groups <= 100,\
"sorry, but this version only supports 100 named groups"
+ # map in either direction
+ groupindex = p.pattern.groupdict
+ indexgroup = [None] * p.pattern.groups
+ for k, i in groupindex.items():
+ indexgroup[i] = k
+
return _sre.compile(
pattern, flags,
array.array(WORDSIZE, code).tostring(),
- p.pattern.groups-1, p.pattern.groupdict
+ p.pattern.groups-1, groupindex, indexgroup
)
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 81ca217..d78737f 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -515,6 +515,8 @@ def _parse(source, state):
group = state.getgroup(name)
while 1:
p = _parse(source, state)
+ if group is not None:
+ p.append((INDEX, group))
if source.match(")"):
if b:
b.append(p)