diff options
author | Gian Mario Tagliaretti <gianmt@src.gnome.org> | 2008-07-11 19:18:28 +0000 |
---|---|---|
committer | Gian Mario Tagliaretti <gianmt@src.gnome.org> | 2008-07-11 19:18:28 +0000 |
commit | eaca30050adb0730653c8f9f434fedb4ffbf5164 (patch) | |
tree | 07206e5213131b23e9250f3698663c0f28bfd139 | |
parent | 62f5b2f1929142c2a3eacd518da770dabfcc7995 (diff) | |
download | pygobject-eaca30050adb0730653c8f9f434fedb4ffbf5164.tar.gz pygobject-eaca30050adb0730653c8f9f434fedb4ffbf5164.tar.xz pygobject-eaca30050adb0730653c8f9f434fedb4ffbf5164.zip |
wrap File.load_contents with docstrings
svn path=/trunk/; revision=793
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | gio/gfile.override | 47 | ||||
-rw-r--r-- | gio/gio.defs | 46 | ||||
-rw-r--r-- | tests/test_gio.py | 9 |
4 files changed, 91 insertions, 19 deletions
@@ -1,3 +1,11 @@ +2008-07-11 Gian Mario Tagliaretti <gianmt@gnome.org> + + * gio/gfile.override: wrap File.load_contents, fix a typo. + + * gio/gio.defs: Add docstring for File.load_contents. + + * tests/test_gio.py: Add a test for the above method. + 2008-07-09 Juha Sahakangas <voas0113@saunalahti.fi> * gobject/gobjectmodule.c (pyg_io_add_watch): Fix error message diff --git a/gio/gfile.override b/gio/gfile.override index f40271f..b36d9da 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -101,7 +101,7 @@ _wrap_g_file_read_async(PyGObject *self, notify = g_slice_new0(PyGAsyncRequestNotify); if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|iOO:InputStream.read_async", + "O|iOO:File.read_async", kwlist, ¬ify->callback, &io_priority, @@ -142,6 +142,50 @@ _wrap_g_file_read_async(PyGObject *self, Py_INCREF(Py_None); return Py_None; } +%% +override g_file_load_contents kwargs +static PyObject * +_wrap_g_file_load_contents(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "cancellable", NULL }; + GCancellable *cancellable; + PyGObject *pycancellable = NULL; + gchar *contents, *etag_out; + gsize lenght; + GError *error = NULL; + gboolean ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|O:File.load_contents", + kwlist, + &pycancellable)) + return NULL; + + if (pycancellable == NULL || (PyObject*)pycancellable == Py_None) + cancellable = NULL; + else if (pygobject_check(pycancellable, &PyGCancellable_Type)) + cancellable = G_CANCELLABLE(pycancellable->obj); + else { + PyErr_SetString(PyExc_TypeError, + "cancellable should be a gio.Cancellable"); + return NULL; + } + + ret = g_file_load_contents(G_FILE(self->obj), cancellable, + &contents, &lenght, &etag_out, &error); + + if (pyg_error_check(&error)) + return NULL; + + if (ret) + return Py_BuildValue("(sks)", contents, lenght, etag_out); + else { + Py_INCREF(Py_None); + return Py_None; + } +} /* GFile.append_to_async */ /* GFile.create_async */ /* GFile.enumerate_children_async */ @@ -163,7 +207,6 @@ _wrap_g_file_read_async(PyGObject *self, /* GFile.query_writable_namespaces: No ArgType for GFileAttributeInfoList* */ /* GFile.set_attribute: No ArgType for gpointer */ /* GFile.set_attributes_finish: No ArgType for GFileInfo** */ -/* GFile.load_contents: No ArgType for char** */ /* GFile.load_contents_finish: No ArgType for char** */ /* GFile.load_partial_contents_finish: No ArgType for char** */ /* GFile.replace_contents: No ArgType for char** */ diff --git a/gio/gio.defs b/gio/gio.defs index 04b59df..63ebb31 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -1253,17 +1253,18 @@ (define-method read (of-object "GFile") (docstring -"F.read([cancellable]) -> input stream\n" -"Opens a file for reading. The result is a GFileInputStream that can be \n" -"used to read the contents of the file.\n" -"\n" -"If cancellable is specified, then the operation can be cancelled by \n" -"triggering the cancellable object from another thread. If the operation \n" -"was cancelled, the error gio.IO_ERROR_CANCELLED will be returned.\n" -"If the file does not exist, the gio.IO_ERROR_NOT_FOUND error will \n" -"be returned. If the file is a directory, the gio.IO_ERROR_IS_DIRECTORY \n" -"error will be returned. Other errors are possible too, and depend on what \n" -"kind of filesystem the file is on.") + "F.read([cancellable]) -> input stream\n" + "Opens a file for reading. The result is a GFileInputStream that\n" + "can be used to read the contents of the file.\n" + "\n" + "If cancellable is specified, then the operation can be cancelled\n" + "by triggering the cancellable object from another thread. If the\n" + "operation was cancelled, the error gio.IO_ERROR_CANCELLED will\n" + "be returned. If the file does not exist, the gio.IO_ERROR_NOT_FOUND\n" + "error will be returned. If the file is a directory, the\n" + "gio.IO_ERROR_IS_DIRECTORY error will be returned. Other errors\n" + "are possible too, and depend on what kind of filesystem the file is on." + ) (c-name "g_file_read") (return-type "GFileInputStream*") (parameters @@ -1275,12 +1276,14 @@ (define-method read_async (of-object "GFile") (docstring -"F.read_async(callback [,io_priority [,cancellable [,user_data]]]) -> start read\n" -"\n" -"For more details, see gio.File.read() which is the synchronous version of this call.\n" -"Asynchronously opens file for reading." -"When the operation is finished, callback will be called.\n" -"You can then call g_file_read_finish() to get the result of the operation.\n") + "F.read_async(callback [,io_priority [,cancellable [,user_data]]]) -> start read\n" + "\n" + "For more details, see gio.File.read() which is the synchronous\n" + "version of this call. Asynchronously opens file for reading.\n" + "When the operation is finished, callback will be called.\n" + "You can then call g_file_read_finish() to get the result of the\n" + "operation.\n" + ) (c-name "g_file_read_async") (return-type "none") (parameters @@ -1906,6 +1909,15 @@ ) (define-method load_contents + (docstring + "F.load_contents([cancellable]) -> contents, length, etag_out\n\n" + "Loads the content of the file into memory, returning the size of the\n" + "data. The data is always zero terminated, but this is not included\n" + "in the resultant length.\n" + "If cancellable is not None, then the operation can be cancelled by\n" + "triggering the cancellable object from another thread. If the operation\n" + "was cancelled, the error gio.IO_ERROR_CANCELLED will be returned.\n" + ) (of-object "GFile") (c-name "g_file_load_contents") (return-type "gboolean") diff --git a/tests/test_gio.py b/tests/test_gio.py index a21eba7..1b91d2d 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -61,6 +61,15 @@ class TestFile(unittest.TestCase): self.assertRaises(TypeError, gio.File, foo="bar") self.assertRaises(TypeError, gio.File, uri=1) self.assertRaises(TypeError, gio.File, path=1) + + def testLoadContents(self): + self._f.write("testing load_contents") + self._f.seek(0) + c = gio.Cancellable() + cont, leng, etag = self.file.load_contents(cancellable=c) + self.assertEqual(cont, "testing load_contents") + self.assertEqual(leng, 21) + self.assertNotEqual(etag, '') class TestGFileEnumerator(unittest.TestCase): |