[Python-modules-commits] [python-getdns] 01/09: Import python-getdns_0.5.0.orig.tar.gz

Scott Kitterman kitterman at moszumanska.debian.org
Tue Dec 29 19:45:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

kitterman pushed a commit to branch master
in repository python-getdns.

commit 36ce53646b7ea9e52b4696eff090b7cc183ce259
Author: Scott Kitterman <scott at kitterman.com>
Date:   Tue Dec 29 12:46:24 2015 -0500

    Import python-getdns_0.5.0.orig.tar.gz
---
 .gitignore                 |   1 +
 README.md                  |  42 ++-
 context.c                  | 899 ++++++++++++++++++++++++++++++++++-----------
 context_util.c             |  40 ++
 doc/conf.py                |   4 +-
 doc/functions.rst          | 244 +++++++-----
 doc/index.rst              |  68 +++-
 doc/response.rst           |  37 +-
 examples/async-get-ip.py   |  20 +-
 examples/get-general.py    |  10 +-
 examples/get-ip.py         |  12 +-
 examples/get-mx-ip.py      |  14 +-
 examples/get-ns-ip.py      |  18 +-
 examples/get-srv.py        |   7 +-
 examples/idn.py            |  20 +
 examples/print-context.py  |   2 +-
 examples/print-version.py  |   4 +-
 examples/query-gdns.py     |   6 +-
 examples/query-stubmode.py |   8 +-
 examples/simple.py         |   9 +-
 getdns.c                   | 257 +++++++++++--
 pygetdns.h                 |  23 +-
 pygetdns_util.c            | 293 +++++++++++----
 result.c                   |  60 ++-
 setup.py                   |  35 +-
 25 files changed, 1603 insertions(+), 530 deletions(-)

diff --git a/.gitignore b/.gitignore
index 07d887b..9c173f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ getdns.so
 *.save
 doc/_build/
 doc/_build/*
+TAGS
diff --git a/README.md b/README.md
index e658445..f67e035 100644
--- a/README.md
+++ b/README.md
@@ -6,11 +6,11 @@ Python bindings for getdns
 External dependencies
 =====================
 
-Built and tested against Python 2.7.  You will need to install
+Built and tested against Python 2.7 and Python 3.4.  You will need to install
 the Python headers and libraries - this is usually a package
 called "python-dev"
 
-Currently building against the getdns 0.1.3 release.
+Currently building against the getdns 0.3.1 release.
 getdns external dependencies include:
 
 * [libldns from NLnet Labs](https://www.nlnetlabs.nl/projects/ldns/) version 1.6.11 or later (ldns requires ope
@@ -49,6 +49,18 @@ people who are using the bindings should go ahead and install.
 python setup.py install
 ````
 
+We recently added Python 3 support.  To build, just invoke
+the Python 3 interpreter rather the Python 2 interpreter (on
+most systems this will be "python3").  
+
+```
+python3 setup.py build
+```
+You will need the
+Python 3 development environment ("python3-dev" or
+"python3-devel", most often).
+
+
 Documentation
 =============
 
@@ -60,18 +72,24 @@ source tree in doc/_build/html.  It is also available online at [readthedocs.org
 Changes from the earlier release
 ================================
 
-We've introduced a Context object with attributes and methods, with
-queries being Context methods.  Attributes can be assigned and read
-directly without using the getdns setters and getters.  For example,
+In addition to adding Python 3 support, we've changed the callback
+argument to the asynchronous methods to accept a callable by name,
+rather than as a literal string.
 
-```python
-import getdns.context
-my_context = getdns.Context()
-my_context.timeout = 1000
-print my_context.timeout
-```
+We're also now supporting a new transport_list attribute, an
+ordered (by preference) list of transport options, including
+TCP, UDP, TLS, and STARTTLS.
+
+There are also a number of bugfixes, including cleaning up
+after unbound zombies (this has been fixed in unbound as well
+but the code is not yet included in a distribution) and
+correct handling of strings encoded as getdns bindatas.
+
+Examples have been updated to work with both Python 2.x and
+Python 3.
 
-Please see the documentation for details on attributes and methods.
+Please see the documentation for details on new attributes 
+extensions, and methods.
 
 Examples
 ========
diff --git a/context.c b/context.c
index 2e0f1de..b31859e 100644
--- a/context.c
+++ b/context.c
@@ -27,9 +27,12 @@
 
 #include <Python.h>
 #include <getdns/getdns.h>
+#include <getdns/getdns_ext_libevent.h>
+#include <getdns/getdns_extra.h>
 #include <arpa/inet.h>
 #include <event2/event.h>
 #include <getdns/getdns_ext_libevent.h>
+#include <sys/wait.h>
 #include "pygetdns.h"
 
 int
@@ -68,12 +71,14 @@ void
 context_dealloc(getdns_ContextObject *self)
 {
     getdns_context *context;
+    int status;
 
     if ((context = PyCapsule_GetPointer(self->py_context, "context")) == NULL)  {
         return;
     }
     Py_XDECREF(self->py_context);
     getdns_context_destroy(context);
+    (void)wait(&status);        /* reap the process spun off by unbound */
     return;
 }
 
@@ -84,11 +89,19 @@ context_set_timeout(getdns_context *context, PyObject *py_value)
     getdns_return_t ret;
     uint64_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long)(value = PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long)(value = PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -101,16 +114,54 @@ context_set_timeout(getdns_context *context, PyObject *py_value)
 
 
 int
+context_set_idle_timeout(getdns_context *context, PyObject *py_value)
+{
+    getdns_return_t ret;
+    uint64_t value;
+    
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
+    if (!PyInt_Check(py_value))  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+#if PY_MAJOR_VERSION >= 3
+    if ((long)(value = PyLong_AsLong(py_value)) < 0)  {
+#else
+    if ((long)(value = PyInt_AsLong(py_value)) < 0)  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+    if ((ret = getdns_context_set_idle_timeout(context, value)) != GETDNS_RETURN_GOOD)  {
+        PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+        return -1;
+    }
+    return 0;
+}
+
+
+int
 context_set_resolution_type(getdns_context *context, PyObject *py_value)
 {
     getdns_return_t ret;
     getdns_resolution_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long long)(value = (getdns_resolution_t)PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long long)(value = (getdns_resolution_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -126,22 +177,35 @@ context_set_resolution_type(getdns_context *context, PyObject *py_value)
 }
 
 
+#if 0                           /* commenting this out for the time being, delete later */
 int
 context_set_dns_transport(getdns_context *context, PyObject *py_value)
 {
     getdns_return_t ret;
     getdns_transport_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long long)(value = (getdns_transport_t)PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long long)(value = (getdns_transport_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
     if ((value < GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP) ||
+#if defined(WITH_TLS)
+        (value > GETDNS_TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN))  {
+#else        
         (value > GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -151,23 +215,32 @@ context_set_dns_transport(getdns_context *context, PyObject *py_value)
     }
     return 0;
 }
-                                   
+#endif                                   
 
 int
 context_set_limit_outstanding_queries(getdns_context *context, PyObject *py_value)
 {
     getdns_return_t ret;
-    uint16_t value;
+    long value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
-    if ((value = PyInt_AsLong(py_value)) < 0)  {
+#if PY_MAJOR_VERSION >= 3
+    if ((value = PyLong_AsLong(py_value)) < 0)  {
+#else
+      if ((value = PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
-    if ((ret = getdns_context_set_limit_outstanding_queries(context, value)) != GETDNS_RETURN_GOOD)  {
+      if ((ret = getdns_context_set_limit_outstanding_queries(context, (uint16_t) value)) !=
+          GETDNS_RETURN_GOOD)  {
         PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
         return -1;
     }
@@ -181,11 +254,19 @@ context_set_follow_redirects(getdns_context *context, PyObject *py_value)
     getdns_return_t ret;
     uint64_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long)(value = PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long)(value = PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -208,11 +289,19 @@ context_set_append_name(getdns_context *context, PyObject *py_value)
     getdns_return_t ret;
     uint64_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long)(value = PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long)(value = PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -252,11 +341,19 @@ context_set_suffix(getdns_context *context, PyObject *py_value)
         getdns_bindata value;
 
         if ((a_value = PyList_GetItem(py_value, (Py_ssize_t)i)) != NULL)  {
+#if PY_MAJOR_VERSION >= 3
+            if (!PyUnicode_Check(a_value))  {
+#else
             if (!PyString_Check(a_value))  {
+#endif
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
+#if PY_MAJOR_VERSION >= 3
+            value.data = (uint8_t *)strdup(PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(a_value), "ascii", NULL)));
+#else
             value.data = (uint8_t *)strdup(PyString_AsString(a_value));
+#endif
             value.size = strlen((char *)value.data);
             getdns_list_set_bindata(values, (size_t)i, &value);
         }  else  {
@@ -278,11 +375,19 @@ context_set_dnssec_allowed_skew(getdns_context *context, PyObject *py_value)
     getdns_return_t ret;
     uint32_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long)(value = (uint32_t)PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long)(value = (uint32_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -300,11 +405,19 @@ context_set_edns_maximum_udp_payload_size(getdns_context *context, PyObject *py_
     getdns_return_t ret;
     uint16_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((long)(value = PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((long)(value = PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -323,11 +436,19 @@ context_set_edns_extended_rcode(getdns_context *context, PyObject *py_value)
     getdns_return_t ret;
     uint8_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((value = (uint8_t)PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((value = (uint8_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -341,16 +462,123 @@ context_set_edns_extended_rcode(getdns_context *context, PyObject *py_value)
 
 
 int
+context_set_tls_authentication(getdns_context *context, PyObject *py_value)  
+{
+    getdns_return_t ret;
+    getdns_tls_authentication_t value;
+
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
+    if (!PyInt_Check(py_value))  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+#if PY_MAJOR_VERSION >= 3
+    if ((value = (getdns_tls_authentication_t)PyLong_AsLong(py_value)) < 0)  {
+#else
+    if ((value = (getdns_tls_authentication_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+    if ((ret = getdns_context_set_tls_authentication(context, value))
+        != GETDNS_RETURN_GOOD)  {
+        PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+        return -1;
+    }
+    return 0;
+}
+
+
+#if GETDNS_NUMERIC_VERSION > 0x00050000
+int
+context_set_tls_query_padding_blocksize(getdns_context *context, PyObject *py_value)  
+{
+    getdns_return_t ret;
+    uint16_t value;
+
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
+    if (!PyInt_Check(py_value))  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    } 
+#if PY_MAJOR_VERSION >= 3
+    if ((value = (uint16_t)PyLong_AsLong(py_value)) < 0)  {
+#else
+    if ((value = (uint16_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+    if ((ret = getdns_context_set_tls_query_padding_blocksize(context, value))
+        != GETDNS_RETURN_GOOD)  {
+        PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+        return -1;
+    }
+    return 0;
+}
+#endif
+
+#if GETDNS_NUMERIC_VERSION > 0x00050000
+int
+context_set_edns_client_subnet_private(getdns_context *context, PyObject *py_value)
+{
+    getdns_return_t ret;
+    uint8_t value;
+    
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
+    if (!PyInt_Check(py_value))  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+#if PY_MAJOR_VERSION >= 3
+    if ((value = (uint8_t)PyLong_AsLong(py_value)) < 0)  {
+#else
+    if ((value = (uint8_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+    if (! ((value == 0) || (value == 1)) )  {
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+    if ((ret = getdns_context_set_edns_client_subnet_private(context, (uint8_t)value))
+        != GETDNS_RETURN_GOOD)  {
+        PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+        return -1;
+    }
+    return 0;
+}
+#endif
+
+int
 context_set_edns_version(getdns_context *context, PyObject *py_value)
 {
     getdns_return_t ret;
     uint8_t value;
     
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((value = (uint8_t)PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((value = (uint8_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -369,11 +597,19 @@ context_set_edns_do_bit(getdns_context *context, PyObject *py_value)
     getdns_return_t ret;
     uint8_t value;
 
+#if PY_MAJOR_VERSION >= 3
+    if (!PyLong_Check(py_value))  {
+#else
     if (!PyInt_Check(py_value))  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
+#if PY_MAJOR_VERSION >= 3
+    if ((value = (uint8_t)PyLong_AsLong(py_value)) < 0)  {
+#else
     if ((value = (uint8_t)PyInt_AsLong(py_value)) < 0)  {
+#endif
         PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return -1;
     }
@@ -411,7 +647,11 @@ context_set_namespaces(getdns_context *context, PyObject *py_value)
         return -1;
     }
     for (i = 0 ; i < count ; i++)  {
+#if PY_MAJOR_VERSION >= 3
+        namespaces[i] = (getdns_namespace_t)PyLong_AsLong(PyList_GetItem(py_value, (Py_ssize_t)i));
+#else
         namespaces[i] = (getdns_namespace_t)PyInt_AsLong(PyList_GetItem(py_value, (Py_ssize_t)i));
+#endif
         if ((namespaces[i] < GETDNS_NAMESPACE_DNS) || (namespaces[i] > GETDNS_NAMESPACE_NIS))  {
             PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
             return -1;
@@ -458,11 +698,19 @@ context_set_dns_root_servers(getdns_context *context, PyObject *py_value)
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
+#if PY_MAJOR_VERSION >= 3
+            if (!PyUnicode_Check(str))  {
+#else
             if (!PyString_Check(str))  {
+#endif
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
+#if PY_MAJOR_VERSION >= 3
+            addr_type.data = (uint8_t *)strdup(PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(str), "ascii", NULL)));
+#else
             addr_type.data = (uint8_t *)strdup(PyString_AsString(str));
+#endif
             addr_type.size = strlen((char *)addr_type.data);
             if (strlen((char *)addr_type.data) != 4)  {
                 PyErr_SetString(getdns_error, GETDNS_RETURN_WRONG_TYPE_REQUESTED_TEXT);
@@ -482,11 +730,19 @@ context_set_dns_root_servers(getdns_context *context, PyObject *py_value)
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
-            if (!PyString_Check(str))  {
+#if PY_MAJOR_VERSION >= 3
+           if (!PyUnicode_Check(str))  {
+#else 
+           if (!PyString_Check(str))  {
+#endif
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
+#if PY_MAJOR_VERSION >= 3
+           if (inet_pton(domain, PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(str), "ascii", NULL)), buf) <= 0)  {
+#else
             if (inet_pton(domain, PyString_AsString(str), buf) <= 0)  {
+#endif
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
@@ -523,11 +779,19 @@ context_set_dnssec_trust_anchors(getdns_context *context, PyObject *py_value)
         getdns_bindata *value = 0;
 
         if ((an_address = PyList_GetItem(py_value, (Py_ssize_t)i)) != NULL)  {
+#if PY_MAJOR_VERSION >= 3
+            if (!PyUnicode_Check(an_address))  {
+#else
             if (!PyString_Check(an_address))  {
+#endif
                 PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
                 return -1;
             }
+#if PY_MAJOR_VERSION >= 3
+            value->data = (uint8_t *)strdup(PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(py_value), "ascii", NULL)));
+#else
             value->data = (uint8_t *)strdup(PyString_AsString(py_value));
+#endif
             value->size = strlen((char *)value->data);
             getdns_list_set_bindata(addresses, (size_t)i, value);
         }  else  {
@@ -588,6 +852,49 @@ context_set_upstream_recursive_servers(getdns_context *context, PyObject *py_val
 }
 
 
+int
+context_set_dns_transport_list(getdns_context *context, PyObject *py_value)
+{
+    getdns_return_t ret;
+    Py_ssize_t len;
+    getdns_transport_list_t *transports;
+    int  i;
+
+    if (!PyList_Check(py_value))  {
+        PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+        return -1;
+    }
+    len = PyList_Size(py_value);
+    if ((transports = (getdns_transport_list_t *)malloc(sizeof(getdns_transport_list_t)*(int)len)) ==
+        (getdns_transport_list_t *)0)  {
+        PyErr_SetString(getdns_error, "memory allocation error");
+        return -1;
+    }
+    for ( i = 0 ; i < (int)len ; i++ )  {
+        PyObject *py_transport;
+        long transport;
+        if ((py_transport = PyList_GetItem(py_value, (Py_ssize_t)i)) != NULL)  {
+            transport = PyLong_AsLong(py_transport);
+            if ((transport < GETDNS_TRANSPORT_UDP) || (transport > GETDNS_TRANSPORT_STARTTLS))  {
+                PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+                return -1;
+            }
+            transports[i] = transport;
+        }
+        else  {
+            PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
+            return -1;
+        }
+    }
+    if ((ret = getdns_context_set_dns_transport_list(context, (size_t)len, transports)) !=
+        GETDNS_RETURN_GOOD)  {
+        PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+        return -1;
+    }
+    return 0;
+}
+            
+
 PyObject *
 context_getattro(PyObject *self, PyObject *nameobj)
 {
@@ -598,8 +905,48 @@ context_getattro(PyObject *self, PyObject *nameobj)
     getdns_return_t ret;
     char *attrname;
 
+#if PY_MAJOR_VERSION >= 3
+    attrname = PyBytes_AsString(PyUnicode_AsEncodedString(PyObject_Str(nameobj), "ascii", NULL));
+#else
     attrname = PyString_AsString(nameobj);
+#endif
     context = PyCapsule_GetPointer(myself->py_context, "context");
+
+    if (!strncmp(attrname, "append_name", strlen("append_name")))  {
+        getdns_append_name_t value;
+        if ((ret = getdns_context_get_append_name(context, &value)) != GETDNS_RETURN_GOOD)  {
+            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+            return NULL;
+        }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)value);
+#else
+        return PyInt_FromLong((long)value);
+#endif
+    }
+
+    if (!strncmp(attrname, "dns_root_servers", strlen("dns_root_servers")))  {
+        PyObject *py_rootservers;
+        getdns_list *dns_root_servers;
+        if ((ret = getdns_context_get_dns_root_servers(context, &dns_root_servers)) !=
+            GETDNS_RETURN_GOOD)  {
+            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+            return NULL;
+        }
+        if (dns_root_servers == (getdns_list *)0)  {
+           Py_RETURN_NONE;
+        }
+        else  {
+        if ((py_rootservers = glist_to_plist(dns_root_servers)) == NULL)  {
+            PyObject *err_type, *err_value, *err_traceback;
+            PyErr_Fetch(&err_type, &err_value, &err_traceback);
+            PyErr_Restore(err_type, err_value, err_traceback);
+            return NULL;
+        }
+        return py_rootservers;
+        }
+    }
+
     api_info = getdns_context_get_api_information(context);
     if (!strncmp(attrname, "resolution_type", strlen("resolution_type")))  {
         uint32_t resolution_type;
@@ -607,7 +954,11 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)resolution_type);
+#else
         return PyInt_FromLong((long)resolution_type);
+#endif
     }
     if ((ret = getdns_dict_get_dict(api_info, "all_context", &all_context)) != GETDNS_RETURN_GOOD)  {
         PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
@@ -619,7 +970,13 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
-        return PyString_FromString((char *)implementation_string->data);
+#if PY_MAJOR_VERSION >= 3
+        return PyUnicode_FromStringAndSize((char *)implementation_string->data,
+                                           (Py_ssize_t)implementation_string->size);
+#else
+        return PyString_FromStringAndSize((char *)implementation_string->data,
+                                          (Py_ssize_t)implementation_string->size);
+#endif
     }
     if (!strncmp(attrname, "version_string", strlen("version_string")))  {
         getdns_bindata *version_string;
@@ -627,7 +984,13 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
-        return PyString_FromString((char *)version_string->data);
+#if PY_MAJOR_VERSION >= 3
+        return PyUnicode_FromStringAndSize((char *)version_string->data,
+                                           (Py_ssize_t)version_string->size);
+#else
+        return PyString_FromStringAndSize((char *)version_string->data,
+                                          (Py_ssize_t)version_string->size);
+#endif
     }
         
     if (!strncmp(attrname, "timeout", strlen("timeout")))  {
@@ -638,6 +1001,34 @@ context_getattro(PyObject *self, PyObject *nameobj)
         }
         return PyLong_FromLong((long)timeout);
     }
+    if (!strncmp(attrname, "idle_timeout", strlen("idle_timeout")))  {
+        uint64_t timeout;
+        if ((ret = getdns_context_get_idle_timeout(context, &timeout)) != GETDNS_RETURN_GOOD)  {
+            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+            return NULL;
+        }
+        return PyLong_FromLong((long)timeout);
+    }
+    if (!strncmp(attrname, "dns_transport_list", strlen("dns_transport_list")))  {
+        getdns_transport_list_t *transports;
+        PyObject *py_transports;
+        size_t transport_count;
+        int i;
+        if ((ret = getdns_context_get_dns_transport_list(context, &transport_count, &transports)) != 
+            GETDNS_RETURN_GOOD)  {
+            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+            return NULL;
+        }
+        if ((py_transports = PyList_New((Py_ssize_t)transport_count)) == NULL)  {
+            PyErr_SetString(getdns_error, "Could not create PyList");
+            return NULL;
+        }
+        for ( i = 0 ; i < transport_count ; i++ )  {
+            PyList_SetItem(py_transports, (Py_ssize_t)i, PyLong_FromLong((long)transports[i]));
+        }
+        return py_transports;
+    }
+#if 0
     if (!strncmp(attrname, "dns_transport", strlen("dns_transport")))  {
         uint32_t dns_transport;
         if ((ret = getdns_dict_get_int(all_context, "dns_transport", &dns_transport)) !=
@@ -645,8 +1036,13 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)dns_transport);
+#else
         return PyInt_FromLong((long)dns_transport);
+#endif
     }
+#endif    
     if (!strncmp(attrname, "limit_outstanding_queries", strlen("limit_outstanding_queries")))  {
         uint32_t limit_outstanding_queries;
         if ((ret = getdns_dict_get_int(all_context, "limit_outstanding_queries",
@@ -655,27 +1051,70 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong(limit_outstanding_queries);
+#else
         return PyInt_FromLong(limit_outstanding_queries);
+#endif
     }
-    if (!strncmp(attrname, "follow_redirects", strlen("follow_redirects")))  {
-        uint32_t follow_redirects;
-        if ((ret = getdns_dict_get_int(all_context, "follow_redirects",
-                                       &follow_redirects)) !=
+#if GETDNS_NUMERIC_VERSION > 0x00050000
+    if (!strncmp(attrname, "tls_query_padding_blocksize", strlen("tls_query_padding_blocksize")))  {
+        uint16_t tls_query_padding_blocksize;
+        if ((ret = getdns_context_get_tls_query_padding_blocksize(context, &tls_query_padding_blocksize)) !=
             GETDNS_RETURN_GOOD)  {
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
-        return PyInt_FromLong(follow_redirects);
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)tls_query_padding_blocksize);
+#else
+        return PyInt_FromLong((long)tls_query_padding_blocksize);
+#endif
+    }
+#endif
+#if GETDNS_NUMERIC_VERSION > 0x00050000
+    if (!strncmp(attrname, "edns_client_subnet_private", strlen("edns_client_subnet_private")))  {
+        uint8_t edns_client_subnet_private;
+        if ((ret = getdns_context_get_edns_client_subnet_private(context, &edns_client_subnet_private)) !=
+            GETDNS_RETURN_GOOD)  {
+            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+            return NULL;
+        }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)edns_client_subnet_private);
+#else
+        return PyInt_FromLong((long)edns_client_subnet_private);
+#endif
+    }
+#endif
+#if GETDNS_NUMERIC_VERSION > 0x00050000
+    if (!strncmp(attrname, "tls_authentication", strlen("tls_authentication")))  {
+        getdns_tls_authentication_t value;
+        if ((ret = getdns_context_get_tls_authentication(context, &value)) !=
+            GETDNS_RETURN_GOOD)  {
+            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
+            return NULL;
+        }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)value);
+#else
+        return PyInt_FromLong((long)value);
+#endif
     }
-    if (!strncmp(attrname, "append_name", strlen("append_name")))  {
-        uint32_t append_name;
-        if ((ret = getdns_dict_get_int(all_context, "append_name",
-                                       &append_name)) !=
+#endif
+    if (!strncmp(attrname, "follow_redirects", strlen("follow_redirects")))  {
+        uint32_t follow_redirects;
+        if ((ret = getdns_dict_get_int(all_context, "follow_redirects",
+                                       &follow_redirects)) !=
             GETDNS_RETURN_GOOD)  {
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
-        return PyInt_FromLong(append_name);
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong(follow_redirects);
+#else
+        return PyInt_FromLong(follow_redirects);
+#endif
     }
     if (!strncmp(attrname, "dnssec_allowed_skew", strlen("dnssec_allowed_skew")))  {
         uint32_t dnssec_allowed_skew;
@@ -684,7 +1123,11 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)dnssec_allowed_skew);
+#else
         return PyInt_FromLong((long)dnssec_allowed_skew);
+#endif
     }
     if (!strncmp(attrname, "edns_maximum_udp_payload_size", strlen("edns_maximum_udp_payload_size")))  {
         uint32_t edns_maximum_udp_payload_size;
@@ -694,7 +1137,11 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)edns_maximum_udp_payload_size);
+#else
         return PyInt_FromLong((long)edns_maximum_udp_payload_size);
+#endif
     }
     if (!strncmp(attrname, "edns_extended_rcode", strlen("edns_extended_rcode")))  {
         uint32_t edns_extended_rcode;
@@ -704,7 +1151,11 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)edns_extended_rcode);
+#else
         return PyInt_FromLong((long)edns_extended_rcode);
+#endif
     }
     if (!strncmp(attrname, "edns_version", strlen("edns_version")))  {
         uint32_t edns_version;
@@ -714,7 +1165,11 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)edns_version);
+#else
         return PyInt_FromLong((long)edns_version);
+#endif
     }
     if (!strncmp(attrname, "edns_do_bit", strlen("edns_do_bit")))  {
         uint32_t edns_do_bit;
@@ -724,7 +1179,11 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
+#if PY_MAJOR_VERSION >= 3
+        return PyLong_FromLong((long)edns_do_bit);
+#else
         return PyInt_FromLong((long)edns_do_bit);
+#endif
     }
     if (!strncmp(attrname, "namespaces", strlen("namespaces")))  {
         PyObject *py_namespaces;
@@ -751,34 +1210,17 @@ context_getattro(PyObject *self, PyObject *nameobj)
             PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
         return py_suffix;
     }
-    if (!strncmp(attrname, "dns_root_servers", strlen("dns_root_servers")))  {
-        PyObject *py_rootservers;
-        getdns_list *dns_root_servers;
-        getdns_return_t ret;
-        if ((ret = getdns_dict_get_list(all_context, "dns_root_servers", &dns_root_servers)) !=
-            GETDNS_RETURN_GOOD)  {
-            PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
-            return NULL;
-        }
-        if ((py_rootservers = glist_to_plist(dns_root_servers)) == NULL)  {
-            PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
-        }
-        return py_rootservers;
-    }
     if (!strncmp(attrname, "upstream_recursive_servers", strlen("upstream_recursive_servers")))  {
         PyObject *py_upstream_servers;
         getdns_list *upstream_list;
         getdns_return_t ret;
 
-        if ((ret = getdns_dict_get_list(all_context, "upstream_recursive_servers",
-                                        &upstream_list)) != GETDNS_RETURN_GOOD)  {
+        if ((ret = getdns_context_get_upstream_recursive_servers(context,
+                                                                 &upstream_list)) != GETDNS_RETURN_GOOD)  {
             PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
             return NULL;
         }
-#if 0
         if ((py_upstream_servers = glist_to_plist(upstream_list)) == NULL)  {
-#endif 
-        if ((py_upstream_servers = pythonify_address_list(upstream_list)) == NULL)  {
             PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
             return NULL;
         }
@@ -788,6 +1230,46 @@ context_getattro(PyObject *self, PyObject *nameobj)
... 2962 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-getdns.git



More information about the Python-modules-commits mailing list