summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--gio/Makefile.am5
-rw-r--r--gio/gfile.override26
-rw-r--r--gio/ginputstream.override44
-rw-r--r--gio/gio.override1
-rw-r--r--gio/goutputstream.override30
-rw-r--r--gio/pygio-utils.c47
-rw-r--r--gio/pygio-utils.h35
8 files changed, 116 insertions, 84 deletions
diff --git a/ChangeLog b/ChangeLog
index 26bff50..342668e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-07-14 Johan Dahlin <johan@gnome.org>
+
+ * gio/Makefile.am:
+ * gio/gfile.override:
+ * gio/ginputstream.override:
+ * gio/gio.override:
+ * gio/goutputstream.override:
+ * gio/pygio-utils.c (pygio_check_cancellable):
+ * gio/pygio-utils.h:
+ Refactor cancellable check to a utility function, avoids
+ plenty of code duplication.
+
2008-07-14 Paul Pogonyshev <pogonyshev@gmx.net>
* codegen/definitions.py (ReturnType): New class.
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 348d9c0..434059c 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -50,7 +50,10 @@ gio.c: $(GIO_DEFS) $(GIO_OVERRIDES)
_gio_la_CFLAGS = $(GIO_CFLAGS)
_gio_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_gio
_gio_la_LIBADD = $(GIO_LIBS)
-_gio_la_SOURCES = giomodule.c
+_gio_la_SOURCES = \
+ giomodule.c \
+ pygio-utils.c \
+ pygio-utils.h
nodist__gio_la_SOURCES = gio.c
if BUILD_GIO
pkgpyexec_LTLIBRARIES += _gio.la
diff --git a/gio/gfile.override b/gio/gfile.override
index b36d9da..a9c4a33 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -121,18 +121,9 @@ _wrap_g_file_read_async(PyGObject *self,
Py_INCREF(notify->callback);
Py_XINCREF(notify->data);
- if (pycancellable == NULL || (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");
- g_slice_free(PyGAsyncRequestNotify, notify);
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
return NULL;
- }
-
+
g_file_read_async(G_FILE(self->obj),
io_priority,
cancellable,
@@ -163,16 +154,9 @@ _wrap_g_file_load_contents(PyGObject *self,
&pycancellable))
return NULL;
- if (pycancellable == NULL || (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 (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
+
ret = g_file_load_contents(G_FILE(self->obj), cancellable,
&contents, &lenght, &etag_out, &error);
diff --git a/gio/ginputstream.override b/gio/ginputstream.override
index 0c21a12..61758e7 100644
--- a/gio/ginputstream.override
+++ b/gio/ginputstream.override
@@ -94,17 +94,9 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
buffersize = BUFSIZE;
- if (pycancellable == NULL || (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 (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
+
v = PyString_FromStringAndSize((char *)NULL, buffersize);
if (v == NULL)
return NULL;
@@ -191,18 +183,9 @@ _wrap_g_input_stream_read_async(PyGObject *self,
Py_INCREF(notify->callback);
Py_XINCREF(notify->data);
- if (pycancellable == NULL || (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");
- g_slice_free(PyGAsyncRequestNotifyRead, notify);
- return NULL;
- }
-
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
+
notify->buffer = PyString_FromStringAndSize((char *)NULL, count);
if (notify->buffer == NULL)
return NULL;
@@ -286,18 +269,9 @@ _wrap_g_input_stream_close_async(PyGObject *self,
}
Py_INCREF(notify->callback);
Py_XINCREF(notify->data);
-
- if (pycancellable == NULL || (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");
- g_slice_free(PyGAsyncRequestNotify, notify);
- return NULL;
- }
+
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
g_input_stream_close_async(G_INPUT_STREAM(self->obj),
io_priority,
diff --git a/gio/gio.override b/gio/gio.override
index 6624ad0..6c896fd 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -28,6 +28,7 @@ headers
#define NO_IMPORT_PYGOBJECT
#include <pygobject.h>
#include <gio/gio.h>
+#include "pygio-utils.h"
#define BUFSIZE 8192
diff --git a/gio/goutputstream.override b/gio/goutputstream.override
index 1125909..640c73f 100644
--- a/gio/goutputstream.override
+++ b/gio/goutputstream.override
@@ -40,16 +40,8 @@ _wrap_g_output_stream_write(PyGObject *self,
&PyGCancellable_Type, &pycancellable))
return NULL;
- if (pycancellable == NULL || (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");
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
return NULL;
- }
pyg_begin_allow_threads;
written = g_output_stream_write(G_OUTPUT_STREAM(self->obj),
@@ -101,16 +93,8 @@ _wrap_g_output_stream_write_async(PyGObject *self,
Py_INCREF(notify->callback);
Py_XINCREF(notify->data);
- if (pycancellable == NULL || (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");
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
return NULL;
- }
g_output_stream_write_async(G_OUTPUT_STREAM(self->obj),
buffer,
@@ -151,16 +135,8 @@ _wrap_g_output_stream_close_async(PyGObject *self,
return NULL;
}
- if (pycancellable == NULL || (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");
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
return NULL;
- }
if (!PyCallable_Check(notify->callback))
{
diff --git a/gio/pygio-utils.c b/gio/pygio-utils.c
new file mode 100644
index 0000000..b3c88b9
--- /dev/null
+++ b/gio/pygio-utils.c
@@ -0,0 +1,47 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 2008 Johan Dahlin
+ *
+ * giomodule.c: module wrapping the GIO library
+ *
+ * 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
+ */
+
+#include "pygio-utils.h"
+
+/**
+ * pygio_check_cancellable:
+ * @pycancellable:
+ * @cancellable:
+ *
+ * Returns:
+ */
+gboolean
+pygio_check_cancellable(PyGObject *pycancellable,
+ GCancellable **cancellable)
+{
+ if (pycancellable == NULL || (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 FALSE;
+ }
+ return TRUE;
+}
diff --git a/gio/pygio-utils.h b/gio/pygio-utils.h
new file mode 100644
index 0000000..980c52f
--- /dev/null
+++ b/gio/pygio-utils.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 2008 Johan Dahlin
+ *
+ * giomodule.c: module wrapping the GIO library
+ *
+ * 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
+ */
+
+#ifndef __PYGIO_UTILS_H__
+#define __PYGIO_UTILS_H__
+
+#include <Python.h>
+#include <gio/gio.h>
+#include "pygobject.h"
+
+extern PyTypeObject PyGCancellable_Type;
+
+gboolean pygio_check_cancellable(PyGObject *pycancellable,
+ GCancellable **cancellable);
+
+#endif /* __PYGIO_UTILS_H__ */