commit | author | age
|
71084d
|
1 |
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py |
CS |
2 |
index 7cda2b6..15d2324 100644 |
|
3 |
--- a/Lib/sre_compile.py |
|
4 |
+++ b/Lib/sre_compile.py |
|
5 |
@@ -355,8 +355,6 @@ def _optimize_unicode(charset, fixup): |
|
6 |
def _simple(av): |
|
7 |
# check if av is a "simple" operator |
|
8 |
lo, hi = av[2].getwidth() |
|
9 |
- if lo == 0 and hi == MAXREPEAT: |
|
10 |
- raise error, "nothing to repeat" |
|
11 |
return lo == hi == 1 and av[2][0][0] != SUBPATTERN |
|
12 |
|
|
13 |
def _compile_info(code, pattern, flags): |
|
14 |
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py |
|
15 |
index 75f8c96..644441d 100644 |
|
16 |
--- a/Lib/sre_parse.py |
|
17 |
+++ b/Lib/sre_parse.py |
|
18 |
@@ -147,7 +147,7 @@ class SubPattern: |
|
19 |
REPEATCODES = (MIN_REPEAT, MAX_REPEAT) |
|
20 |
for op, av in self.data: |
|
21 |
if op is BRANCH: |
|
22 |
- i = sys.maxint |
|
23 |
+ i = MAXREPEAT - 1 |
|
24 |
j = 0 |
|
25 |
for av in av[1]: |
|
26 |
l, h = av.getwidth() |
|
27 |
@@ -165,14 +165,14 @@ class SubPattern: |
|
28 |
hi = hi + j |
|
29 |
elif op in REPEATCODES: |
|
30 |
i, j = av[2].getwidth() |
|
31 |
- lo = lo + long(i) * av[0] |
|
32 |
- hi = hi + long(j) * av[1] |
|
33 |
+ lo = lo + i * av[0] |
|
34 |
+ hi = hi + j * av[1] |
|
35 |
elif op in UNITCODES: |
|
36 |
lo = lo + 1 |
|
37 |
hi = hi + 1 |
|
38 |
elif op == SUCCESS: |
|
39 |
break |
|
40 |
- self.width = int(min(lo, sys.maxint)), int(min(hi, sys.maxint)) |
|
41 |
+ self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT) |
|
42 |
return self.width |
|
43 |
|
|
44 |
class Tokenizer: |
|
45 |
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py |
|
46 |
index 18a81a2..f0827d8 100644 |
|
47 |
--- a/Lib/test/test_re.py |
|
48 |
+++ b/Lib/test/test_re.py |
|
49 |
@@ -897,6 +897,17 @@ class ReTests(unittest.TestCase): |
|
50 |
with self.assertRaisesRegexp(sre_constants.error, '\?foo'): |
|
51 |
re.compile('(?P<?foo>)') |
|
52 |
|
|
53 |
+ def test_bug_2537(self): |
|
54 |
+ # issue 2537: empty submatches |
|
55 |
+ for outer_op in ('{0,}', '*', '+', '{1,187}'): |
|
56 |
+ for inner_op in ('{0,}', '*', '?'): |
|
57 |
+ r = re.compile("^((x|y)%s)%s" % (inner_op, outer_op)) |
|
58 |
+ m = r.match("xyyzy") |
|
59 |
+ self.assertEqual(m.group(0), "xyy") |
|
60 |
+ self.assertEqual(m.group(1), "") |
|
61 |
+ self.assertEqual(m.group(2), "y") |
|
62 |
+ |
|
63 |
+ |
|
64 |
|
|
65 |
def run_re_tests(): |
|
66 |
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR |
|
67 |
diff --git a/Lib/doctest.py b/Lib/doctest.py |
|
68 |
index 90bcca1..0ee40a2 100644 |
|
69 |
--- a/Lib/doctest.py |
|
70 |
+++ b/Lib/doctest.py |
|
71 |
@@ -564,7 +564,7 @@ class DocTestParser: |
|
72 |
# Want consists of any non-blank lines that do not start with PS1. |
|
73 |
(?P<want> (?:(?![ ]*$) # Not a blank line |
|
74 |
(?![ ]*>>>) # Not a line starting with PS1 |
|
75 |
- .*$\n? # But any other line |
|
76 |
+ .+$\n? # But any other line |
|
77 |
)*) |
|
78 |
''', re.MULTILINE | re.VERBOSE) |
|
79 |
|
|
80 |
|