pygobject r797 - in trunk: . gio



Author: johan
Date: Mon Jul 14 18:27:57 2008
New Revision: 797
URL: http://svn.gnome.org/viewvc/pygobject?rev=797&view=rev

Log:
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



Added:
   trunk/gio/pygio-utils.c
   trunk/gio/pygio-utils.h
Modified:
   trunk/ChangeLog
   trunk/gio/Makefile.am
   trunk/gio/gfile.override
   trunk/gio/ginputstream.override
   trunk/gio/gio.override
   trunk/gio/goutputstream.override

Modified: trunk/gio/Makefile.am
==============================================================================
--- trunk/gio/Makefile.am	(original)
+++ trunk/gio/Makefile.am	Mon Jul 14 18:27:57 2008
@@ -50,7 +50,10 @@
 _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

Modified: trunk/gio/gfile.override
==============================================================================
--- trunk/gio/gfile.override	(original)
+++ trunk/gio/gfile.override	Mon Jul 14 18:27:57 2008
@@ -121,18 +121,9 @@
   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 @@
                                       &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);
 

Modified: trunk/gio/ginputstream.override
==============================================================================
--- trunk/gio/ginputstream.override	(original)
+++ trunk/gio/ginputstream.override	Mon Jul 14 18:27:57 2008
@@ -94,17 +94,9 @@
   
   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 @@
   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 @@
     }
   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,

Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override	(original)
+++ trunk/gio/gio.override	Mon Jul 14 18:27:57 2008
@@ -28,6 +28,7 @@
 #define NO_IMPORT_PYGOBJECT
 #include <pygobject.h>
 #include <gio/gio.h>
+#include "pygio-utils.h"
 
 #define BUFSIZE 8192
 

Modified: trunk/gio/goutputstream.override
==============================================================================
--- trunk/gio/goutputstream.override	(original)
+++ trunk/gio/goutputstream.override	Mon Jul 14 18:27:57 2008
@@ -40,16 +40,8 @@
 				   &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 @@
   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 @@
       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))
     {

Added: trunk/gio/pygio-utils.c
==============================================================================
--- (empty file)
+++ trunk/gio/pygio-utils.c	Mon Jul 14 18:27:57 2008
@@ -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;
+}

Added: trunk/gio/pygio-utils.h
==============================================================================
--- (empty file)
+++ trunk/gio/pygio-utils.h	Mon Jul 14 18:27:57 2008
@@ -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__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]