[pypy-commit] pypy stdlib-2.7.9: test/fix re.match.group accepting long

bdkearns noreply at buildbot.pypy.org
Mon Dec 15 23:50:23 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.9
Changeset: r74950:ab9dcc40fcf4
Date: 2014-12-15 17:49 -0500
http://bitbucket.org/pypy/pypy/changeset/ab9dcc40fcf4/

Log:	test/fix re.match.group accepting long

diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -415,7 +415,8 @@
         try:
             groupnum = space.int_w(w_arg)
         except OperationError, e:
-            if not e.match(space, space.w_TypeError):
+            if not e.match(space, space.w_TypeError) and \
+                    not e.match(space, space.w_OverflowError):
                 raise
             try:
                 w_groupnum = space.getitem(self.srepat.w_groupindex, w_arg)
diff --git a/pypy/module/_sre/test/test_app_sre.py b/pypy/module/_sre/test/test_app_sre.py
--- a/pypy/module/_sre/test/test_app_sre.py
+++ b/pypy/module/_sre/test/test_app_sre.py
@@ -191,6 +191,13 @@
         raises(IndexError, m.group, 'foobarbaz')
         raises(IndexError, m.group, 'first', 'foobarbaz')
 
+    def test_group_takes_long(self):
+        import re
+        import sys
+        assert re.match("(foo)", "foo").group(1L) == "foo"
+        exc = raises(IndexError, re.match("", "").group, sys.maxint + 1)
+        assert str(exc.value) == "no such group"
+
     def test_expand(self):
         import re
         m = re.search("a(..)(?P<name>..)", "ab1bc")


More information about the pypy-commit mailing list