[pypy-svn] r38644 - in pypy/dist/pypy: module/_sre/test rlib/rsre
arigo at codespeak.net
arigo at codespeak.net
Mon Feb 12 22:35:48 CET 2007
Author: arigo
Date: Mon Feb 12 22:35:46 2007
New Revision: 38644
Modified:
pypy/dist/pypy/module/_sre/test/test_app_sre.py
pypy/dist/pypy/rlib/rsre/rsre_core.py
Log:
Fix bug in sre: missing normalization phase done by CPython during
the conversion from state->marks to match->marks.
Modified: pypy/dist/pypy/module/_sre/test/test_app_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/test/test_app_sre.py (original)
+++ pypy/dist/pypy/module/_sre/test/test_app_sre.py Mon Feb 12 22:35:46 2007
@@ -194,6 +194,31 @@
m = re.match('hel+', a)
assert m.end() == 4
+ def test_group_bug(self):
+ import re
+ r = re.compile(r"""
+ \&(?:
+ (?P<escaped>\&) |
+ (?P<named>[_a-z][_a-z0-9]*) |
+ {(?P<braced>[_a-z][_a-z0-9]*)} |
+ (?P<invalid>)
+ )
+ """, re.IGNORECASE | re.VERBOSE)
+ matches = list(r.finditer('this &gift is for &{who} &&'))
+ assert len(matches) == 3
+ assert matches[0].groupdict() == {'escaped': None,
+ 'named': 'gift',
+ 'braced': None,
+ 'invalid': None}
+ assert matches[1].groupdict() == {'escaped': None,
+ 'named': None,
+ 'braced': 'who',
+ 'invalid': None}
+ assert matches[2].groupdict() == {'escaped': '&',
+ 'named': None,
+ 'braced': None,
+ 'invalid': None}
+
class AppTestSreScanner:
Modified: pypy/dist/pypy/rlib/rsre/rsre_core.py
==============================================================================
--- pypy/dist/pypy/rlib/rsre/rsre_core.py (original)
+++ pypy/dist/pypy/rlib/rsre/rsre_core.py Mon Feb 12 22:35:46 2007
@@ -37,11 +37,14 @@
regs = [(self.start, self.string_position)]
for group in range(group_count):
mark_index = 2 * group
+ start = end = -1
if mark_index + 1 < len(self.marks):
- regs.append((self.marks[mark_index],
- self.marks[mark_index + 1]))
- else:
- regs.append((-1, -1))
+ start1 = self.marks[mark_index]
+ end1 = self.marks[mark_index + 1]
+ if start1 >= 0 and end1 >= 0:
+ start = start1
+ end = end1
+ regs.append((start, end))
return regs
def set_mark(self, mark_nr, position):
More information about the Pypy-commit
mailing list