Index: trunk/Makefile.in
===================================================================
--- trunk/Makefile.in	(revision 3523)
+++ trunk/Makefile.in	(working copy)
@@ -15,7 +15,8 @@
 includedir	= @includedir@
 doxygen		= @doxygen@
 pywrapdir       = ${srcdir}/contrib/python
-swig    	= @swig@
+swig		= @swig@
+swigpy_flags	= -python @SWIGPY3@
 python_site	=@PYTHON_SITE_PKG@
 pyldns_inst	=@PYLDNS@
 pyldns_uninst	=@PYLDNS@
@@ -172,7 +173,7 @@
 pyldns:		_ldns.la
 
 $(pywrapdir)/ldns_wrapper.c:	$(pywrapdir)/ldns.i $(wildcard $(pywrapdir)/*.i) $(LIBDNS_HEADERS) ldns/common.h ldns/util.h ldns/config.h
-	$(swig) -python -o $@ $(CPPFLAGS) $(PYTHON_CPPFLAGS) $<
+	$(swig) $(swigpy_flags) -o $@ $(CPPFLAGS) $(PYTHON_CPPFLAGS) $<
 
 ldns_wrapper.lo:	$(pywrapdir)/ldns_wrapper.c $(LIBDNS_HEADERS) ldns/common.h ldns/util.h ldns/config.h
 	$(COMP_LIB) -I./include/ldns $(PYTHON_CPPFLAGS) $(PYTHON_X_CFLAGS) -c $< -o $@
Index: trunk/acx_python.m4
===================================================================
--- trunk/acx_python.m4	(revision 3523)
+++ trunk/acx_python.m4	(working copy)
@@ -14,17 +14,19 @@
         fi
 
         if test -z "$PYTHON_VERSION"; then
-		PYTHON_VERSION=`$PYTHON -c "import sys, string; \
-			print string.split(sys.version)[[0]]"`
-	fi
+                PYTHON_VERSION=`$PYTHON -c "import sys; \
+                        ver = sys.version.split()[[0]]; \
+                        major,minor = ver.split('.')[[0:2]]; \
+                        print(major + '.' + minor)"`
+        fi
 
         #
         # Check for a version of Python >= 2.1.0
         #
         AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
-        ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                ver = string.split(sys.version)[[0]]; \
-                print ver >= '2.1.0'"`
+        ac_supports_python_ver=`$PYTHON -c "import sys; \
+                ver = sys.version.split()[[0]]; \
+                print(ver >= '2.1.0')"`
         if test "$ac_supports_python_ver" != "True"; then
                 if test -z "$PYTHON_NOVERSIONCHECK"; then
                         AC_MSG_RESULT([no])
@@ -49,8 +51,8 @@
         #
         if test -n "$1"; then
                 AC_MSG_CHECKING([for a version of Python $1])
-                ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                        ver = string.split(sys.version)[[0]]; \
+                ac_supports_python_ver=`$PYTHON -c "import sys; \
+                        ver = sys.version.split()[[0]]; \
                         print ver $1"`
                 if test "$ac_supports_python_ver" = "True"; then
                    AC_MSG_RESULT([yes])
@@ -86,7 +88,7 @@
         AC_MSG_CHECKING([for Python include path])
         if test -z "$PYTHON_CPPFLAGS"; then
                 python_path=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_inc();"`
+                        print(distutils.sysconfig.get_python_inc())"`
                 if test -n "${python_path}"; then
                         python_path="-I$python_path"
                 fi
@@ -103,22 +105,20 @@
                 # (makes two attempts to ensure we've got a version number
                 # from the interpreter)
                 py_version=`$PYTHON -c "from distutils.sysconfig import *; \
-                        from string import join; \
-                        print join(get_config_vars('VERSION'))"`
+                        print(get_config_vars('VERSION')[[0]])"`
                 if test "$py_version" = "[None]"; then
                         if test -n "$PYTHON_VERSION"; then
                                 py_version=$PYTHON_VERSION
                         else
                                 py_version=`$PYTHON -c "import sys; \
-                                        print sys.version[[:3]]"`
+                                        print(sys.version[[:3]])"`
                         fi
                 fi
 
                 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
-                        from string import join; \
-                        print '-L' + get_python_lib(0,1), \
-                        '-L' + os.path.dirname(get_python_lib(0,1)), \
-                        '-lpython';"`$py_version
+                        print('-L' + get_python_lib(0,1) + \
+                        ' -L' + os.path.dirname(get_python_lib(0,1)) + \
+                        ' -lpython')"`$py_version
         fi
         AC_MSG_RESULT([$PYTHON_LDFLAGS])
         AC_SUBST([PYTHON_LDFLAGS])
@@ -129,7 +129,7 @@
         AC_MSG_CHECKING([for Python site-packages path])
         if test -z "$PYTHON_SITE_PKG"; then
                 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_lib(1,0);"`
+                        print(distutils.sysconfig.get_python_lib(1,0))"`
         fi
         AC_MSG_RESULT([$PYTHON_SITE_PKG])
         AC_SUBST([PYTHON_SITE_PKG])
@@ -141,7 +141,7 @@
         if test -z "$PYTHON_EXTRA_LIBS"; then
            PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
                 conf = distutils.sysconfig.get_config_var; \
-                print conf('LOCALMODLIBS'), conf('LIBS')"`
+                print(conf('LOCALMODLIBS') + conf('LIBS'))"`
         fi
         AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
         AC_SUBST(PYTHON_EXTRA_LIBS)
@@ -153,7 +153,7 @@
         if test -z "$PYTHON_EXTRA_LDFLAGS"; then
                 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
                         conf = distutils.sysconfig.get_config_var; \
-                        print conf('LINKFORSHARED')"`
+                        print(conf('LINKFORSHARED'))"`
         fi
         AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
         AC_SUBST(PYTHON_EXTRA_LDFLAGS)
Index: trunk/configure.ac
===================================================================
--- trunk/configure.ac	(revision 3523)
+++ trunk/configure.ac	(working copy)
@@ -94,7 +94,9 @@
    ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
    AC_PYTHON_DEVEL
    if test ! -z "$PYTHON_VERSION"; then
-        if test `$PYTHON -c "print '$PYTHON_VERSION' >= '2.4.0'"` = "False"; then
+        if test `$PYTHON -c "import sys; \
+            ver = sys.version.split()[[0]]; \
+            print(ver >= '2.4.0')"` = "False"; then
                 AC_ERROR([Python version >= 2.4.0 is required])
         fi
 	# Have Python
@@ -102,6 +104,13 @@
 	ldns_have_python=yes
    fi
 
+   # pass additional Python 3 option to swig
+   if test `$PYTHON -c "import sys; \
+       ver = sys.version.split()[[0]]; \
+       print(ver >= '3.0.0')"` = "True"; then
+       AC_SUBST(SWIGPY3, [-py3])
+   fi
+
    # check for swig
    if test x_$ldns_have_python != x_no; then
 	sinclude(ac_pkg_swig.m4)
Index: trunk/contrib/python/ldns_rdf.i
===================================================================
--- trunk/contrib/python/ldns_rdf.i	(revision 3523)
+++ trunk/contrib/python/ldns_rdf.i	(working copy)
@@ -32,8 +32,8 @@
 
 //automatic conversion of const ldns_rdf* parameter from string 
 %typemap(in,noblock=1) const ldns_rdf * (void* argp, $1_ltype tmp = 0, int res) {
-   if (PyString_Check($input)) {
-      tmp = ldns_dname_new_frm_str(PyString_AsString($input));
+   if (Python_str_Check($input)) {
+      tmp = ldns_dname_new_frm_str(SWIG_Python_str_AsChar($input));
       if (tmp == NULL) {
          %argument_fail(SWIG_TypeError, "char *", $symname, $argnum);
       }
Index: trunk/contrib/python/ldns.i
===================================================================
--- trunk/contrib/python/ldns.i	(revision 3523)
+++ trunk/contrib/python/ldns.i	(working copy)
@@ -101,6 +101,17 @@
 %include "ldns_packet.i"
 %include "ldns_resolver.i"
 %include "ldns_rr.i"
+
+%inline %{
+int Python_str_Check(PyObject *o) {
+#if PY_VERSION_HEX>=0x03000000
+  return PyUnicode_Check(o);
+#else
+  return PyString_Check(o);
+#endif
+}
+%}
+
 %include "ldns_rdf.i"
 %include "ldns_zone.i"
 %include "ldns_key.i"
Index: trunk/contrib/python/docs/source/examples/example2.py
===================================================================
--- trunk/contrib/python/docs/source/examples/example2.py	(revision 3523)
+++ trunk/contrib/python/docs/source/examples/example2.py	(working copy)
@@ -9,7 +9,7 @@
 argc = len(sys.argv)
 name = "www.nic.cz"
 if argc < 2:
-   print "Usage:", sys.argv[0], "domain [resolver_addr]"
+   print("Usage:", sys.argv[0], "domain [resolver_addr]")
    sys.exit(1)
 else:
    name = sys.argv[1]
@@ -33,13 +33,13 @@
 
    # Debug
    if debug:
-      print "NS returned:", pkt.get_rcode(), "(AA: %d AD: %d)" % ( pkt.ad(), pkt.ad() )
+      print("NS returned:", pkt.get_rcode(), "(AA: %d AD: %d)" % ( pkt.ad(), pkt.ad() ))
 
    # SERVFAIL indicated bogus name
    if pkt.get_rcode() is ldns.LDNS_RCODE_SERVFAIL:
-      print name, "is bogus"
+      print(name, "is bogus")
 
    # Check AD (Authenticated) bit
    if pkt.get_rcode() is ldns.LDNS_RCODE_NOERROR:
-      if pkt.ad(): print name, "is secure"
-      else:        print name, "is insecure"
+      if pkt.ad(): print(name, "is secure")
+      else:        print(name, "is insecure")
Index: trunk/contrib/python/Makefile
===================================================================
--- trunk/contrib/python/Makefile	(revision 3523)
+++ trunk/contrib/python/Makefile	(working copy)
@@ -61,7 +61,7 @@
 
 #for development only
 swig: ldns.i
-	swig -python -o ldns_wrapper.c -I../.. ldns.i
-	gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/local/include/python2.6 -I. -o ldns_wrapper.o
+	swig -python -py3 -o ldns_wrapper.c -I../.. ldns.i
+	gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python3.1 -I. -o ldns_wrapper.o
 	ld -shared ldns_wrapper.o -L../../.libs -lldns -o _ldns.so 
 
Index: trunk/contrib/python/examples/python3/ldns-buf.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-buf.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-buf.py	(revision 0)
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+
+import ldns
+
+buf = ldns.ldns_buffer(1024)
+buf.printf("Test buffer")
+print(buf)
+

Property changes on: trunk/contrib/python/examples/python3/ldns-buf.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-dnssec.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-dnssec.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-dnssec.py	(revision 0)
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import ldns
+import sys
+
+debug = True
+
+# Check args
+argc = len(sys.argv)
+name = "www.nic.cz"
+if argc < 2:
+   print("Usage:", sys.argv[0], "domain [resolver_addr]")
+   sys.exit(1)
+else:
+   name = sys.argv[1]
+
+# Create resolver
+resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
+resolver.set_dnssec(True)
+
+# Custom resolver
+if argc > 2:
+   # Clear previous nameservers
+   ns = resolver.pop_nameserver()
+   while ns != None:
+      ns = resolver.pop_nameserver()
+   ip = ldns.ldns_rdf.new_frm_str(sys.argv[2], ldns.LDNS_RDF_TYPE_A)
+   resolver.push_nameserver(ip)
+
+# Resolve DNS name
+pkt = resolver.query(name, ldns.LDNS_RR_TYPE_A, ldns.LDNS_RR_CLASS_IN)
+if pkt and pkt.answer():
+
+   # Debug
+   if debug:
+      print("NS returned:", pkt.get_rcode(), "(AA: %d AD: %d)" % ( pkt.ad(), pkt.ad() ))
+
+   # SERVFAIL indicated bogus name
+   if pkt.get_rcode() is ldns.LDNS_RCODE_SERVFAIL:
+      print(name, "is bogus")
+
+   # Check AD (Authenticated) bit
+   if pkt.get_rcode() is ldns.LDNS_RCODE_NOERROR:
+      if pkt.ad(): print(name, "is secure")
+      else:        print(name, "is insecure")

Property changes on: trunk/contrib/python/examples/python3/ldns-dnssec.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-axfr.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-axfr.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-axfr.py	(revision 0)
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+# vim:fileencoding=utf-8
+#
+# AXFR client with IDN (Internationalized Domain Names) support
+#
+
+import ldns
+import encodings.idna
+
+def utf2name(name):
+    return '.'.join([encodings.idna.ToASCII(a).decode("utf-8") for a in name.split('.')])
+def name2utf(name):
+    return '.'.join([encodings.idna.ToUnicode(a) for a in name.split('.')])
+
+
+resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
+
+#addr = ldns.ldns_get_rr_list_addr_by_name(resolver, "zone.nic.cz", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD);
+addr = resolver.get_addr_by_name("zone.nic.cz", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD);
+if (not addr):
+    raise Exception("Can't retrieve server address")
+
+print("Addr_by_name:",str(addr).replace("\n","; "))
+
+#remove all nameservers
+while resolver.pop_nameserver(): 
+    pass
+
+#insert server addr
+for rr in addr.rrs():
+    resolver.push_nameserver_rr(rr)
+
+#AXFR transfer
+status = resolver.axfr_start(utf2name("háčkyčárky.cz"), ldns.LDNS_RR_CLASS_IN)
+if status != ldns.LDNS_STATUS_OK:
+    raise Exception("Can't start AXFR. Error: %s" % ldns.ldns_get_errorstr_by_id(status))
+
+#Print results
+while True:
+    rr = resolver.axfr_next()
+    if not rr: 
+        break
+
+    rdf = rr.owner()
+    if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
+        print("RDF owner: type=",rdf.get_type_str(),"data=",name2utf(str(rdf)))
+    else:
+        print("RDF owner: type=",rdf.get_type_str(),"data=",str(rdf))
+    print("   RR type=", rr.get_type_str()," ttl=",rr.ttl())
+    for rdf in rr.rdfs():
+        if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
+            print("   RDF: type=",rdf.get_type_str(),"data=",name2utf(str(rdf)))
+        else:
+            print("   RDF: type=",rdf.get_type_str(),"data=",str(rdf))
+
+    print()

Property changes on: trunk/contrib/python/examples/python3/ldns-axfr.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-mx.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-mx.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-mx.py	(revision 0)
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+#
+# MX is a small program that prints out the mx records for a particular domain
+#
+import ldns
+
+resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
+
+pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
+
+if (pkt):
+    mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
+    if (mx):
+       mx.sort()
+       print(mx)

Property changes on: trunk/contrib/python/examples/python3/ldns-mx.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-mx1.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-mx1.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-mx1.py	(revision 0)
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+#
+# MX is a small program that prints out the mx records for a particular domain
+#
+import ldns
+
+dname = ldns.ldns_dname("nic.cz")
+print(dname)
+
+resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
+
+pkt = resolver.query(dname, ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
+
+if (pkt):
+    mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
+    if (mx):
+       mx.sort()
+       print(mx)

Property changes on: trunk/contrib/python/examples/python3/ldns-mx1.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-mx2.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-mx2.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-mx2.py	(revision 0)
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+#
+# MX is a small program that prints out the mx records for a particular domain
+#
+import ldns
+
+resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
+
+pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
+if (pkt) and (pkt.answer()):
+
+    for rr in pkt.answer().rrs():
+        if (rr.get_type() != ldns.LDNS_RR_TYPE_MX):
+            continue
+
+        rdf = rr.owner()
+        print(rdf," ",rr.ttl()," ",rr.get_class_str()," ",rr.get_type_str()," ", end=" ")
+        print(" ".join(str(rdf) for rdf in rr.rdfs()))
+

Property changes on: trunk/contrib/python/examples/python3/ldns-mx2.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-higher.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-higher.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-higher.py	(revision 0)
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+import ldns
+
+resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
+
+dnn = ldns.ldns_dname("www.google.com")
+print(dnn.get_type_str(), dnn)
+
+dna = ldns.ldns_rdf.new_frm_str("74.125.43.99",ldns.LDNS_RDF_TYPE_A)
+print(dna.get_type_str(), dna)
+
+name = resolver.get_name_by_addr(dna)
+if (not name): raise Exception("Can't retrieve server name")
+for rr in name.rrs():
+    print(rr)
+
+name = resolver.get_name_by_addr("74.125.43.99")
+if (not name): raise Exception("Can't retrieve server name")
+for rr in name.rrs():
+    print(rr)
+
+addr = resolver.get_addr_by_name(dnn)
+if (not addr): raise Exception("Can't retrieve server address")
+for rr in addr.rrs():
+    print(rr)
+
+addr = resolver.get_addr_by_name("www.google.com")
+if (not addr): raise Exception("Can't retrieve server address")
+for rr in addr.rrs():
+    print(rr)
+
+hosts = ldns.ldns_rr_list.new_frm_file("/etc/hosts")
+if (not hosts): raise Exception("Can't retrieve the content of file")
+for rr in hosts.rrs():
+    print(rr)
+

Property changes on: trunk/contrib/python/examples/python3/ldns-higher.py
___________________________________________________________________
Added: svn:executable
   + *

Index: trunk/contrib/python/examples/python3/ldns-newpkt.py
===================================================================
--- trunk/contrib/python/examples/python3/ldns-newpkt.py	(revision 0)
+++ trunk/contrib/python/examples/python3/ldns-newpkt.py	(revision 0)
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+import ldns
+
+pkt = ldns.ldns_pkt.new_query_frm_str("www.google.com",ldns.LDNS_RR_TYPE_ANY, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_QR | ldns.LDNS_AA)
+
+rra = ldns.ldns_rr.new_frm_str("www.google.com. IN A 192.168.1.1",300)
+rrb = ldns.ldns_rr.new_frm_str("www.google.com. IN TXT Some\ Description",300)
+
+list = ldns.ldns_rr_list()
+if (rra): list.push_rr(rra)
+if (rrb): list.push_rr(rrb)
+
+pkt.push_rr_list(ldns.LDNS_SECTION_ANSWER, list)
+
+print("Packet:")
+print(pkt)

Property changes on: trunk/contrib/python/examples/python3/ldns-newpkt.py
___________________________________________________________________
Added: svn:executable
   + *

