[pypy-svn] r74775 - in pypy/trunk/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Wed May 26 16:20:40 CEST 2010
Author: afa
Date: Wed May 26 16:20:38 2010
New Revision: 74775
Modified:
pypy/trunk/pypy/module/cpyext/object.py
pypy/trunk/pypy/module/cpyext/test/test_object.py
Log:
add PyFile_FromString()
Modified: pypy/trunk/pypy/module/cpyext/object.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/object.py (original)
+++ pypy/trunk/pypy/module/cpyext/object.py Wed May 26 16:20:38 2010
@@ -413,3 +413,13 @@
rffi.free_nonmovingbuffer(data, buf)
return 0
+ at cpython_api([CONST_STRING, CONST_STRING], PyObject)
+def PyFile_FromString(space, filename, mode):
+ """
+ On success, return a new file object that is opened on the file given by
+ filename, with a file mode given by mode, where mode has the same
+ semantics as the standard C routine fopen(). On failure, return NULL."""
+ 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/trunk/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_object.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_object.py Wed May 26 16:20:38 2010
@@ -192,6 +192,17 @@
assert api.PyObject_Unicode(space.wrap("\xe9")) is None
api.PyErr_Clear()
+ def test_file_fromstring(self, space, api):
+ filename = rffi.str2charp(str(udir / "_test_file"))
+ mode = rffi.str2charp("wb")
+ w_file = api.PyFile_FromString(filename, mode)
+ rffi.free_charp(filename)
+ rffi.free_charp(mode)
+
+ space.call_method(w_file, "write", space.wrap("text"))
+ space.call_method(w_file, "close")
+ assert (udir / "_test_file").read() == "text"
+
class AppTestObjectPrint(AppTestCpythonExtensionBase):
def setup_class(cls):
AppTestCpythonExtensionBase.setup_class.im_func(cls)
More information about the Pypy-commit
mailing list