[pypy-svn] r38697 - in pypy/dist/pypy/module: _sre _sre/test mmap/test

arigo at codespeak.net arigo at codespeak.net
Tue Feb 13 15:03:03 CET 2007


Author: arigo
Date: Tue Feb 13 15:03:00 2007
New Revision: 38697

Modified:
   pypy/dist/pypy/module/_sre/interp_sre.py
   pypy/dist/pypy/module/_sre/test/test_app_sre.py
   pypy/dist/pypy/module/mmap/test/test_mmap.py
Log:
Some minimal type-checking on the object that we pass to sre:
it should be a "sequence" object, at least.


Modified: pypy/dist/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/interp_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/interp_sre.py	Tue Feb 13 15:03:00 2007
@@ -161,6 +161,11 @@
     def unwrap_object(self):
         # cannot unwrap in the general case
         space = self.space
+        # some type-checking
+        if (space.lookup(self.w_string, '__getitem__') is None or
+            space.lookup(self.w_string, 'keys') is not None):
+            msg = "string or sequence of characters expected"
+            raise OperationError(space.w_TypeError, space.wrap(msg))
         return space.int_w(space.len(self.w_string))
 
     def get_char_ord(self, p):

Modified: pypy/dist/pypy/module/_sre/test/test_app_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/test/test_app_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/test/test_app_sre.py	Tue Feb 13 15:03:00 2007
@@ -229,6 +229,11 @@
                                           'braced': None,
                                           'invalid': ''}
 
+    def test_sub_typecheck(self):
+        import re
+        KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
+        raises(TypeError, KEYCRE.sub, "hello", {"%(": 1})
+
 
 class AppTestSreScanner:
 

Modified: pypy/dist/pypy/module/mmap/test/test_mmap.py
==============================================================================
--- pypy/dist/pypy/module/mmap/test/test_mmap.py	(original)
+++ pypy/dist/pypy/module/mmap/test/test_mmap.py	Tue Feb 13 15:03:00 2007
@@ -419,6 +419,17 @@
 #         m = mmap(self.f.fileno(), 6)
 #         assert m[-3:7] == "bar"
 # 
+
+    def test_sequence_type(self):
+        from mmap import mmap
+        f = open(self.tmpname + "x", "w+")
+        f.write("foobar")
+        f.flush()
+        m = mmap(f.fileno(), 6)
+        import operator
+        assert operator.isSequenceType(m)
+        assert not operator.isMappingType(m)
+
     def test_all(self):
         # this is a global test, ported from test_mmap.py
         import mmap



More information about the Pypy-commit mailing list