From 11cc25fd53475e2addaa8d05c72ea3bc996874d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20=C5=A0imerda?= <psimerda@redhat.com>
Date: Mon, 22 Sep 2014 12:48:40 +0200
Subject: [PATCH 2/2] fix examples to mostly work with python 3.x

---
 libunbound/python/examples/async-lookup.py   |  6 +++---
 libunbound/python/examples/dns-lookup.py     |  4 ++--
 libunbound/python/examples/dnssec-valid.py   |  8 ++++----
 libunbound/python/examples/dnssec_test.py    | 14 +++++++-------
 libunbound/python/examples/example8-1.py     | 18 +++++++++---------
 libunbound/python/examples/idn-lookup.py     | 16 ++++++++--------
 libunbound/python/examples/mx-lookup.py      | 12 ++++++------
 libunbound/python/examples/ns-lookup.py      |  6 +++---
 libunbound/python/examples/reverse-lookup.py |  2 +-
 9 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/libunbound/python/examples/async-lookup.py b/libunbound/python/examples/async-lookup.py
index 52a2d3c..cbb8ea0 100644
--- a/libunbound/python/examples/async-lookup.py
+++ b/libunbound/python/examples/async-lookup.py
@@ -39,9 +39,9 @@ ctx = unbound.ub_ctx()
 ctx.resolvconf("/etc/resolv.conf")
 
 def call_back(my_data,status,result):
-    print "Call_back:", my_data
+    print("Call_back:", my_data)
     if status == 0 and result.havedata:
-        print "Result:", result.data.address_list
+        print("Result:", result.data.address_list)
         my_data['done_flag'] = True
 
 
@@ -53,4 +53,4 @@ while (status == 0) and (not my_data['done_flag']):
     time.sleep(0.1)
 
 if (status != 0):
-    print "Resolve error:", unbound.ub_strerror(status)
+    print("Resolve error:", unbound.ub_strerror(status))
diff --git a/libunbound/python/examples/dns-lookup.py b/libunbound/python/examples/dns-lookup.py
index 2821ed3..b3f4008 100644
--- a/libunbound/python/examples/dns-lookup.py
+++ b/libunbound/python/examples/dns-lookup.py
@@ -39,6 +39,6 @@ ctx.resolvconf("/etc/resolv.conf")
 
 status, result = ctx.resolve("www.nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:", result.data.address_list
+    print("Result:", result.data.address_list)
 elif status != 0:
-    print "Error:", unbound.ub_strerror(status)
+    print("Error:", unbound.ub_strerror(status))
diff --git a/libunbound/python/examples/dnssec-valid.py b/libunbound/python/examples/dnssec-valid.py
index 3e05ddd..5c3cad9 100644
--- a/libunbound/python/examples/dnssec-valid.py
+++ b/libunbound/python/examples/dnssec-valid.py
@@ -48,12 +48,12 @@ if os.path.isfile("keys"):
 status, result = ctx.resolve("www.nic.cz", RR_TYPE_A, RR_CLASS_IN)
 if status == 0 and result.havedata:
 
-    print "Result:", result.data.address_list
+    print("Result:", result.data.address_list)
 
     if result.secure:
-        print "Result is secure"
+        print("Result is secure")
     elif result.bogus:
-        print "Result is bogus"
+        print("Result is bogus")
     else:
-        print "Result is insecure"
+        print("Result is insecure")
 
diff --git a/libunbound/python/examples/dnssec_test.py b/libunbound/python/examples/dnssec_test.py
index 138e19b..0d62b9f 100644
--- a/libunbound/python/examples/dnssec_test.py
+++ b/libunbound/python/examples/dnssec_test.py
@@ -3,27 +3,27 @@ from unbound import ub_ctx, RR_TYPE_A, RR_TYPE_RRSIG, RR_TYPE_NSEC, RR_TYPE_NSEC
 import ldns
 
 def dnssecParse(domain, rrType=RR_TYPE_A):
-    print "Resolving domain", domain
+    print("Resolving domain", domain)
     s, r = resolver.resolve(domain)
-    print "status: %s, secure: %s, rcode: %s, havedata: %s, answer_len; %s" % (s, r.secure, r.rcode_str, r.havedata, r.answer_len)
+    print("status: %s, secure: %s, rcode: %s, havedata: %s, answer_len; %s" % (s, r.secure, r.rcode_str, r.havedata, r.answer_len))
     
     s, pkt = ldns.ldns_wire2pkt(r.packet)
     if s != 0:
         raise RuntimeError("Error parsing DNS packet")
 
     rrsigs = pkt.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_ANSWER)
-    print "RRSIGs from answer:", rrsigs
+    print("RRSIGs from answer:", rrsigs)
     
     rrsigs = pkt.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_AUTHORITY)
-    print "RRSIGs from authority:", rrsigs
+    print("RRSIGs from authority:", rrsigs)
     
     nsecs = pkt.rr_list_by_type(RR_TYPE_NSEC, ldns.LDNS_SECTION_AUTHORITY)
-    print "NSECs:", nsecs
+    print("NSECs:", nsecs)
     
     nsec3s = pkt.rr_list_by_type(RR_TYPE_NSEC3, ldns.LDNS_SECTION_AUTHORITY)
-    print "NSEC3s:", nsec3s
+    print("NSEC3s:", nsec3s)
     
-    print "---"
+    print("---")
 
 
 resolver = ub_ctx()
diff --git a/libunbound/python/examples/example8-1.py b/libunbound/python/examples/example8-1.py
index 6816da0..ca868e5 100644
--- a/libunbound/python/examples/example8-1.py
+++ b/libunbound/python/examples/example8-1.py
@@ -40,22 +40,22 @@ ctx.resolvconf("/etc/resolv.conf")
 
 status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.mx_list:
-        print "      priority:%d address:%s" % k
+        print("      priority:%d address:%s" % k)
 
 status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.address_list:
-        print "      address:%s" % k
+        print("      address:%s" % k)
 
 status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_NS, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.domain_list:
-        print "      host: %s" % k
+        print("      host: %s" % k)
 
diff --git a/libunbound/python/examples/idn-lookup.py b/libunbound/python/examples/idn-lookup.py
index 7cfdc9e..2170637 100644
--- a/libunbound/python/examples/idn-lookup.py
+++ b/libunbound/python/examples/idn-lookup.py
@@ -43,20 +43,20 @@ ctx.resolvconf("/etc/resolv.conf")
 #The unicode IDN string is automatically converted (if necessary)
 status, result = ctx.resolve(u"www.háčkyčárky.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.address_list:
-        print "      address:%s" % k
+        print("      address:%s" % k)
 
 status, result = ctx.resolve(u"háčkyčárky.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.mx_list_idn:
-        print "      priority:%d address:%s" % k
+        print("      priority:%d address:%s" % k)
 
 status, result = ctx.resolve(unbound.reverse('217.31.204.66')+'.in-addr.arpa', unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result.data:", result.data
+    print("Result.data:", result.data)
     for k in result.data.domain_list_idn:
-        print "      dname:%s" % k
+        print("      dname:%s" % k)
diff --git a/libunbound/python/examples/mx-lookup.py b/libunbound/python/examples/mx-lookup.py
index cdcd1b1..f83f690 100644
--- a/libunbound/python/examples/mx-lookup.py
+++ b/libunbound/python/examples/mx-lookup.py
@@ -40,14 +40,14 @@ ctx.resolvconf("/etc/resolv.conf")
 
 status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.mx_list:
-        print "      priority:%d address:%s" % k
+        print("      priority:%d address:%s" % k)
 
 status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.address_list:
-        print "      address:%s" % k
+        print("      address:%s" % k)
diff --git a/libunbound/python/examples/ns-lookup.py b/libunbound/python/examples/ns-lookup.py
index f9eafb2..bcd51de 100644
--- a/libunbound/python/examples/ns-lookup.py
+++ b/libunbound/python/examples/ns-lookup.py
@@ -40,8 +40,8 @@ ctx.resolvconf("/etc/resolv.conf")
 
 status, result = ctx.resolve("vutbr.cz", unbound.RR_TYPE_NS, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result:"
-    print "      raw data:", result.data
+    print("Result:")
+    print("      raw data:", result.data)
     for k in result.data.domain_list:
-        print "      host: %s" % k
+        print("      host: %s" % k)
 
diff --git a/libunbound/python/examples/reverse-lookup.py b/libunbound/python/examples/reverse-lookup.py
index 4d3e0bb..7e06844 100644
--- a/libunbound/python/examples/reverse-lookup.py
+++ b/libunbound/python/examples/reverse-lookup.py
@@ -39,5 +39,5 @@ ctx.resolvconf("/etc/resolv.conf")
 
 status, result = ctx.resolve(unbound.reverse("74.125.43.147") + ".in-addr.arpa.", unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN)
 if status == 0 and result.havedata:
-    print "Result.data:", result.data, result.data.domain_list
+    print("Result.data:", result.data, result.data.domain_list)
 
-- 
1.8.5.5

