pygobject r920 - in trunk: . gio tests



Author: gianmt
Date: Sat Aug  2 21:51:10 2008
New Revision: 920
URL: http://svn.gnome.org/viewvc/pygobject?rev=920&view=rev

Log:
Wrap GFile.create_async with docs and 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	Sat Aug  2 21:51:10 2008
@@ -826,8 +826,92 @@
     Py_INCREF(Py_None);
     return Py_None;
 }
+%%
+override g_file_create_async kwargs
+static PyObject *
+_wrap_g_file_create_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "flags", "io_priority",
+                              "cancellable", "user_data", NULL };
+    GCancellable *cancellable;
+    PyGObject *pycancellable = NULL;
+    GFileCreateFlags flags = G_FILE_CREATE_NONE;
+    PyObject *py_flags = NULL;
+    int io_priority = G_PRIORITY_DEFAULT;
+    PyGIONotify *notify;
 
-/* GFile.create_async */
+    notify = g_slice_new0(PyGIONotify);
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O|OiOO:File.create_async",
+                                      kwlist,
+                                      &notify->callback,
+                                      &flags, &io_priority,
+                                      &pycancellable,
+                                      &notify->data))
+
+    {
+      g_slice_free(PyGIONotify, notify);
+      return NULL;
+    }
+
+    if (py_flags && pyg_flags_get_value(G_TYPE_FILE_CREATE_FLAGS,
+                                        py_flags, (gpointer)&flags))
+        return NULL;
+
+    if (!pygio_check_cancellable(pycancellable, &cancellable))
+        return NULL;
+
+    g_file_create_async(G_FILE(self->obj), flags, io_priority, cancellable,
+                        (GAsyncReadyCallback)async_result_callback_marshal,
+                        notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+%%
+override g_file_create_async kwargs
+static PyObject *
+_wrap_g_file_create_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "flags", "io_priority",
+                              "cancellable", "user_data", NULL };
+    GCancellable *cancellable;
+    PyGObject *pycancellable = NULL;
+    GFileCreateFlags flags = G_FILE_CREATE_NONE;
+    PyObject *py_flags = NULL;
+    int io_priority = G_PRIORITY_DEFAULT;
+    PyGIONotify *notify;
+
+    notify = g_slice_new0(PyGIONotify);
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O|OiOO:File.create_async",
+                                      kwlist,
+                                      &notify->callback,
+                                      &flags, &io_priority,
+                                      &pycancellable,
+                                      &notify->data))
+
+    {
+      g_slice_free(PyGIONotify, notify);
+      return NULL;
+    }
+
+    if (py_flags && pyg_flags_get_value(G_TYPE_FILE_CREATE_FLAGS,
+                                        py_flags, (gpointer)&flags))
+        return NULL;
+
+    if (!pygio_check_cancellable(pycancellable, &cancellable))
+        return NULL;
+
+    g_file_create_async(G_FILE(self->obj), flags, io_priority, cancellable,
+                        (GAsyncReadyCallback)async_result_callback_marshal,
+                        notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
 /* GFile.eject_mountable */
 /* GFile.find_enclosing_mount_async */
 /* GFile.query_info_async */

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Sat Aug  2 21:51:10 2008
@@ -1420,6 +1420,16 @@
 )
 
 (define-method create_async
+  (docstring
+  "F.create_async(callback [flags, [,io_priority [,cancellable [,user_data]]]]) -> file created\n"
+  "\n"
+  "Asynchronously creates a new file and returns an output stream for\n"
+  "writing to it. The file must not already exist.\n"
+  "For more details, see F.create() which is the synchronous\n"
+  "version of this call.\n"
+  "When the operation is finished, callback will be called. You can\n"
+  "then call F.create_finish() to get the result of the operation."
+  )
   (of-object "GFile")
   (c-name "g_file_create_async")
   (return-type "none")

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Sat Aug  2 21:51:10 2008
@@ -72,6 +72,45 @@
         loop = glib.MainLoop()
         loop.run()
 
+    def testCreateAsync(self):
+        def callback(file, result):
+            try:
+                stream = file.create_finish(result)
+                self.failUnless(isinstance(stream, gio.OutputStream))
+                w = stream.write("testing")
+                cont, leng, etag = file.load_contents()
+                self.assertEqual(cont, "testing")
+            finally:
+                if os.path.exists('temp.txt'):
+                    os.unlink("temp.txt")
+                loop.quit()
+
+        gfile = gio.File("temp.txt")
+        gfile.create_async(callback, gio.FILE_CREATE_NONE,
+                           glib.PRIORITY_HIGH)
+
+        loop = glib.MainLoop()
+        loop.run()
+
+    def testCreateAsyncNoargs(self):
+        def callback(file, result):
+            try:
+                stream = file.create_finish(result)
+                self.failUnless(isinstance(stream, gio.OutputStream))
+                w = stream.write("testing")
+                cont, leng, etag = file.load_contents()
+                self.assertEqual(cont, "testing")
+            finally:
+                if os.path.exists('temp.txt'):
+                    os.unlink("temp.txt")
+                loop.quit()
+
+        gfile = gio.File("temp.txt")
+        gfile.create_async(callback)
+
+        loop = glib.MainLoop()
+        loop.run()
+
     def testReadAsyncError(self):
         self.assertRaises(TypeError, self.file.read_async)
         self.assertRaises(TypeError, self.file.read_async, "foo", "bar")



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