summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--gio/Makefile.am1
-rw-r--r--gio/gfile.override75
-rw-r--r--gio/ginputstream.override2
-rw-r--r--gio/gio.override5
-rw-r--r--gio/goutputstream.override2
-rw-r--r--gio/gvolumemonitor.override2
-rw-r--r--tests/test_gio.py53
8 files changed, 139 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d1b35b..2d60e3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-01-21 Johan Dahlin <johan@gnome.org>
+
+ * gio/gio.override (async_result_callback_marshal):
+ Don't assume the buffer is set, use Py_XINCREF instead of Py_INCREF.
+
+ * gio/Makefile.am:
+ * gio/ginputstream.override:
+ * gio/goutputstream.override:
+ * gio/gvolumemonitor.override:
+ * gio/gfile.override:
+ * tests/test_gio.py:
+ Implement and test GFile.read_async. Use try/finally to always quit
+ the mainloop, even if the test fail.
+ Update source comment headers.
+
2008-01-20 Johan Dahlin <johan@gnome.org>
* tests/test_gio.py (TestVolumeMonitor): New test
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 955e3f2..0d40ea8 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -35,6 +35,7 @@ EXTRA_DIST =
# gio module
GIO_OVERRIDES = \
gio.override \
+ gfile.override \
ginputstream.override \
goutputstream.override \
gvolumemonitor.override
diff --git a/gio/gfile.override b/gio/gfile.override
new file mode 100644
index 0000000..a876cb8
--- /dev/null
+++ b/gio/gfile.override
@@ -0,0 +1,75 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygobject - Python bindings for GObject
+ * Copyright (C) 2008 Johan Dahlin
+ *
+ * gfile.override: module overrides for GInputStream
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+%%
+override g_file_read_async kwargs
+static PyObject *
+_wrap_g_file_read_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "io_priority", "cancellable", "callback",
+ "user_data", NULL };
+ int io_priority = G_PRIORITY_DEFAULT;
+ PyGObject *pycancellable;
+ GCancellable *cancellable;
+ PyGAsyncRequestNotify *notify;
+
+ notify = g_slice_new0(PyGAsyncRequestNotify);
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "iOO|O:InputStream.read_async",
+ kwlist,
+ &io_priority,
+ &pycancellable,
+ &notify->callback,
+ &notify->data))
+ {
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+
+ if ((PyObject*)pycancellable == Py_None)
+ cancellable = NULL;
+ else if (pygobject_check(pycancellable, &PyGCancellable_Type))
+ cancellable = G_CANCELLABLE(pycancellable->obj);
+ else
+ {
+ PyErr_SetString(PyExc_TypeError, "cancellable should be a gio.Cancellable");
+ return NULL;
+ }
+
+ if (!PyCallable_Check(notify->callback))
+ {
+ PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+ Py_INCREF(notify->callback);
+ Py_XINCREF(notify->data);
+
+ g_file_read_async(G_FILE(self->obj),
+ io_priority,
+ cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
diff --git a/gio/ginputstream.override b/gio/ginputstream.override
index a880f5f..d85a2c3 100644
--- a/gio/ginputstream.override
+++ b/gio/ginputstream.override
@@ -1,5 +1,5 @@
/* -*- Mode: C; c-basic-offset: 4 -*-
- * pygtk- Python bindings for the GTK toolkit.
+ * pygobject - Python bindings for GObject
* Copyright (C) 2008 Johan Dahlin
*
* ginputstream.override: module overrides for GInputStream
diff --git a/gio/gio.override b/gio/gio.override
index 8e6f167..8a401cb 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -53,10 +53,10 @@ async_result_callback_marshal(GObject *source_object,
static GQuark quark = 0;
state = pyg_gil_state_ensure();
-
+
if (!quark)
quark = g_quark_from_string("pygio::buffer");
- Py_INCREF(notify->buffer);
+ Py_XINCREF(notify->buffer);
g_object_set_qdata_full(G_OBJECT(result), quark,
notify->buffer, py_decref_callback);
@@ -86,6 +86,7 @@ async_result_callback_marshal(GObject *source_object,
}
%%
include
+ gfile.override
ginputstream.override
goutputstream.override
gvolumemonitor.override
diff --git a/gio/goutputstream.override b/gio/goutputstream.override
index f7ad2e1..6969d7f 100644
--- a/gio/goutputstream.override
+++ b/gio/goutputstream.override
@@ -1,5 +1,5 @@
/* -*- Mode: C; c-basic-offset: 4 -*-
- * pygtk- Python bindings for the GTK toolkit.
+ * pygobject - Python bindings for GObject
* Copyright (C) 2008 Johan Dahlin
*
* goutputstream.override: module overrides for GOutputStream
diff --git a/gio/gvolumemonitor.override b/gio/gvolumemonitor.override
index 27c193f..1ecc942 100644
--- a/gio/gvolumemonitor.override
+++ b/gio/gvolumemonitor.override
@@ -1,5 +1,5 @@
/* -*- Mode: C; c-basic-offset: 4 -*-
- * pygtk- Python bindings for the GTK toolkit.
+ * pygobject - Python bindings for GObject
* Copyright (C) 2008 Johan Dahlin
*
* gvolumemonitor.override: module overrides for GVolumeMonitor
diff --git a/tests/test_gio.py b/tests/test_gio.py
index d083361..b45e92f 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -6,6 +6,33 @@ import unittest
from common import gio, gobject
+class TestFile(unittest.TestCase):
+ def setUp(self):
+ self._f = open("file.txt", "w+")
+ self.file = gio.file_new_for_path("file.txt")
+
+ def tearDown(self):
+ self._f.close()
+ os.unlink("file.txt")
+
+ def testReadAsync(self):
+ self._f.write("testing")
+ self._f.seek(0)
+
+ def callback(file, result):
+ try:
+ stream = file.read_finish(result)
+ self.failUnless(isinstance(stream, gio.InputStream))
+ self.assertEquals(stream.read(), "testing")
+ finally:
+ loop.quit()
+
+ self.file.read_async(0, None, callback)
+
+ loop = gobject.MainLoop()
+ loop.run()
+
+
class TestInputStream(unittest.TestCase):
def setUp(self):
self._f = open("inputstream.txt", "w+")
@@ -22,11 +49,13 @@ class TestInputStream(unittest.TestCase):
def testReadAsync(self):
def callback(stream, result):
- read = stream.read_finish(result)
- self.assertEquals(read, len("testing"))
- self.assertEquals(result.get_buffer(), "testing")
- stream.close()
- loop.quit()
+ try:
+ read = stream.read_finish(result)
+ self.assertEquals(read, len("testing"))
+ self.assertEquals(result.get_buffer(), "testing")
+ stream.close()
+ finally:
+ loop.quit()
self.stream.read_async(7, 0, None, callback)
@@ -36,12 +65,14 @@ class TestInputStream(unittest.TestCase):
def testReadAsyncError(self):
self.count = 0
def callback(stream, result):
- #self.assertEquals(result.get_buffer(), None)
- self.count += 1
- if self.count == 1:
- return
- self.assertRaises(gobject.GError, stream.read_finish, result)
- loop.quit()
+ try:
+ #self.assertEquals(result.get_buffer(), None)
+ self.count += 1
+ if self.count == 1:
+ return
+ self.assertRaises(gobject.GError, stream.read_finish, result)
+ finally:
+ loop.quit()
self.stream.read_async(10240, 0, None, callback)
self.stream.read_async(10240, 0, None, callback)