summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-03-22 18:14:01 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-03-22 18:14:01 +0000
commitc27ae2b634dc06b1242ac7a9368d11945a4e1783 (patch)
tree6df83df006616945e974ceef542906a84bb1ae44
parent6ee167447336570b83e41ca2c4216d6e9058fd43 (diff)
downloadpygobject-c27ae2b634dc06b1242ac7a9368d11945a4e1783.tar.gz
pygobject-c27ae2b634dc06b1242ac7a9368d11945a4e1783.tar.xz
pygobject-c27ae2b634dc06b1242ac7a9368d11945a4e1783.zip
Make read_finish() return the string, remove the get_buffer method. This
2008-03-22 Johan Dahlin <johan@gnome.org> * gio/ginputstream.override: * gio/gio.override: * tests/test_gio.py: Make read_finish() return the string, remove the get_buffer method. This is more pythonic, as it mimics the normal read() behavior of python. Update the tests and use a separate marshaller for read. svn path=/trunk/; revision=753
-rw-r--r--ChangeLog11
-rw-r--r--gio/ginputstream.override97
-rw-r--r--gio/gio.override31
-rw-r--r--tests/test_gio.py6
4 files changed, 114 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index eb5b290..6825894 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-03-22 Johan Dahlin <johan@gnome.org>
+
+ * gio/ginputstream.override:
+ * gio/gio.override:
+ * tests/test_gio.py:
+
+ Make read_finish() return the string, remove the get_buffer method.
+ This is more pythonic, as it mimics the normal read() behavior of
+ python.
+ Update the tests and use a separate marshaller for read.
+
2008-03-21 Johan Dahlin <johan@gnome.org>
* gobject/__init__.py:
diff --git a/gio/ginputstream.override b/gio/ginputstream.override
index c279d41..a33903b 100644
--- a/gio/ginputstream.override
+++ b/gio/ginputstream.override
@@ -19,6 +19,64 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
+#define BUFSIZE 8192
+
+typedef struct {
+ PyObject *callback;
+ PyObject *data;
+ PyObject *buffer;
+} PyGAsyncRequestNotifyRead;
+
+static void
+py_decref_callback (gpointer data)
+{
+ Py_DECREF((PyObject*)data);
+}
+
+static void
+async_result_callback_marshal_read(GObject *source_object,
+ GAsyncResult *result,
+ PyGAsyncRequestNotifyRead *notify)
+{
+ PyObject *ret;
+ PyGILState_STATE state;
+ static GQuark quark = 0;
+
+ state = pyg_gil_state_ensure();
+
+ /* buffer is only used by read_async */
+ if (notify->buffer) {
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+ Py_XINCREF(notify->buffer);
+ g_object_set_qdata_full(G_OBJECT(result), quark,
+ notify->buffer, py_decref_callback);
+ }
+
+ if (notify->data)
+ ret = PyEval_CallFunction(notify->callback, "(OOO)",
+ pygobject_new(source_object),
+ pygobject_new((GObject *)result),
+ notify->data);
+ else
+ ret = PyObject_CallFunction(notify->callback, "(OO)",
+ pygobject_new(source_object),
+ pygobject_new((GObject *)result));
+
+ if (ret == NULL)
+ {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+
+ Py_XDECREF(ret);
+
+ Py_DECREF(notify->callback);
+ Py_XDECREF(notify->data);
+ g_slice_free(PyGAsyncRequestNotifyRead, notify);
+
+ pyg_gil_state_release(state);
+}
%%
override g_input_stream_read kwargs
static PyObject *
@@ -103,9 +161,9 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
GCancellable *cancellable;
- PyGAsyncRequestNotify *notify;
+ PyGAsyncRequestNotifyRead *notify;
- notify = g_slice_new0(PyGAsyncRequestNotify);
+ notify = g_slice_new0(PyGAsyncRequestNotifyRead);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"liOO|O:InputStream.read_async",
@@ -115,7 +173,7 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
&notify->callback,
&notify->data))
{
- g_slice_free(PyGAsyncRequestNotify, notify);
+ g_slice_free(PyGAsyncRequestNotifyRead, notify);
return NULL;
}
@@ -132,7 +190,7 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
if (!PyCallable_Check(notify->callback))
{
PyErr_SetString(PyExc_TypeError, "callback argument not callable");
- g_slice_free(PyGAsyncRequestNotify, notify);
+ g_slice_free(PyGAsyncRequestNotifyRead, notify);
return NULL;
}
Py_INCREF(notify->callback);
@@ -147,9 +205,38 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
count,
io_priority,
cancellable,
- (GAsyncReadyCallback)async_result_callback_marshal,
+ (GAsyncReadyCallback)async_result_callback_marshal_read,
notify);
Py_INCREF(Py_None);
return Py_None;
}
+%%
+override g_input_stream_read_finish kwargs
+static PyObject *
+_wrap_g_input_stream_read_finish(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "result", NULL };
+ PyGObject *result;
+ GError *error = NULL;
+ static GQuark quark = 0;
+ PyObject *buffer;
+
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!:GInputStream.read_finish",
+ kwlist, &PyGAsyncResult_Type, &result))
+ return NULL;
+
+
+ g_input_stream_read_finish(G_INPUT_STREAM(self->obj), G_ASYNC_RESULT(result->obj), &error);
+
+ if (pyg_error_check(&error))
+ return NULL;
+
+ buffer = g_object_get_qdata(G_OBJECT(result->obj), quark);
+ /* FIXME: Should we refcount the buffer here? */
+ return buffer;
+}
diff --git a/gio/gio.override b/gio/gio.override
index 8a401cb..ad26083 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -53,13 +53,16 @@ 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_XINCREF(notify->buffer);
- g_object_set_qdata_full(G_OBJECT(result), quark,
- notify->buffer, py_decref_callback);
+ /* buffer is only used by read_async */
+ if (notify->buffer) {
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+ Py_XINCREF(notify->buffer);
+ g_object_set_qdata_full(G_OBJECT(result), quark,
+ notify->buffer, py_decref_callback);
+ }
+
if (notify->data)
ret = PyEval_CallFunction(notify->callback, "(OOO)",
pygobject_new(source_object),
@@ -161,19 +164,3 @@ _wrap_g_app_info_get_all_for_type (PyGObject *self, PyObject *args)
return ret;
}
-%%
-define GSimpleAsyncResult.get_buffer noargs
-static PyObject *
-_wrap_g_simple_async_result_get_buffer(PyGObject *self)
-{
- static GQuark quark = 0;
- PyObject *buffer;
-
- if (!quark)
- quark = g_quark_from_string("pygio::buffer");
-
- buffer = g_object_get_qdata(G_OBJECT(self->obj), quark);
-
- Py_INCREF(buffer);
- return buffer;
-}
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 2b12d5b..ce1095e 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -66,9 +66,8 @@ class TestInputStream(unittest.TestCase):
def testReadAsync(self):
def callback(stream, result):
try:
- read = stream.read_finish(result)
- self.assertEquals(read, len("testing"))
- self.assertEquals(result.get_buffer(), "testing")
+ data = stream.read_finish(result)
+ self.assertEquals(data, "testing")
stream.close()
finally:
loop.quit()
@@ -82,7 +81,6 @@ class TestInputStream(unittest.TestCase):
self.count = 0
def callback(stream, result):
try:
- #self.assertEquals(result.get_buffer(), None)
self.count += 1
if self.count == 1:
return