Commits

Brian Kearns  committed c0ea2f3 Merge

merge heads

  • Participants
  • Parent commits 6b10ac9, 37e8795
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/module/_sre/interp_sre.py

         if endpos < pos: endpos = pos
         if space.is_true(space.isinstance(w_string, space.w_unicode)):
             unicodestr = space.unicode_w(w_string)
-            if not space.isinstance_w(self.w_pattern, space.w_unicode):
+            if not (space.is_none(self.w_pattern) or
+                    space.isinstance_w(self.w_pattern, space.w_unicode)):
                 raise OperationError(space.w_TypeError, space.wrap(
                         "can't use a string pattern on a bytes-like object"))
             if pos > len(unicodestr): pos = len(unicodestr)
                                                  pos, endpos, self.flags)
         else:
             str = space.bufferstr_w(w_string)
-            if space.isinstance_w(self.w_pattern, space.w_unicode):
+            if (not space.is_none(self.w_pattern) and
+                space.isinstance_w(self.w_pattern, space.w_unicode)):
                 raise OperationError(space.w_TypeError, space.wrap(
                         "can't use a bytes pattern on a string-like object"))
             if pos > len(str): pos = len(str)
     w_srepat = space.allocate_instance(W_SRE_Pattern, w_subtype)
     srepat = space.interp_w(W_SRE_Pattern, w_srepat)
     srepat.space = space
+    # Type check
+    if not (space.is_none(w_pattern) or
+            space.isinstance_w(w_pattern, space.w_unicode)):
+        space.bufferstr_w(w_pattern)
     srepat.w_pattern = w_pattern      # the original uncompiled pattern
     srepat.flags = flags
     srepat.code = code

File pypy/module/_sre/test/test_app_sre.py

         import re, _weakref
         _weakref.ref(re.compile(r""))
 
+    def test_pattern_check(self):
+        import _sre
+        raises(TypeError, _sre.compile, {}, 0, [])
+
 
 class AppTestSreMatch:
     spaceconfig = dict(usemodules=('array',))
         assert ("bla", "") == (p.search().group(0), p.search().group(0))
         assert None == p.search()
 
+    def test_no_pattern(self):
+        import sre_compile, sre_parse
+        sre_pattern = sre_compile.compile(
+            sre_parse.SubPattern(sre_parse.Pattern()))
+        assert sre_pattern.scanner('s') is not None
+
 
 class AppTestGetlower:
     spaceconfig = dict(usemodules=('_locale',))