From 407b0e909056f15960e6a4e549896d786ce0a0b2 Mon Sep 17 00:00:00 2001 From: Gian Mario Tagliaretti Date: Tue, 9 Jun 2009 00:08:21 +0200 Subject: Wrap gio.BufferedInputStream.fill_async Wrap the method gio.BufferedInputStream.fill_async and add a test --- gio/Makefile.am | 1 + gio/gbufferedinputstream.override | 70 +++++++++++++++++++++++++++++++++++++++ gio/gio.override | 1 + tests/test_gio.py | 25 ++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 gio/gbufferedinputstream.override diff --git a/gio/Makefile.am b/gio/Makefile.am index ccb8000..53f5024 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -38,6 +38,7 @@ GIO_OVERRIDES = \ gio.override \ gappinfo.override \ gapplaunchcontext.override \ + gbufferedinputstream.override \ gdatainputstream.override \ gdrive.override \ gfile.override \ diff --git a/gio/gbufferedinputstream.override b/gio/gbufferedinputstream.override new file mode 100644 index 0000000..cb76da4 --- /dev/null +++ b/gio/gbufferedinputstream.override @@ -0,0 +1,70 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygobject - Python bindings for GObject + * Copyright (C) 2009 Gian Mario Tagliaretti + * + * gbufferedinputstream.override: module overrides for GBufferedInputStream + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ +%% +override g_buffered_input_stream_fill_async kwargs +static PyObject * +_wrap_g_buffered_input_stream_fill_async(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "count", "callback", "io_priority", + "cancellable", "user_data", NULL }; + long count = -1; + int io_priority = G_PRIORITY_DEFAULT; + PyGObject *pycancellable = NULL; + GCancellable *cancellable; + PyGIONotify *notify; + + notify = pygio_notify_new(); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "lO|iOO:gio.BufferedInputStream.fill_async", + kwlist, + &count, + ¬ify->callback, + &io_priority, + &pycancellable, + ¬ify->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_buffered_input_stream_fill_async(G_INPUT_STREAM(self->obj), + count, + io_priority, + cancellable, + (GAsyncReadyCallback) async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; + + error: + pygio_notify_free(notify); + return NULL; +} diff --git a/gio/gio.override b/gio/gio.override index 3363a0f..78d3688 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -230,6 +230,7 @@ async_result_callback_marshal(GObject *source_object, include gappinfo.override gapplaunchcontext.override + gbufferedinputstream.override gdatainputstream.override gdrive.override gfile.override diff --git a/tests/test_gio.py b/tests/test_gio.py index de5409f..1578d58 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -1042,3 +1042,28 @@ class TestFileOutputStream(unittest.TestCase): loop = glib.MainLoop() loop.run() + +class TestBufferedInputStream(unittest.TestCase): + def setUp(self): + self._f = open("buffer.txt", "w+") + self._f.write("testing") + self._f.seek(0) + stream = gio.unix.InputStream(self._f.fileno(), False) + self.buffered = gio.BufferedInputStream(stream) + + def tearDown(self): + self._f.close() + os.unlink("buffer.txt") + + def test_fill_async(self): + def callback(stream, result): + try: + size = stream.fill_finish(result) + self.failUnlessEqual(size, 4) + finally: + loop.quit() + + self.buffered.fill_async(4, callback) + + loop = glib.MainLoop() + loop.run() -- cgit