Author: Armin Rigo <[email protected]>
Branch: stdlib-2.7.5
Changeset: r68897:bfa0306f27f6
Date: 2014-01-24 09:40 +0100
http://bitbucket.org/pypy/pypy/changeset/bfa0306f27f6/
Log: Finish fixing rsre in this branch according to 7b0cafed5689.
diff --git a/rpython/rlib/rsre/rpy/__init__.py
b/rpython/rlib/rsre/rpy/__init__.py
--- a/rpython/rlib/rsre/rpy/__init__.py
+++ b/rpython/rlib/rsre/rpy/__init__.py
@@ -1,1 +1,1 @@
-from ._sre import get_code
+from ._sre import get_code, VERSION
diff --git a/rpython/rlib/rsre/rpy/_sre.py b/rpython/rlib/rsre/rpy/_sre.py
--- a/rpython/rlib/rsre/rpy/_sre.py
+++ b/rpython/rlib/rsre/rpy/_sre.py
@@ -1,9 +1,10 @@
-
+import sys
from rpython.rlib.rsre import rsre_char
from rpython.rlib.rarithmetic import intmask
-
+VERSION = "2.7.5"
MAGIC = 20031017
+MAXREPEAT = rsre_char.MAXREPEAT
CODESIZE = rsre_char.CODESIZE
getlower = rsre_char.getlower
diff --git a/rpython/rlib/rsre/rpy/sre_compile.py
b/rpython/rlib/rsre/rpy/sre_compile.py
--- a/rpython/rlib/rsre/rpy/sre_compile.py
+++ b/rpython/rlib/rsre/rpy/sre_compile.py
@@ -8,12 +8,12 @@
# See the sre.py file for information on usage and redistribution.
#
-"""Internal support module for sre (copied from CPython 2.7.3)"""
+"""Internal support module for sre (copied from CPython 2.7.5)"""
import sys
from . import _sre, sre_parse
from .sre_constants import *
-from _sre import MAXREPEAT
+from ._sre import MAXREPEAT
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
diff --git a/rpython/rlib/rsre/rpy/sre_constants.py
b/rpython/rlib/rsre/rpy/sre_constants.py
--- a/rpython/rlib/rsre/rpy/sre_constants.py
+++ b/rpython/rlib/rsre/rpy/sre_constants.py
@@ -9,13 +9,13 @@
# See the sre.py file for information on usage and redistribution.
#
-"""Internal support module for sre (copied from CPython 2.7.3)"""
+"""Internal support module for sre (copied from CPython 2.7.5)"""
# update when constants are added or removed
MAGIC = 20031017
-from _sre import MAXREPEAT
+from ._sre import MAXREPEAT
# SRE standard exception (access as sre.error)
# (use the real re.error exception class)
diff --git a/rpython/rlib/rsre/rpy/sre_parse.py
b/rpython/rlib/rsre/rpy/sre_parse.py
--- a/rpython/rlib/rsre/rpy/sre_parse.py
+++ b/rpython/rlib/rsre/rpy/sre_parse.py
@@ -8,14 +8,14 @@
# See the sre.py file for information on usage and redistribution.
#
-"""Internal support module for sre (copied from CPython 2.7.3)"""
+"""Internal support module for sre (copied from CPython 2.7.5)"""
# XXX: show string offset and offending character for all errors
import sys
from .sre_constants import *
-from _sre import MAXREPEAT
+from ._sre import MAXREPEAT
SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{"
diff --git a/rpython/rlib/rsre/rsre_char.py b/rpython/rlib/rsre/rsre_char.py
--- a/rpython/rlib/rsre/rsre_char.py
+++ b/rpython/rlib/rsre/rsre_char.py
@@ -5,7 +5,7 @@
from rpython.rlib.rlocale import tolower, isalnum
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib import jit
-from rpython.rlib.rarithmetic import int_between
+from rpython.rlib.rarithmetic import int_between, intmask
# Note: the unicode parts of this module require you to call
# rsre_char.set_unicode_db() first, to select one of the modules
@@ -26,7 +26,10 @@
# Identifying as _sre from Python 2.3 and onwards (at least up to 2.7)
MAGIC = 20031017
-MAXREPEAT = 65535
+if sys.maxint > 2**32:
+ MAXREPEAT = intmask(2**32 - 1)
+else:
+ MAXREPEAT = intmask(2**31 - 1)
# In _sre.c this is bytesize of the code word type of the C implementation.
# There it's 2 for normal Python builds and more for wide unicode builds
(large
diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py
--- a/rpython/rlib/rsre/rsre_core.py
+++ b/rpython/rlib/rsre/rsre_core.py
@@ -95,6 +95,10 @@
self.match_start = match_start
self.end = end
self.flags = flags
+ # check we don't get the old value of MAXREPEAT
+ # during the untranslated tests
+ if not we_are_translated():
+ assert 65535 not in pattern
def reset(self, start):
self.match_start = start
diff --git a/rpython/rlib/rsre/test/targetrsre.py
b/rpython/rlib/rsre/test/targetrsre.py
--- a/rpython/rlib/rsre/test/targetrsre.py
+++ b/rpython/rlib/rsre/test/targetrsre.py
@@ -1,14 +1,15 @@
#!/usr/bin/env python
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.rsre import rsre_core
+from rpython.rlib.rsre.rsre_char import MAXREPEAT
import os, time
# <item>\s*<title>(.*?)</title>
r_code1 = [17, 18, 1, 21, 131091, 6, 6, 60, 105, 116, 101, 109, 62, 0,
0, 0, 0, 0, 0, 19, 60, 19, 105, 19, 116, 19, 101, 19, 109, 19, 62, 29,
-9, 0, 65535, 15, 4, 9, 2, 0, 1, 19, 60, 19, 116, 19, 105, 19, 116, 19,
-108, 19, 101, 19, 62, 21, 0, 31, 5, 0, 65535, 2, 1, 21, 1, 19, 60, 19,
+9, 0, MAXREPEAT, 15, 4, 9, 2, 0, 1, 19, 60, 19, 116, 19, 105, 19, 116, 19,
+108, 19, 101, 19, 62, 21, 0, 31, 5, 0, MAXREPEAT, 2, 1, 21, 1, 19, 60, 19,
47, 19, 116, 19, 105, 19, 116, 19, 108, 19, 101, 19, 62, 1]
diff --git a/rpython/rlib/rsre/test/test_match.py
b/rpython/rlib/rsre/test/test_match.py
--- a/rpython/rlib/rsre/test/test_match.py
+++ b/rpython/rlib/rsre/test/test_match.py
@@ -1,6 +1,6 @@
-import re, random
+import re, random, py
from rpython.rlib.rsre import rsre_core
-from rpython.rlib.rsre.rpy import get_code
+from rpython.rlib.rsre.rpy import get_code, VERSION
def get_code_and_re(regexp):
@@ -239,6 +239,9 @@
assert rsre_core.match(r, "x")
def test_match_bug3(self):
+ if VERSION == "2.7.5":
+ py.test.skip("pattern fails to compile with exactly 2.7.5 "
+ "(works on 2.7.3 and on 2.7.trunk though)")
r = get_code(r'([ax]*?x*)?$')
assert rsre_core.match(r, "aaxaa")
@@ -257,3 +260,10 @@
assert res is not None
else:
assert res is None
+
+ def test_simple_match_1(self):
+ r = get_code(r"ab*bbbbbbbc")
+ print r
+ match = rsre_core.match(r, "abbbbbbbbbcdef")
+ assert match
+ assert match.match_end == 11
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit