[pygobject] Wrap gio.SocketAddressEnumerator.next_async() and add a test



commit dff024256295c15e49888ad9d5fef74a7746edd7
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Wed Dec 30 23:44:25 2009 +0100

    Wrap gio.SocketAddressEnumerator.next_async() and add a test

 gio/gsocket.override  |   42 ++++++++++++++++++++++++++++++++++++++++++
 tests/test_gsocket.py |   16 ++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/gio/gsocket.override b/gio/gsocket.override
index 4bf3a6b..95e6527 100644
--- a/gio/gsocket.override
+++ b/gio/gsocket.override
@@ -66,6 +66,48 @@ _wrap_g_socket_condition_wait(PyGObject *self,
     
     return PyBool_FromLong(ret);
 }
+%%
+override g_socket_address_enumerator_next_async kwargs
+static PyObject *
+_wrap_g_socket_address_enumerator_next_async(PyGObject *self,
+                                             PyObject *args,
+                                             PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
+    PyGIONotify *notify;
+    PyGObject *py_cancellable = NULL;
+    GCancellable *cancellable;
+
+    notify = pygio_notify_new();
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                    "O|OO:gio.SocketAddressEnumerator.next_async",
+                                    kwlist,
+                                    &notify->callback,
+                                    &py_cancellable,
+                                    &notify->data))
+        goto error;
+      
+    if (!pygio_notify_callback_is_valid(notify))
+        goto error;
+
+    if (!pygio_check_cancellable(py_cancellable, &cancellable))
+        goto error;
+
+    pygio_notify_reference_callback(notify);
+
+    g_socket_address_enumerator_next_async(G_SOCKET_ADDRESS_ENUMERATOR(self->obj),
+                          cancellable,
+                          (GAsyncReadyCallback) async_result_callback_marshal,
+                          notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+
+ error:
+    pygio_notify_free(notify);
+    return NULL;
+}
 
 /* Could not write method GSocket.receive_from: No ArgType for GSocketAddress** */
 /* Could not write method GSocket.receive_message: No ArgType for GSocketAddress** */
diff --git a/tests/test_gsocket.py b/tests/test_gsocket.py
index 671026f..9ac2398 100644
--- a/tests/test_gsocket.py
+++ b/tests/test_gsocket.py
@@ -23,3 +23,19 @@ class TestSocket(unittest.TestCase):
 
     def tearDown(self):
         self.sock.close()
+
+class TestSocketAddress(unittest.TestCase):
+    def test_socket_address_enumerator_next_async(self):
+        def callback(enumerator, result):
+            try:
+                address = enumerator.next_finish(result)
+                self.failUnless(isinstance(address, gio.SocketAddress))
+            finally:
+                loop.quit()
+
+        socket = gio.NetworkAddress("www.pygtk.org", 80)
+        enumerator = socket.enumerate()
+        enumerator.next_async(callback)
+
+        loop = glib.MainLoop()
+        loop.run()



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