[pygobject] Wrap gio.Resolver.lookup_by_name_finish() and add a test



commit c91656dbe56f07d3ebbad5113467c22427cf212a
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Tue Dec 29 21:41:30 2009 +0100

    Wrap gio.Resolver.lookup_by_name_finish() and add a test

 gio/gresolver.override  |   82 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_gresolver.py |   16 ++++++++-
 2 files changed, 96 insertions(+), 2 deletions(-)
---
diff --git a/gio/gresolver.override b/gio/gresolver.override
index 1f2d9b6..2055fd3 100644
--- a/gio/gresolver.override
+++ b/gio/gresolver.override
@@ -55,3 +55,85 @@ _wrap_g_resolver_lookup_by_name(PyGObject *self,
         return Py_None;
     }
 }
+%%
+override g_resolver_lookup_by_name_async kwargs
+static PyObject *
+_wrap_g_resolver_lookup_by_name_async(PyGObject *self,
+                                      PyObject *args,
+                                      PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "hostname",
+                              "cancellable", "user_data", NULL };
+    PyGIONotify *notify;
+    gchar *hostname;
+    PyGObject *py_cancellable = NULL;
+    GCancellable *cancellable;
+
+    notify = pygio_notify_new();
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "Os|OO:gio.Resolver.lookup_by_name_async",
+                                     kwlist,
+                                     &notify->callback,
+                                     &hostname,
+                                     &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_resolver_lookup_by_name_async(G_RESOLVER(self->obj),
+                          hostname,
+                          cancellable,
+                          (GAsyncReadyCallback) async_result_callback_marshal,
+                          notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+
+ error:
+    pygio_notify_free(notify);
+    return NULL;
+}
+%%
+override g_resolver_lookup_by_name_finish kwargs
+static PyObject *
+_wrap_g_resolver_lookup_by_name_finish(PyGObject *self,
+                                       PyObject *args,
+                                       PyObject *kwargs)
+{
+    static char *kwlist[] = { "result", NULL };
+    PyGObject *result;
+    GList *addr;
+    PyObject *ret;
+    GError *error = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O!:gio.Resolver.lookup_by_name_finish",
+                                     kwlist,
+                                     &PyGAsyncResult_Type,
+                                     &result))
+        return NULL;
+    
+    addr = g_resolver_lookup_by_name_finish(G_RESOLVER(self->obj),
+                                            G_ASYNC_RESULT(result->obj),
+                                            &error);
+    
+    if (pyg_error_check(&error))
+        return NULL;
+
+    if (addr) {
+        PYLIST_FROMGLIST(ret, addr, pygobject_new(list_item),
+                         g_resolver_free_addresses, NULL);
+        return ret;
+    } else {
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+}
diff --git a/tests/test_gresolver.py b/tests/test_gresolver.py
index 67ffbb2..b6fd0b0 100644
--- a/tests/test_gresolver.py
+++ b/tests/test_gresolver.py
@@ -3,7 +3,7 @@
 import os
 import unittest
 
-from common import gio
+from common import gio, glib
 
 
 class TestResolver(unittest.TestCase):
@@ -18,4 +18,16 @@ class TestResolver(unittest.TestCase):
         address = gio.inet_address_new_from_string("8.8.8.8")
         dns = self.resolver.lookup_by_address(address, cancellable=None)
         self.failUnlessEqual(dns, "google-public-dns-a.google.com")
-        
+    
+    def test_resolver_lookup_by_name_async(self):
+        def callback(resolver, result):
+            try:
+                addresses = resolver.lookup_by_name_finish(result)
+                self.failUnless(isinstance(addresses[0], gio.InetAddress))
+            finally:
+                loop.quit()
+
+        self.resolver.lookup_by_name_async(callback, "pygtk.org")
+
+        loop = glib.MainLoop()
+        loop.run()



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