[pypy-commit] pypy py3.5: hg merge py3k

arigo pypy.commits at gmail.com
Mon Aug 29 10:16:53 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r86698:a513e5ef114e
Date: 2016-08-29 16:14 +0200
http://bitbucket.org/pypy/pypy/changeset/a513e5ef114e/

Log:	hg merge py3k

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
@@ -52,7 +52,6 @@
 SRE_INFO_CHARSET = 4
 SRE_FLAG_LOCALE = 4 # honour system locale
 SRE_FLAG_UNICODE = 32 # use unicode locale
-SRE_FLAG_FULLMATCH = 0x4000   # PyPy extension, for CPython >= 3.4
 
 
 def getlower(char_ord, flags):
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
@@ -89,6 +89,7 @@
     match_end = 0
     match_marks = None
     match_marks_flat = None
+    fullmatch_only = False
 
     def __init__(self, pattern, match_start, end, flags):
         # 'match_start' and 'end' must be known to be non-negative
@@ -527,7 +528,7 @@
             return
 
         elif op == OPCODE_SUCCESS:
-            if ctx.flags & rsre_char.SRE_FLAG_FULLMATCH:
+            if ctx.fullmatch_only:
                 if ptr != ctx.end:
                     return     # not a full match
             ctx.match_end = ptr
@@ -558,7 +559,11 @@
             # assert subpattern
             # <ASSERT> <0=skip> <1=back> <pattern>
             ptr1 = ptr - ctx.pat(ppos+1)
-            if ptr1 < 0 or sre_match(ctx, ppos + 2, ptr1, marks) is None:
+            saved = ctx.fullmatch_only
+            ctx.fullmatch_only = False
+            stop = ptr1 < 0 or sre_match(ctx, ppos + 2, ptr1, marks) is None
+            ctx.fullmatch_only = saved
+            if stop:
                 return
             marks = ctx.match_marks
             ppos += ctx.pat(ppos)
@@ -567,7 +572,12 @@
             # assert not subpattern
             # <ASSERT_NOT> <0=skip> <1=back> <pattern>
             ptr1 = ptr - ctx.pat(ppos+1)
-            if ptr1 >= 0 and sre_match(ctx, ppos + 2, ptr1, marks) is not None:
+            saved = ctx.fullmatch_only
+            ctx.fullmatch_only = False
+            stop = (ptr1 >= 0 and sre_match(ctx, ppos + 2, ptr1, marks)
+                                      is not None)
+            ctx.fullmatch_only = saved
+            if stop:
                 return
             ppos += ctx.pat(ppos)
 
@@ -1006,17 +1016,17 @@
     elif end > length: end = length
     return start, end
 
-def match(pattern, string, start=0, end=sys.maxint, flags=0):
+def match(pattern, string, start=0, end=sys.maxint, flags=0, fullmatch=False):
     start, end = _adjust(start, end, len(string))
     ctx = StrMatchContext(pattern, string, start, end, flags)
+    ctx.fullmatch_only = fullmatch
     if match_context(ctx):
         return ctx
     else:
         return None
 
 def fullmatch(pattern, string, start=0, end=sys.maxint, flags=0):
-    return match(pattern, string, start, end,
-                 flags | rsre_char.SRE_FLAG_FULLMATCH)
+    return match(pattern, string, start, end, flags, fullmatch=True)
 
 def search(pattern, string, start=0, end=sys.maxint, flags=0):
     start, end = _adjust(start, end, len(string))
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
@@ -293,3 +293,9 @@
         r = get_code(r"a((bp)*)c")
         match = rsre_core.fullmatch(r, "abpbpbpc")
         assert match.group(1) == "bpbpbp"
+
+    def test_fullmatch_assertion(self):
+        r = get_code(r"(?=a).b")
+        assert rsre_core.fullmatch(r, "ab")
+        r = get_code(r"(?!a)..")
+        assert not rsre_core.fullmatch(r, "ab")


More information about the pypy-commit mailing list