pygobject r802 - in trunk: . gio tests



Author: gianmt
Date: Mon Jul 14 21:47:31 2008
New Revision: 802
URL: http://svn.gnome.org/viewvc/pygobject?rev=802&view=rev

Log:
wrap File.load_contents_async and File.load_contents_finish with docsstrings and a test

Modified:
   trunk/ChangeLog
   trunk/gio/gfile.override
   trunk/gio/gio.defs
   trunk/tests/test_gio.py

Modified: trunk/gio/gfile.override
==============================================================================
--- trunk/gio/gfile.override	(original)
+++ trunk/gio/gfile.override	Mon Jul 14 21:47:31 2008
@@ -170,12 +170,83 @@
         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 @@
 /* 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** */

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Mon Jul 14 21:47:31 2008
@@ -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")

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Mon Jul 14 21:47:31 2008
@@ -70,7 +70,25 @@
         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):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]