[pypy-svn] r73545 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

jandem at codespeak.net jandem at codespeak.net
Thu Apr 8 14:59:36 CEST 2010


Author: jandem
Date: Thu Apr  8 14:59:35 2010
New Revision: 73545

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/number.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_number.py
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
Log:
add PyIndex_Check


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	Thu Apr  8 14:59:35 2010
@@ -54,6 +54,7 @@
 import pypy.module.cpyext.unicodeobject
 import pypy.module.cpyext.pycobject
 import pypy.module.cpyext.sysmodule
+import pypy.module.cpyext.number
 
 # now that all rffi_platform.Struct types are registered, configure them
 api.configure_types()

Added: pypy/branch/cpython-extension/pypy/module/cpyext/number.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/number.py	Thu Apr  8 14:59:35 2010
@@ -0,0 +1,15 @@
+from pypy.interpreter.error import OperationError
+from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL
+from pypy.module.cpyext.pyobject import PyObject
+from pypy.rpython.lltypesystem import rffi, lltype
+
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyIndex_Check(space, w_obj):
+    """Returns True if o is an index integer (has the nb_index slot of the
+    tp_as_number structure filled in).
+    """
+    try:
+        space.index(w_obj)
+        return 1
+    except OperationError:
+        return 0

Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_number.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_number.py	Thu Apr  8 14:59:35 2010
@@ -0,0 +1,9 @@
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.interpreter.error import OperationError
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext import sequence
+
+class TestIterator(BaseApiTest):
+    def test_index(self, space, api):
+        assert api.PyIndex_Check(space.wrap(12))
+        assert not api.PyIndex_Check(space.wrap('12'))



More information about the Pypy-commit mailing list