libunbound.i (249140) | libunbound.i (276605) |
---|---|
1/* 2 * libounbound.i: pyUnbound module (libunbound wrapper for Python) 3 * 4 * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz) 5 * Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 6 * 7 * This software is open source. 8 * --- 30 unchanged lines hidden (view full) --- 39 #include <sys/socket.h> 40 #include <netinet/in.h> 41 #include <arpa/inet.h> 42 #include "libunbound/unbound.h" 43%} 44 45%pythoncode %{ 46 import encodings.idna | 1/* 2 * libounbound.i: pyUnbound module (libunbound wrapper for Python) 3 * 4 * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz) 5 * Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 6 * 7 * This software is open source. 8 * --- 30 unchanged lines hidden (view full) --- 39 #include <sys/socket.h> 40 #include <netinet/in.h> 41 #include <arpa/inet.h> 42 #include "libunbound/unbound.h" 43%} 44 45%pythoncode %{ 46 import encodings.idna |
47 48 # Ensure compatibility with older python versions 49 if 'bytes' not in vars(): 50 bytes = str 51 52 def ord(s): 53 if isinstance(s, int): 54 return s 55 return __builtins__.ord(s) |
|
47%} 48 49//%include "doc.i" 50%include "file.i" 51 52%feature("docstring") strerror "Convert error value to a human readable string." 53 54// ================================================================================ --- 499 unchanged lines hidden (view full) --- 554 domain name in text format (a string or unicode string). IDN domain name have to be passed as a unicode string. 555 :param rrtype: 556 type of RR in host order (optional argument). Default value is RR_TYPE_A (A class). 557 :param rrclass: 558 class of RR in host order (optional argument). Default value is RR_CLASS_IN (for internet). 559 :returns: * (int) 0 if OK, else error. 560 * (: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). 561 """ | 56%} 57 58//%include "doc.i" 59%include "file.i" 60 61%feature("docstring") strerror "Convert error value to a human readable string." 62 63// ================================================================================ --- 499 unchanged lines hidden (view full) --- 563 domain name in text format (a string or unicode string). IDN domain name have to be passed as a unicode string. 564 :param rrtype: 565 type of RR in host order (optional argument). Default value is RR_TYPE_A (A class). 566 :param rrclass: 567 class of RR in host order (optional argument). Default value is RR_CLASS_IN (for internet). 568 :returns: * (int) 0 if OK, else error. 569 * (: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). 570 """ |
562 if isinstance(name, unicode): #probably IDN 563 return _unbound.ub_resolve(self,idn2dname(name),rrtype,rrclass) 564 else: | 571 if isinstance(name, bytes): #probably IDN |
565 return _unbound.ub_resolve(self,name,rrtype,rrclass) | 572 return _unbound.ub_resolve(self,name,rrtype,rrclass) |
573 else: 574 return _unbound.ub_resolve(self,idn2dname(name),rrtype,rrclass) |
|
566 #parameters: struct ub_ctx *,char *,int,int, 567 #retvals: int,struct ub_result ** 568 569 def resolve_async(self,name,mydata,callback,rrtype=RR_TYPE_A,rrclass=RR_CLASS_IN): 570 """Perform resolution and validation of the target name. 571 572 Asynchronous, after a while, the callback will be called with your data and the result. 573 If an error happens during processing, your callback will be called with error set to a nonzero value (and result==None). --- 18 unchanged lines hidden (view full) --- 592 pass 593 594 **Parameters:** 595 * `mydata` - mydata object 596 * `status` - 0 when a result has been found 597 * `result` - the result structure. The result may be None, in that case err is set. 598 599 """ | 575 #parameters: struct ub_ctx *,char *,int,int, 576 #retvals: int,struct ub_result ** 577 578 def resolve_async(self,name,mydata,callback,rrtype=RR_TYPE_A,rrclass=RR_CLASS_IN): 579 """Perform resolution and validation of the target name. 580 581 Asynchronous, after a while, the callback will be called with your data and the result. 582 If an error happens during processing, your callback will be called with error set to a nonzero value (and result==None). --- 18 unchanged lines hidden (view full) --- 601 pass 602 603 **Parameters:** 604 * `mydata` - mydata object 605 * `status` - 0 when a result has been found 606 * `result` - the result structure. The result may be None, in that case err is set. 607 608 """ |
600 if isinstance(name, unicode): #probably IDN 601 return _unbound._ub_resolve_async(self,idn2dname(name),rrtype,rrclass,mydata,callback) 602 else: | 609 if isinstance(name, bytes): #probably IDN |
603 return _unbound._ub_resolve_async(self,name,rrtype,rrclass,mydata,callback) | 610 return _unbound._ub_resolve_async(self,name,rrtype,rrclass,mydata,callback) |
611 else: 612 return _unbound._ub_resolve_async(self,idn2dname(name),rrtype,rrclass,mydata,callback) |
|
604 #parameters: struct ub_ctx *,char *,int,int,void *,ub_callback_t, 605 #retvals: int, int 606 607 def wait(self): 608 """Wait for a context to finish with results. 609 610 Calls after the wait for you. After the wait, there are no more outstanding asynchronous queries. 611 --- 72 unchanged lines hidden (view full) --- 684 res = [] 685 slen = len(s) 686 if maxlen > 0: 687 slen = min(slen, maxlen) 688 689 idx = ofs 690 while (idx < slen): 691 complen = ord(s[idx]) | 613 #parameters: struct ub_ctx *,char *,int,int,void *,ub_callback_t, 614 #retvals: int, int 615 616 def wait(self): 617 """Wait for a context to finish with results. 618 619 Calls after the wait for you. After the wait, there are no more outstanding asynchronous queries. 620 --- 72 unchanged lines hidden (view full) --- 693 res = [] 694 slen = len(s) 695 if maxlen > 0: 696 slen = min(slen, maxlen) 697 698 idx = ofs 699 while (idx < slen): 700 complen = ord(s[idx]) |
692 res.append(s[idx+1:idx+1+complen]) | 701 # In python 3.x `str()` converts the string to unicode which is the expected text string type 702 res.append(str(s[idx+1:idx+1+complen])) |
693 idx += complen + 1 694 695 return res 696 697 def as_raw_data(self): 698 """Returns a list of RAW strings""" 699 return self.data 700 --- 58 unchanged lines hidden (view full) --- 759 return Py_None; 760 761 for (cnt=0,i=0;;i++,cnt++) 762 if (result->data[i] == 0) 763 break; 764 765 list = PyList_New(cnt); 766 for (i=0;i<cnt;i++) | 703 idx += complen + 1 704 705 return res 706 707 def as_raw_data(self): 708 """Returns a list of RAW strings""" 709 return self.data 710 --- 58 unchanged lines hidden (view full) --- 769 return Py_None; 770 771 for (cnt=0,i=0;;i++,cnt++) 772 if (result->data[i] == 0) 773 break; 774 775 list = PyList_New(cnt); 776 for (i=0;i<cnt;i++) |
767 PyList_SetItem(list, i, PyString_FromStringAndSize(result->data[i],result->len[i])); | 777 PyList_SetItem(list, i, PyBytes_FromStringAndSize(result->data[i],result->len[i])); |
768 769 return list; 770 } 771 772 PyObject* _packet() { | 778 779 return list; 780 } 781 782 PyObject* _packet() { |
773 return PyString_FromStringAndSize($self->answer_packet, $self->answer_len); | 783 return PyBytes_FromStringAndSize($self->answer_packet, $self->answer_len); |
774 } 775 776 %pythoncode %{ 777 def __init__(self): 778 raise Exception("This class can't be created directly.") 779 780 #__swig_destroy__ = _unbound.ub_resolve_free_dbg 781 __swig_destroy__ = _unbound._ub_resolve_free --- 160 unchanged lines hidden --- | 784 } 785 786 %pythoncode %{ 787 def __init__(self): 788 raise Exception("This class can't be created directly.") 789 790 #__swig_destroy__ = _unbound.ub_resolve_free_dbg 791 __swig_destroy__ = _unbound._ub_resolve_free --- 160 unchanged lines hidden --- |