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



commit 7fc71f490494dae73a5264869a97a9d30814930e
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Tue Dec 29 22:12:50 2009 +0100

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

 gio/gresolver.override  |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_gresolver.py |   14 ++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/gio/gresolver.override b/gio/gresolver.override
index 2055fd3..17a0224 100644
--- a/gio/gresolver.override
+++ b/gio/gresolver.override
@@ -137,3 +137,49 @@ _wrap_g_resolver_lookup_by_name_finish(PyGObject *self,
         return Py_None;
     }
 }
+%%
+override g_resolver_lookup_by_address_async kwargs
+static PyObject *
+_wrap_g_resolver_lookup_by_address_async(PyGObject *self,
+                                         PyObject *args,
+                                         PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "address",
+                              "cancellable", "user_data", NULL };
+    PyGIONotify *notify;
+    PyGObject *address;
+    PyGObject *py_cancellable = NULL;
+    GCancellable *cancellable;
+
+    notify = pygio_notify_new();
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "OO|OO:gio.Resolver.lookup_by_address_async",
+                                     kwlist,
+                                     &notify->callback,
+                                     &address,
+                                     &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_address_async(G_RESOLVER(self->obj),
+                          G_INET_ADDRESS(address->obj),
+                          cancellable,
+                          (GAsyncReadyCallback) async_result_callback_marshal,
+                          notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+
+ error:
+    pygio_notify_free(notify);
+    return NULL;
+}
diff --git a/tests/test_gresolver.py b/tests/test_gresolver.py
index b6fd0b0..736caaa 100644
--- a/tests/test_gresolver.py
+++ b/tests/test_gresolver.py
@@ -31,3 +31,17 @@ class TestResolver(unittest.TestCase):
 
         loop = glib.MainLoop()
         loop.run()
+
+    def test_resolver_lookup_by_address_async(self):
+        def callback(resolver, result):
+            try:
+                dns = resolver.lookup_by_address_finish(result)
+                self.failUnlessEqual(dns, "google-public-dns-b.google.com")
+            finally:
+                loop.quit()
+
+        address = gio.inet_address_new_from_string("8.8.4.4")
+        self.resolver.lookup_by_address_async(callback, address)
+
+        loop = glib.MainLoop()
+        loop.run()



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