[pypy-svn] r79823 - in pypy/branch/cpyext-darwin/pypy/module/cpyext: . test

danchr at codespeak.net danchr at codespeak.net
Sat Dec 4 20:51:11 CET 2010


Author: danchr
Date: Sat Dec  4 20:51:08 2010
New Revision: 79823

Modified:
   pypy/branch/cpyext-darwin/pypy/module/cpyext/object.py
   pypy/branch/cpyext-darwin/pypy/module/cpyext/stubs.py
   pypy/branch/cpyext-darwin/pypy/module/cpyext/test/test_object.py
Log:
Implement PyFile_Check & PyFile_CheckExact

Modified: pypy/branch/cpyext-darwin/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpyext-darwin/pypy/module/cpyext/object.py	(original)
+++ pypy/branch/cpyext-darwin/pypy/module/cpyext/object.py	Sat Dec  4 20:51:08 2010
@@ -2,12 +2,13 @@
 from pypy.module.cpyext.api import (
     cpython_api, generic_cpy_call, CANNOT_FAIL, Py_ssize_t, Py_ssize_tP,
     PyVarObject, Py_TPFLAGS_HEAPTYPE, Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT,
-    Py_GE, CONST_STRING, FILEP, fwrite)
+    Py_GE, CONST_STRING, FILEP, fwrite, build_type_checkers)
 from pypy.module.cpyext.pyobject import (
     PyObject, PyObjectP, create_ref, from_ref, Py_IncRef, Py_DecRef,
     track_reference, get_typedescr, RefcountState)
 from pypy.module.cpyext.typeobject import PyTypeObjectPtr
 from pypy.module.cpyext.pyerrors import PyErr_NoMemory, PyErr_BadInternalCall
+from pypy.module._file.interp_file import W_File
 from pypy.objspace.std.objectobject import W_ObjectObject
 from pypy.objspace.std.typeobject import W_TypeObject
 from pypy.interpreter.error import OperationError
@@ -428,6 +429,8 @@
         rffi.free_nonmovingbuffer(data, buf)
     return 0
 
+PyFile_Check, PyFile_CheckExact = build_type_checkers("File", W_File)
+
 @cpython_api([CONST_STRING, CONST_STRING], PyObject)
 def PyFile_FromString(space, filename, mode):
     """
@@ -437,4 +440,3 @@
     w_filename = space.wrap(rffi.charp2str(filename))
     w_mode = space.wrap(rffi.charp2str(mode))
     return space.call_method(space.builtin, 'file', w_filename, w_mode)
-

Modified: pypy/branch/cpyext-darwin/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpyext-darwin/pypy/module/cpyext/stubs.py	(original)
+++ pypy/branch/cpyext-darwin/pypy/module/cpyext/stubs.py	Sat Dec  4 20:51:08 2010
@@ -791,21 +791,6 @@
     successful invocation of Py_EnterRecursiveCall()."""
     raise NotImplementedError
 
- at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyFile_Check(space, p):
-    """Return true if its argument is a PyFileObject or a subtype of
-    PyFileObject.
-    
-    Allowed subtypes to be accepted."""
-    raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyFile_CheckExact(space, p):
-    """Return true if its argument is a PyFileObject, but not a subtype of
-    PyFileObject.
-    """
-    raise NotImplementedError
-
 @cpython_api([FILE, rffi.CCHARP, rffi.CCHARP, rffi.INT_real], PyObject)
 def PyFile_FromFile(space, fp, name, mode, close):
     """Create a new PyFileObject from the already-open standard C file

Modified: pypy/branch/cpyext-darwin/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpyext-darwin/pypy/module/cpyext/test/test_object.py	(original)
+++ pypy/branch/cpyext-darwin/pypy/module/cpyext/test/test_object.py	Sat Dec  4 20:51:08 2010
@@ -188,6 +188,10 @@
         rffi.free_charp(filename)
         rffi.free_charp(mode)
 
+        assert api.PyFile_Check(w_file)
+        assert api.PyFile_CheckExact(w_file)
+        assert not api.PyFile_Check(space.wrap("text"))
+
         space.call_method(w_file, "write", space.wrap("text"))
         space.call_method(w_file, "close")
         assert (udir / "_test_file").read() == "text"



More information about the Pypy-commit mailing list