mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
- Fix swig and python examples for Python 3.x.
git-svn-id: file:///svn/unbound/trunk@3227 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
bc404518cf
commit
4cab831abc
11 changed files with 63 additions and 50 deletions
|
|
@ -1,3 +1,6 @@
|
|||
22 September 2014: Wouter
|
||||
- Fix swig and python examples for Python 3.x.
|
||||
|
||||
19 September 2014: Wouter
|
||||
- improve python configuration detection to build on Fedora 22.
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@
|
|||
|
||||
%pythoncode %{
|
||||
import encodings.idna
|
||||
|
||||
# Ensure compatibility with older python versions
|
||||
if 'bytes' not in vars():
|
||||
bytes = str
|
||||
|
||||
def ord(s):
|
||||
if isinstance(s, int):
|
||||
return s
|
||||
return __builtins__.ord(s)
|
||||
%}
|
||||
|
||||
//%include "doc.i"
|
||||
|
|
@ -559,10 +568,10 @@ Result: ['74.125.43.147', '74.125.43.99', '74.125.43.103', '74.125.43.104']
|
|||
:returns: * (int) 0 if OK, else error.
|
||||
* (:class:`ub_result`) the result data is returned in a newly allocated result structure. May be None on return, return value is set to an error in that case (out of memory).
|
||||
"""
|
||||
if isinstance(name, unicode): #probably IDN
|
||||
return _unbound.ub_resolve(self,idn2dname(name),rrtype,rrclass)
|
||||
else:
|
||||
if isinstance(name, bytes): #probably IDN
|
||||
return _unbound.ub_resolve(self,name,rrtype,rrclass)
|
||||
else:
|
||||
return _unbound.ub_resolve(self,idn2dname(name),rrtype,rrclass)
|
||||
#parameters: struct ub_ctx *,char *,int,int,
|
||||
#retvals: int,struct ub_result **
|
||||
|
||||
|
|
@ -597,10 +606,10 @@ Result: ['74.125.43.147', '74.125.43.99', '74.125.43.103', '74.125.43.104']
|
|||
* `result` - the result structure. The result may be None, in that case err is set.
|
||||
|
||||
"""
|
||||
if isinstance(name, unicode): #probably IDN
|
||||
return _unbound._ub_resolve_async(self,idn2dname(name),rrtype,rrclass,mydata,callback)
|
||||
else:
|
||||
if isinstance(name, bytes): #probably IDN
|
||||
return _unbound._ub_resolve_async(self,name,rrtype,rrclass,mydata,callback)
|
||||
else:
|
||||
return _unbound._ub_resolve_async(self,idn2dname(name),rrtype,rrclass,mydata,callback)
|
||||
#parameters: struct ub_ctx *,char *,int,int,void *,ub_callback_t,
|
||||
#retvals: int, int
|
||||
|
||||
|
|
@ -689,7 +698,8 @@ Result: ['74.125.43.147', '74.125.43.99', '74.125.43.103', '74.125.43.104']
|
|||
idx = ofs
|
||||
while (idx < slen):
|
||||
complen = ord(s[idx])
|
||||
res.append(s[idx+1:idx+1+complen])
|
||||
# In python 3.x `str()` converts the string to unicode which is the expected text string type
|
||||
res.append(str(s[idx+1:idx+1+complen]))
|
||||
idx += complen + 1
|
||||
|
||||
return res
|
||||
|
|
|
|||
Loading…
Reference in a new issue