[pygobject] Wrap gio.OutputStream.splice_async()



commit 11524cdf6472d9115a812ce431f6767aec5627bc
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Sun May 24 22:12:04 2009 +0200

    Wrap gio.OutputStream.splice_async()
    
    wrap gio.OutputStream.splice_async() and add a test.
---
 gio/goutputstream.override |   58 +++++++++++++++++++++++++++++++++++++++++++-
 tests/test_gio.py          |   20 +++++++++++++++
 2 files changed, 77 insertions(+), 1 deletions(-)

diff --git a/gio/goutputstream.override b/gio/goutputstream.override
index e51c6b2..6f3cd95 100644
--- a/gio/goutputstream.override
+++ b/gio/goutputstream.override
@@ -255,6 +255,62 @@ _wrap_g_output_stream_flush_async(PyGObject *self,
   pygio_notify_free(notify);
   return NULL;
 }
+%%
+override g_output_stream_splice_async kwargs
+static PyObject *
+_wrap_g_output_stream_splice_async(PyGObject *self,
+                                  PyObject *args,
+                                  PyObject *kwargs)
+{
+    static char *kwlist[] = { "source", "callback", "flags", "io_priority",
+                              "cancellable", "user_data", NULL };
+    
+    int io_priority = G_PRIORITY_DEFAULT;
+    GOutputStreamSpliceFlags flags = G_OUTPUT_STREAM_SPLICE_NONE;
+    PyObject *py_flags = NULL;
+    PyGObject *source;
+    PyGObject *pycancellable = NULL;
+    GCancellable *cancellable;
+    PyGIONotify *notify;
+  
+    notify = pygio_notify_new();
+  
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O!O|iOO:OutputStream.splice_async",
+                                     kwlist,
+                                     &PyGInputStream_Type,
+                                     &source,
+                                     &notify->callback,
+                                     &flags,
+                                     &io_priority,
+                                     &pycancellable,
+                                     &notify->data))
+        goto error;
+  
+    if (!pygio_notify_callback_is_valid(notify))
+        goto error;
+  
+    if (py_flags && pyg_flags_get_value(G_TYPE_OUTPUT_STREAM_SPLICE_FLAGS,
+                                        py_flags, (gpointer)&flags))
+        goto error;
+    
+    if (!pygio_check_cancellable(pycancellable, &cancellable))
+        goto error;
+  
+    pygio_notify_reference_callback(notify);
+    
+    g_output_stream_splice_async(G_OUTPUT_STREAM(self->obj),
+                            G_INPUT_STREAM(source->obj), flags, 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 */
diff --git a/tests/test_gio.py b/tests/test_gio.py
index cf82658..05b82b3 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -816,6 +816,26 @@ class TestOutputStream(unittest.TestCase):
 
         loop = glib.MainLoop()
         loop.run()
+    
+    def testSpliceAsync(self):
+        _f = open("stream.txt", "w+")
+        _f.write("testing")
+        _f.seek(0)
+        instream = gio.unix.InputStream(_f.fileno(), False)
+        
+        def callback(stream, result):
+            try:
+                size = stream.splice_finish(result)
+                self.assertEqual(size, 7)
+                
+            finally:
+                os.unlink("stream.txt")
+                loop.quit()
+
+        self.stream.splice_async(instream, 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]