[pygobject] Wrap gio.OutputStream.flush_async()



commit 59da8cd24ea390b6c983995833ec6b0e5d028b35
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Sun May 24 11:44:24 2009 +0200

    Wrap gio.OutputStream.flush_async()
    
    wrap gio.OutputStream.flush_async() and add a test.
---
 gio/goutputstream.override |   47 +++++++++++++++++++++++++++++++++++++++++++-
 tests/test_gio.py          |   11 ++++++++++
 2 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/gio/goutputstream.override b/gio/goutputstream.override
index 9e2f8c4..e51c6b2 100644
--- a/gio/goutputstream.override
+++ b/gio/goutputstream.override
@@ -209,7 +209,52 @@ _wrap_g_memory_output_stream_get_data(PyGObject *self)
     return PyString_FromStringAndSize(g_memory_output_stream_get_data(stream),
 				      g_seekable_tell(G_SEEKABLE(stream)));
 }
+%%
+override g_output_stream_flush_async kwargs
+static PyObject *
+_wrap_g_output_stream_flush_async(PyGObject *self,
+				  PyObject *args,
+				  PyObject *kwargs)
+{
+  static char *kwlist[] = { "callback", "io_priority",
+			    "cancellable", "user_data", NULL };
+  int io_priority = G_PRIORITY_DEFAULT;
+  PyGObject *pycancellable = NULL;
+  GCancellable *cancellable;
+  PyGIONotify *notify;
+
+  notify = pygio_notify_new();
+
+  if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+				   "O|iOO:OutputStream.flush_async",
+				   kwlist,
+				   &notify->callback,
+				   &io_priority,
+				   &pycancellable,
+				   &notify->data))
+      goto error;
+
+  if (!pygio_notify_callback_is_valid(notify))
+      goto error;
+
+  if (!pygio_check_cancellable(pycancellable, &cancellable))
+      goto error;
+
+  pygio_notify_reference_callback(notify);
+  
+  g_output_stream_flush_async(G_OUTPUT_STREAM(self->obj),
+			      io_priority,
+			      cancellable,
+			      (GAsyncReadyCallback)async_result_callback_marshal,
+			      notify);
+  
+  Py_INCREF(Py_None);
+  return Py_None;
+
+ error:
+  pygio_notify_free(notify);
+  return NULL;
+}
 
 /* GOutputStream.write_all: No ArgType for const-void* */
 /* GOutputStream.splice_async: No ArgType for GAsyncReadyCallback */
-/* GOutputStream.flush_async: No ArgType for GAsyncReadyCallback */
diff --git a/tests/test_gio.py b/tests/test_gio.py
index d36c213..cf82658 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -804,7 +804,18 @@ class TestOutputStream(unittest.TestCase):
 
         loop = glib.MainLoop()
         loop.run()
+        
+    def testFlushAsync(self):
+        def callback(stream, result):
+            try:
+                self.failUnless(stream.flush_finish(result))
+            finally:
+                loop.quit()
+
+        self.stream.flush_async(callback)
 
+        loop = glib.MainLoop()
+        loop.run()
 
 class TestMemoryOutputStream(unittest.TestCase):
     def setUp(self):



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