[pygobject] Wrap gio.Resolver.lookup_by_name() and add a couple of tests



commit 7589128515b79d836365247dc876538c6352da23
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Tue Dec 29 12:40:50 2009 +0100

    Wrap gio.Resolver.lookup_by_name() and add a couple of tests

 gio/Makefile.am         |    1 +
 gio/gio.override        |    1 +
 gio/gresolver.override  |   57 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_gresolver.py |   21 +++++++++++++++++
 4 files changed, 80 insertions(+), 0 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 1c5b41f..51a8fbc 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -55,6 +55,7 @@ GIO_OVERRIDES = 			\
 	gmemoryoutputstream.override	\
 	gmount.override			\
 	goutputstream.override 		\
+	gresolver.override		\
 	gvolume.override		\
 	gvolumemonitor.override
 
diff --git a/gio/gio.override b/gio/gio.override
index c9b13c3..62833ee 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -247,6 +247,7 @@ include
   gmount.override
   ginputstream.override
   goutputstream.override
+  gresolver.override
   gvolume.override
   gvolumemonitor.override
 %%
diff --git a/gio/gresolver.override b/gio/gresolver.override
new file mode 100644
index 0000000..1f2d9b6
--- /dev/null
+++ b/gio/gresolver.override
@@ -0,0 +1,57 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygobject - Python bindings for GObject
+ * Copyright (C) 2009  Gian Mario Tagliaretti
+ *
+ *   gresolver.override: module overrides for GResolver
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+%%
+override g_resolver_lookup_by_name kwargs
+static PyObject *
+_wrap_g_resolver_lookup_by_name(PyGObject *self,
+                                PyObject *args,
+                                PyObject *kwargs)
+{
+    static char *kwlist[] = { "hostname", "cancellable", NULL };
+    gchar *hostname;
+    PyGObject *pycancellable = NULL;
+    GCancellable *cancellable;
+    GList *addr;
+    GError *error = NULL;
+    PyObject *ret;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                    "s|O:gio.Resolver.lookup_by_name",
+                                    kwlist,
+                                    &hostname,
+                                    &pycancellable))
+        return NULL;
+    
+    if (!pygio_check_cancellable(pycancellable, &cancellable))
+	return NULL;
+    
+    addr = g_resolver_lookup_by_name(G_RESOLVER(self->obj),
+                                     hostname, cancellable, &error);
+    
+    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
new file mode 100644
index 0000000..67ffbb2
--- /dev/null
+++ b/tests/test_gresolver.py
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+
+import os
+import unittest
+
+from common import gio
+
+
+class TestResolver(unittest.TestCase):
+    def setUp(self):
+        self.resolver = gio.resolver_get_default()
+
+    def test_resolver_lookup_by_name(self):
+        addresses = self.resolver.lookup_by_name("pygtk.org", cancellable=None)
+        self.failUnless(isinstance(addresses[0], gio.InetAddress))
+
+    def test_resolver_lookup_by_address(self):
+        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")
+        



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