diff options
author | Gian Mario Tagliaretti <gianmt@gnome.org> | 2009-05-24 22:12:04 +0200 |
---|---|---|
committer | Gian Mario Tagliaretti <gianmt@gnome.org> | 2009-05-24 22:19:34 +0200 |
commit | 11524cdf6472d9115a812ce431f6767aec5627bc (patch) | |
tree | 55c5a0621009141fad38c72e61a0d320e79bf8ea | |
parent | 82ad6b8c8ea4d6694126f5e0e67b826717e38f19 (diff) | |
download | pygobject-11524cdf6472d9115a812ce431f6767aec5627bc.tar.gz pygobject-11524cdf6472d9115a812ce431f6767aec5627bc.tar.xz pygobject-11524cdf6472d9115a812ce431f6767aec5627bc.zip |
Wrap gio.OutputStream.splice_async()
wrap gio.OutputStream.splice_async() and add a test.
-rw-r--r-- | gio/goutputstream.override | 58 | ||||
-rw-r--r-- | 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, + ¬ify->callback, + &flags, + &io_priority, + &pycancellable, + ¬ify->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): |