summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGian Mario Tagliaretti <gianmt@src.gnome.org>2008-07-14 21:47:31 +0000
committerGian Mario Tagliaretti <gianmt@src.gnome.org>2008-07-14 21:47:31 +0000
commitd0aaac8f4c57bb759712936a8d612f826fd87fde (patch)
treeea6b5010fe249a5b250f79f8a737be5765d7b9aa
parent0220bbda1afbfb2b8e9abe1ff07b193a49cbb4d8 (diff)
downloadpygobject-d0aaac8f4c57bb759712936a8d612f826fd87fde.tar.gz
pygobject-d0aaac8f4c57bb759712936a8d612f826fd87fde.tar.xz
pygobject-d0aaac8f4c57bb759712936a8d612f826fd87fde.zip
wrap File.load_contents_async and File.load_contents_finish with docsstrings and a test
svn path=/trunk/; revision=802
-rw-r--r--ChangeLog9
-rw-r--r--gio/gfile.override74
-rw-r--r--gio/gio.defs19
-rw-r--r--tests/test_gio.py20
4 files changed, 119 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 013f681..f3259af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-07-14 Gian Mario Tagliaretti <gianmt@gnome.org>
+
+ * gio/gfile.override: wrap File.load_contents_async and
+ File.load_contents_finish
+
+ * gio/gio.defs: Add docstring for the above methods.
+
+ * tests/test_gio.py: Add a test for the above methods.
+
2008-07-14 Johan Dahlin <johan@gnome.org>
Bug 487523 – Add xslfiles variable to .pc.in files
diff --git a/gio/gfile.override b/gio/gfile.override
index a9c4a33..49b12aa 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -170,12 +170,83 @@ _wrap_g_file_load_contents(PyGObject *self,
return Py_None;
}
}
+%%
+override g_file_load_contents_async kwargs
+static PyObject *
+_wrap_g_file_load_contents_async(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
+ GCancellable *cancellable;
+ PyGObject *pycancellable = NULL;
+ PyGAsyncRequestNotify *notify;
+
+ notify = g_slice_new0(PyGAsyncRequestNotify);
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O|OO:File.load_contents_async",
+ kwlist,
+ &notify->callback,
+ &pycancellable,
+ &notify->data))
+
+ {
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
+
+ g_file_load_contents_async(G_FILE(self->obj),
+ cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+%%
+override g_file_load_contents_finish kwargs
+static PyObject *
+_wrap_g_file_load_contents_finish(PyGObject *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "res", NULL };
+ PyGObject *res;
+ gchar *contents, *etag_out;
+ gsize lenght;
+ GError *error = NULL;
+ gboolean ret;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!:File.load_contents_finish",
+ kwlist,
+ &PyGAsyncResult_Type,
+ &res))
+ return NULL;
+
+ ret = g_file_load_contents_finish(G_FILE(self->obj),
+ G_ASYNC_RESULT(res->obj), &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 */
/* GFile.eject_mountable */
/* GFile.find_enclosing_mount_async */
-/* GFile.load_contents_async */
/* GFile.mount_enclosing_volume */
/* GFile.mount_mountable */
/* GFile.query_info_async */
@@ -191,7 +262,6 @@ _wrap_g_file_load_contents(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_finish: No ArgType for char** */
/* GFile.load_partial_contents_finish: No ArgType for char** */
/* GFile.replace_contents: No ArgType for char** */
/* GFile.replace_contents_finish: No ArgType for char** */
diff --git a/gio/gio.defs b/gio/gio.defs
index ba6700a..49fc12b 100644
--- a/gio/gio.defs
+++ b/gio/gio.defs
@@ -1931,6 +1931,18 @@
)
(define-method load_contents_async
+ (docstring
+ "F.load_contents_async(callback, [cancellable, [user_data]])->start loading\n\n"
+ "Starts an asynchronous load of the file's contents.\n\n"
+ "For more details, see F.load_contents() which is the synchronous\n"
+ "version of this call.\n\n"
+ "When the load operation has completed, callback will be called with\n"
+ "user data. To finish the operation, call F.load_contents_finish() with\n"
+ "the parameter 'res' returned by the callback.\n\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_async")
(return-type "none")
@@ -1942,6 +1954,13 @@
)
(define-method load_contents_finish
+ (docstring
+ "F.load_contents_finish(res) -> contents, length, etag_out\n\n"
+ "Finishes an asynchronous load of the file's contents. The contents are\n"
+ "placed in contents, and length is set to the size of the contents\n"
+ "string. If etag_out is present, it will be set to the new entity\n"
+ "tag for the file.\n"
+ )
(of-object "GFile")
(c-name "g_file_load_contents_finish")
(return-type "gboolean")
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 1b91d2d..7f33137 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -70,7 +70,25 @@ class TestFile(unittest.TestCase):
self.assertEqual(cont, "testing load_contents")
self.assertEqual(leng, 21)
self.assertNotEqual(etag, '')
-
+
+ def testLoadContentsAsync(self):
+ self._f.write("testing load_contents_async")
+ self._f.seek(0)
+
+ def callback(contents, result):
+ try:
+ cont, leng, etag = contents.load_contents_finish(result)
+ self.assertEqual(cont, "testing load_contents_async")
+ self.assertEqual(leng, 27)
+ self.assertNotEqual(etag, '')
+ finally:
+ loop.quit()
+
+ canc = gio.Cancellable()
+ self.file.load_contents_async(callback, cancellable=canc)
+
+ loop = gobject.MainLoop()
+ loop.run()
class TestGFileEnumerator(unittest.TestCase):
def setUp(self):