diff options
Diffstat (limited to 'contrib/python')
| -rw-r--r-- | contrib/python/Changelog | 66 | ||||
| -rw-r--r-- | contrib/python/Makefile | 63 | ||||
| -rw-r--r-- | contrib/python/docs/source/conf.py | 4 | ||||
| -rw-r--r-- | contrib/python/docs/source/install.rst | 56 | ||||
| -rwxr-xr-x | contrib/python/examples/ldns-keygen.py | 2 | ||||
| -rwxr-xr-x | contrib/python/examples/python3/ldns-signzone.py | 65 | ||||
| -rwxr-xr-x | contrib/python/examples/test_buffer.py | 843 | ||||
| -rwxr-xr-x | contrib/python/examples/test_dname.py | 474 | ||||
| -rwxr-xr-x | contrib/python/examples/test_rdf.py | 805 | ||||
| -rw-r--r-- | contrib/python/examples/test_rr.py | 2383 | ||||
| -rw-r--r-- | contrib/python/file_py3.i | 3 | ||||
| -rw-r--r-- | contrib/python/ldns.i | 82 | ||||
| -rw-r--r-- | contrib/python/ldns_buffer.i | 665 | ||||
| -rw-r--r-- | contrib/python/ldns_dname.i | 617 | ||||
| -rw-r--r-- | contrib/python/ldns_dnssec.i | 25 | ||||
| -rw-r--r-- | contrib/python/ldns_packet.i | 2 | ||||
| -rw-r--r-- | contrib/python/ldns_rdf.i | 854 | ||||
| -rw-r--r-- | contrib/python/ldns_rr.i | 2507 |
18 files changed, 8161 insertions, 1355 deletions
diff --git a/contrib/python/Changelog b/contrib/python/Changelog new file mode 100644 index 000000000000..aaa57e13692b --- /dev/null +++ b/contrib/python/Changelog @@ -0,0 +1,66 @@ +1.6.16 2012-11-13 + * Fix typo in ldns_struct_pkt.opcode2str + +1.6.14 2012-10-23 + * Added rich comparison methods for ldns_dname, ldns_rdf, ldns_rr and + ldns_rr_list classes. + * Added deprecation warnings into ldns_rr.new_frm_fp() and + ldns_rr.new_frm_fp_l() and others. + * Fixed ldns_rr.set_rdf(), which may cause memory leaks, because it + returns new objects (in the scope of Python). Also it leaked memory, + when the call was not successful. + * Fixed ldns_get_rr_list_hosts_frm_file, marked as newobject. + * Fixed ldns_rr_list.cat() to return bool as mentioned in documentation. + * Fixed ldns_rr_list_cat_clone, marked as newobject. + * Fixed ldns_rr_list.new_frm_file(). Exception argument was invalid. + * Fixed ldns_rr_list.push_rr() to return bool as mentioned in + documentation. + * Fixed ldns_rr_list.push_rr_list() to return bool as mentioned in + documentation. + * Fixed ldns_rr_list.set_rr(), which caused memory corruption, double free + problems and memory leaks. (The wrapper used original function instead + of its push cloned variant which was missing.) + * Fixed ldns_rr_list.set_rr_count(), added python exception raise in order + to avoid assertion failure. + * Fixed ldns_rr_list.subtype_by_rdf(), marked as newobject. + * Added ldns_rr.to_canonical(), ldns_rr.is_question(), + ldns_rr.type_by_name(), ldns_rr.class_by_name(), ldns_rr_list.new(), + ldns_rr.set_question(). + * Modified ldns_rr_list.owner() and ldns_rr.owner(), now returns ldns_dname. + * Fixed assertion failures for several methods when receiving incorrect but + syntactically valid arguments (i.e., ldns_rr.a_address(), + ldns_rr.dnskey_algorithm(), ldns_rr.dnskey_flags(), + ldns_rr.dnskey_key(), ldns_rr.dnskey_protocol(), + ldns_rr.mx_exchange(), ldns_rr.mx_preference(), ldns_rr.ns_nsdname(), + ldns_rr.owner(), ldns_rr.rdf(), ldns_rr.rrsig_algorithm(), + ldns_rr.rrsig_expiration(), ldns_rr.rrsig_inception(), + ldns_rr.rrsig_keytag(), ldns_rr.rrsig_labels(), ldns_rr.rrsig_origttl(), + ldns_rr.rrsig_sig(), ldns_rr.rrsig_signame(), + ldns_rr.rrsig_typecovered(), ldns_rr_list.owner(), ldns_rr_list.rr()) + * Fixed ldns_rr.a_address(), which was asserting when called + on non A or AAAA type rr. Now returns None when fails. + * Added scripts for testing the basic functionality of the ldns_rr, + ldns_rr_descriptor and ldns_rr_list class code. + * Improved documentation of ldns_rr, ldns_rr_descriptor and ldns_rr_list. + * Fixed automatic conversion from Python string to ldns_rdf and + ldns_dname. Caused memory corruption when using Python 3. + * The Python 3 wrapper code now raises TypeError instead of ValueError + when receiving a non FILE * argument when it should be a FILE *. + * Fixed wrong handling of _ldns_rr_list_free() and + _ldns_rr_list_deep_free() when compiling with LDNS_DEBUG directive. + * Fixed malfunctioning ldns.ldns_rdf_new_frm_fp_l(). + * Fixed malfunctioning ldns_drf.absolute() and ldns_dname.absolute(). + * Marked several functions related to ldns_rdf and ldns_buffer as + returning new objects. + * Method operating on ldns_dnames and returning dname ldns_rdfs now + return ldns_dname instances. + * Improved documentation of ldns_buffer, ldns_rdf and ldns_dname + classes. + * Methods ldns_buffer.available() and ldns_buffer.available_at() now + return bool types as described in the documentation. + * Added scripts for testing the basic functionality of the ldns_buffer, + ldns_rdf, ldns_dname class code. + * Added deprecation warnings to ldns_rdf methods operating on dname + rdfs. The user is encouraged to converts dname ldns_rdfs to + ldns_dnames. + * Extended ldns_dname constructor to accept ldns_rdfs containing dnames. diff --git a/contrib/python/Makefile b/contrib/python/Makefile index c43970509a4e..927685764bbf 100644 --- a/contrib/python/Makefile +++ b/contrib/python/Makefile @@ -28,6 +28,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. + +.PHONY: help clean testenv test doc te bw bw3 sw sw3 + help: @echo "Please use \`make <target>' where <target> is one of" @echo " testenv to make test environment and run bash " @@ -41,27 +44,65 @@ help: _ldns.so: ../../Makefile $(MAKE) -C ../.. -../../.libs/ldns.so.1: ../../Makefile +../../.libs/libldns.so.1: ../../Makefile $(MAKE) -C ../.. clean: - rm -rdf examples/ldns + rm -rf examples/ldns rm -f _ldns.so ldns_wrapper.o $(MAKE) -C ../.. clean testenv: ../../.libs/libldns.so.1 _ldns.so - rm -rdf examples/ldns - cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1 && ls -la + rm -rf examples/ldns + cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../../../.libs/_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1 && ls -la @echo "Run a script by typing ./script_name.py" cd examples && LD_LIBRARY_PATH=ldns bash - rm -rdf examples/ldns + rm -rf examples/ldns + +test: ../../.libs/libldns.so.1 _ldns.so examples/test_buffer.py examples/test_rdf.py examples/test_dname.py examples/test_rr.py + @rm -rf examples/ldns + @cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../../../.libs/_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1 + @cd examples && LD_LIBRARY_PATH=ldns ./test_buffer.py 2>/dev/null + @cd examples && LD_LIBRARY_PATH=ldns ./test_rdf.py 2>/dev/null + @cd examples && LD_LIBRARY_PATH=ldns ./test_dname.py 2>/dev/null + @cd examples && LD_LIBRARY_PATH=ldns ./test_rr.py 2>/dev/null + @rm -rf examples/ldns -doc: ../../.libs/ldns.so.1 _ldns.so +doc: ../../.libs/libldns.so.1 _ldns.so + echo @VERSION_MAJOR@ + rm -f _ldns.so + ln -s ../../.libs/_ldns.so $(MAKE) -C docs html + rm -f _ldns.so + +# For development only: + +# Test environment, does not build the wrapper from dependencies. +te: + rm -rf examples/ldns + cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../../../.libs/_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1 && ls -la + @echo "Run a script by typing ./script_name.py" + cd examples && LD_LIBRARY_PATH=ldns bash + rm -rf examples/ldns + +# Builds Python 2 wrapper from present wrapper C code. +bw: + gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python2.7 -I. -o ldns_wrapper.o + mkdir -p ../../.libs + ld -shared ldns_wrapper.o -L../../.libs -lldns -o ../../.libs/_ldns.so + +# Builds Python 3 wrapper from present wrapper C code. +bw3: + gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python3.2 -I. -o ldns_wrapper.o + mkdir -p ../../.libs + ld -shared ldns_wrapper.o -L../../.libs -ldns -o ../../.libs/_ldns.so -#for development only -swig: ldns.i - 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 +# Builds Python 2 wrapper from interface file. +sw: ldns.i + swig -python -o ldns_wrapper.c -I../.. ldns.i + $(MAKE) bw +# Builds Python 3 wrapper from interface file. +sw3: ldns.i + swig -python -py3 -DPY3 -o ldns_wrapper.c -I../.. ldns.i + $(MAKE) bw3 diff --git a/contrib/python/docs/source/conf.py b/contrib/python/docs/source/conf.py index 22b73bcd712d..4d891543b1a3 100644 --- a/contrib/python/docs/source/conf.py +++ b/contrib/python/docs/source/conf.py @@ -43,9 +43,9 @@ copyright = '2009, Karel Slany, Zdenek Vasicek' # other places throughout the built documents. # # The short X.Y version. -version = '1.0' +version = '1.6' # The full version, including alpha/beta/rc tags. -release = '1.0.0' +release = '1.6.16' # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: diff --git a/contrib/python/docs/source/install.rst b/contrib/python/docs/source/install.rst index b3845b6e21b8..03d0f53facbf 100644 --- a/contrib/python/docs/source/install.rst +++ b/contrib/python/docs/source/install.rst @@ -3,44 +3,70 @@ Installation **Prerequisites** -Python 2.4 or higher, SWIG 1.3 or higher, GNU make +SWIG 1.3 and GNU make are required to build modules for Python 2.4 and higher +(but lower than 3). In order to build modules for Python 3.2 or higher, +SWIG in version 2.0.4 or higher is required. + +Note that Python 3.0 and 3.1 are not supported. + +In order to build this documentation the Sphinx Python documentation generator +is required. **Download** -You can download the source codes `here`_. -The latest release is 1.4.1, Jan 15, 2009. +The lates source codes can be downloaded from `here`_. -.. _here: ldns-1.4.1-py.tar.gz +.. _here: http://nlnetlabs.nl/projects/ldns/ **Compiling** -After downloading, you can compile the library by doing:: +After downloading the source code archive (this example uses +ldns-1.6.13.tar.gz), pyLDNS can be enabled and compiled by typing:: - > tar -xzf ldns-1.4.1-py.tar.gz - > cd ldns-1.4.1 + > tar -xzf ldns-1.6.13.tar.gz + > cd ldns-1.6.13 > ./configure --with-pyldns > make -You need GNU make to compile pyLDNS; SWIG and Python development libraries to compile extension module. +You need GNU make to compile pyLDNS; SWIG and Python development libraries to +compile the extension module. + +**Selecting Target Python Interpreter** + +By default, the pyLDNS module builds for the default Python interpreter (i.e., +the Python interpreter which can be accessed by just typing ``python`` in +the command line). If you desire to build the pyLDNS module for a different +Python version then you must specify the desired Python version by setting +the ``PYTHON_VERSION`` variable during the configure phase:: + > PYTHON_VERSION=3.2 ./configure --with-pyldns + > make + +By default the pyLDNS compiles from sources for a single Python interpreter. +Remember to execute scripts requiring pyLDNS in those Python interpreters which +have pyLDNS installed. **Testing** -If the compilation is successfull, you can test the python LDNS extension module by:: +If the compilation is successful, you can test the python LDNS extension module +by executing the commands:: > cd contrib/python > make testenv > ./ldns-mx.py -This will start a new shell, during which the symbolic links will be working. -When you exit the shell, then symbolic links will be deleted. +Again, remember to use the Python interpreter version which the pyLDNS module +has been compiled with. -In ``contrib/examples`` you can find many simple applications in python which demostrates the capabilities of LDNS library. +The commands will start a new shell, in which several symbolic links will be +set-up. When you exit the shell, then symbolic links will be deleted. + +In ``contrib/python/examples`` several simple Python scripts utilising pyLDNS +can be found. These scripts demonstrate the capabilities of the LDNS library. **Installation** -To install libraries and extension type:: +To install the libraries and it's extensions type:: - > cd ldns-1.4.1 + > cd ldns-1.6.13 > make install - diff --git a/contrib/python/examples/ldns-keygen.py b/contrib/python/examples/ldns-keygen.py index 3ddf41a946e6..71375fce205c 100755 --- a/contrib/python/examples/ldns-keygen.py +++ b/contrib/python/examples/ldns-keygen.py @@ -7,7 +7,7 @@ import ldns algorithm = ldns.LDNS_SIGN_DSA bits = 512 -ldns.ldns_init_random(open("/dev/random","rb"), (bits+7)//8) +ldns.ldns_init_random(open("/dev/urandom","rb"), (bits+7)//8) domain = ldns.ldns_dname("example.") diff --git a/contrib/python/examples/python3/ldns-signzone.py b/contrib/python/examples/python3/ldns-signzone.py new file mode 100755 index 000000000000..cac5d32165b5 --- /dev/null +++ b/contrib/python/examples/python3/ldns-signzone.py @@ -0,0 +1,65 @@ +#!/usr/bin/python +# This example shows how to sign a given zone file with private key + +import ldns +import sys, os, time + +#private key TAG which identifies the private key +#use ldns-keygen.py in order to obtain private key +keytag = 30761 + +# Read zone file +#------------------------------------------------------------- + +zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN) +soa = zone.soa() +origin = soa.owner() + +# Prepare keys +#------------------------------------------------------------- + +#Read private key from file +keyfile = open("key-%s-%d.private" % (origin, keytag), "r"); +key = ldns.ldns_key.new_frm_fp(keyfile) + +#Read public key from file +pubfname = "key-%s-%d.key" % (origin, keytag) +pubkey = None +if os.path.isfile(pubfname): + pubkeyfile = open(pubfname, "r"); + pubkey,_,_,_ = ldns.ldns_rr.new_frm_fp(pubkeyfile) + +if not pubkey: + #Create new public key + pubkey = key.key_to_rr() + +#Set key expiration +key.set_expiration(int(time.time()) + 365*60*60*24) #365 days + +#Set key owner (important step) +key.set_pubkey_owner(origin) + +#Insert DNSKEY RR +zone.push_rr(pubkey) + +# Sign zone +#------------------------------------------------------------- + +#Create keylist and push private key +keys = ldns.ldns_key_list() +keys.push_key(key) + +#Add SOA +signed_zone = ldns.ldns_dnssec_zone() +signed_zone.add_rr(soa) + +#Add RRs +for rr in zone.rrs().rrs(): + print("RR:", str(rr), end=" ") + signed_zone.add_rr(rr) + +added_rrs = ldns.ldns_rr_list() +status = signed_zone.sign(added_rrs, keys) +if (status == ldns.LDNS_STATUS_OK): + signed_zone.print_to_file(open("zone_signed.txt","w")) + diff --git a/contrib/python/examples/test_buffer.py b/contrib/python/examples/test_buffer.py new file mode 100755 index 000000000000..0baf76f6ab02 --- /dev/null +++ b/contrib/python/examples/test_buffer.py @@ -0,0 +1,843 @@ +#!/usr/bin/env python + +# +# ldns_buffer testing script. +# +# Do not use constructs that differ between Python 2 and 3. +# Use write on stdout or stderr. +# + + +import ldns +import sys +import os +import inspect + + +class_name = "ldns_buffer" +method_name = None +error_detected = False + + +def set_error(): + """ + Writes an error message and sets error flag. + """ + global class_name + global method_name + global error_detected + error_detected = True + sys.stderr.write("(line %d): malfunctioning method %s.\n" % \ + (inspect.currentframe().f_back.f_lineno, method_name)) + + +# Buffer creation. +capacity = 1024 + +#if not error_detected: +if True: + method_name = "ldns_buffer.__init__()" + try: + buf = ldns.ldns_buffer(1024) + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.__str__()" + buf.printf("abcedf") + try: + string = buf.__str__() + except: + set_error() + if not isinstance(string, str): + # Should be string. + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.at()" + try: + ret = buf.at(512) + except: + set_error() + try: + # Must raise TypeError. + ret = buf.at("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.available()" + try: + ret = buf.available(capacity) + except: + set_error() + if not isinstance(ret, bool): + # Should be bool. + set_error() + if not buf.available(capacity): + # Should return True. + set_error() + if buf.available(capacity + 1): + # Should return False. + set_error() + try: + # Must raise TypeError. + ret = buf.available("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# # Must raise ValueError. +# ret = buf.available("") +# set_error() +# except ValueError: +# pass +# except: +# set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.available_at()" + try: + ret = buf.available_at(512, capacity - 512) + except: + set_error() + if not isinstance(ret, bool): + # Should be bool. + set_error() + if not buf.available_at(512, capacity - 512): + # Should return True. + set_error() + if buf.available_at(512, capacity - 512 + 1): + # Should return False. + set_error() + try: + # Must raise TypeError. + ret = buf.available_at("", 1) + set_error() + except TypeError: + pass + except: + set_error() + try: + # Must raise TypeError. + ret = buf.available_at(1, "") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# # Must raise ValueError. +# ret = buf.available_at(-1, 512) +# set_error() +# except ValueError: +# pass +# except: +# set_error() +# try: +# # Must raise ValueError. +# ret = buf.available_at(512, -1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.begin()" + try: + ret = buf.begin() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.capacity()" + try: + ret = buf.capacity() + except: + set_error() + if not isinstance(ret, int): + # Should be int. + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.clear()" + try: + buf.clear() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.copy()" + sys.stderr.write("%s not tested.\n" % (method_name)) +# buf2 = ldns.ldns_buffer(10) +# buf2.printf("abcdef") +# try: +# buf.copy(buf2) +# print buf.capacity() +# print buf2.capacity() +# except: +# set_error() +# buf.printf("2") +# print buf + + +#if not error_detected: +if True: + method_name = "ldns_buffer.current()" + try: + ret = buf.current() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.end()" + try: + ret = buf.end() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.export()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + mehod_name = "ldns_buffer.flip()" + buf.printf("abcdef") + try: + buf.flip() + except: + set_error() +# if buf.remaining() != capacity: +# # Should be at beginning. +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.getc()" + buf.printf("a") + buf.rewind() + try: + ret = buf.getc() + except: + set_error() + if ret != ord("a"): + set_error() +# Test return value for -1 + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.invariant()" + try: + buf.invariant() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.limit()" + try: + ret = buf.limit() + except: + set_error() + if ret != capacity: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.position()" + try: + ret = buf.position() + except: + set_error() + if not isinstance(ret, int): + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.printf()" + try: + ret = buf.printf("abcdef") + except: + set_error() + if not isinstance(ret, int): + set_error() + try: + ret = buf.printf(10) + set_error() + except TypeError: + pass + except: + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_at()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_u16()" + buf.printf("aac") + buf.rewind() + try: + ret = buf.read_u16() + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != (ord("a") * 0x0101): + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_u16_at()" + buf.printf("abbc") + try: + ret = buf.read_u16_at(1) + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != (ord("b") * 0x0101): + set_error() + try: + ret = buf.read_u16_at("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# ret = buf.read_u16_at(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_u32()" + buf.printf("aaaac") + buf.rewind() + try: + ret = buf.read_u32() + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != (ord("a") * 0x01010101): + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_u32_at()" + buf.printf("abbbbc") + try: + ret = buf.read_u32_at(1) + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != (ord("b") * 0x01010101): + set_error() + try: + ret = buf.read_u32_at("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# ret = buf.read_u32_at(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_u8()" + buf.printf("ac") + buf.rewind() + try: + ret = buf.read_u8() + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != ord("a"): + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.read_u8_at()" + buf.printf("abc") + try: + ret = buf.read_u8_at(1) + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != ord("b"): + set_error() + try: + ret = buf.read_u8_at("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# ret = buf.read_u8_at(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.remaining()" + buf.printf("abcdef") + try: + ret = buf.remaining() + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != (capacity - 6): + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.remaining_at()" + buf.printf("abcdef") + try: + ret = buf.remaining_at(1) + except: + set_error() + if not isinstance(ret, int): + set_error() + if ret != (capacity - 1): + set_error() + try: + ret = buf.remaining_at("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# ret = buf.remaining_at(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.reserve()" + buf2 = ldns.ldns_buffer(512) + try: + ret = buf2.reserve(1024) + except: + set_error() + if not isinstance(ret, bool): + set_error() + try: + ret = buf2.reserve("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# ret = buf2.reserve(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.rewind()" + buf.printf("abcdef") + try: + buf.rewind() + except: + set_error() + if buf.position() != 0: + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.set_capacity()" + try: + ret = buf.set_capacity(capacity) + except: + set_error() + if not isinstance(ret, bool): + set_error() + try: + ret = buf.set_capacity("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# ret = buf.set_capacity(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.set_limit()" + try: + buf.set_limit(0) + except: + set_error() + try: + buf.set_limit("") + set_error() + except TypeError: + pass + except: + set_error() +# try: +# buf.set_limit(-1) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.set_position()" + try: + buf.set_position(0) + except: + set_error() + try: + buf.set_position("") + except TypeError: + pass + except: + set_error() +# try: +# buf.set_position(-1) +# except ValueError: +# pass +# except: +# set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.skip()" + try: + buf.skip(10) + except: + set_error() + try: + buf.skip(-1) + except: + set_error() + try: + buf.skip("") + set_error() + except TypeError: + pass + except: + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.status()" + try: + ret = buf.status() + except: + set_error() + # Returned status is an integer. + if not isinstance(ret, int): + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.status_ok()" + try: + ret = buf.status_ok() + except: + set_error() + if not isinstance(ret, bool): + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_at()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_string()" + try: + buf.write_string("abcdef") + except: + set_error() +# try: +# buf.write_sring(-1) +# set_error() +# except TypeError: +# pass +# except: +# set_error() + sys.stderr.write("%s not tested for parameter correctness.\n" % \ + (method_name)) + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_string_at()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_u16()" + try: + buf.write_u16(ord("b") * 0x0101) + except: + set_error() + try: + buf.write_u16("") + set_error() + except TypeError: + pass + except: + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_u16_at()" + buf.printf("a") + try: + buf.write_u16_at(1, ord("b") * 0x0101) + except: + set_error() + try: + buf.write_u16_at("", ord("b") * 0x0101) + set_error() + except TypeError: + pass + except: + set_error() +# try: +# buf.write_u16_at(-1, ord("b") * 0x0101) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + try: + buf.write_u16_at(1, "") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_u32()" + try: + buf.write_u32(ord("b") * 0x01010101) + except: + set_error() + try: + buf.write_u32("") + set_error() + except TypeError: + pass + except: + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_u32_at()" + buf.printf("a") + try: + buf.write_u32_at(1, ord("b") * 0x01010101) + except: + set_error() + try: + buf.write_u32_at("", ord("b") * 0x01010101) + set_error() + except TypeError: + pass + except: + set_error() +# try: +# buf.write_u32_at(-1, ord("b") * 0x01010101) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + try: + buf.write_u32_at(1, "") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_u8()" + try: + buf.write_u8(ord("b")) + except: + set_error() + try: + buf.write_u8("") + set_error() + except TypeError: + pass + except: + set_error() + buf.clear() + + +#if not error_detected: +if True: + method_name = "ldns_buffer.write_u8_at()" + buf.printf("a") + try: + buf.write_u8_at(1, ord("b")) + except: + set_error() + try: + buf.write_u8_at("", ord("b")) + set_error() + except TypeError: + pass + except: + set_error() +# try: +# buf.write_u8_at(-1, ord("b")) +# set_error() +# except ValueError: +# pass +# except: +# set_error() + try: + buf.write_u8_at(1, "") + set_error() + except TypeError: + pass + except: + set_error() + + +if not error_detected: + sys.stdout.write("%s: passed.\n" % (os.path.basename(__file__))) +else: + sys.stdout.write("%s: errors detected.\n" % (os.path.basename(__file__))) + sys.exit(1) diff --git a/contrib/python/examples/test_dname.py b/contrib/python/examples/test_dname.py new file mode 100755 index 000000000000..d69170737acc --- /dev/null +++ b/contrib/python/examples/test_dname.py @@ -0,0 +1,474 @@ +#!/usr/bin/env python + +# +# ldns_dname testing script. +# +# Do not use constructs that differ between Python 2 and 3. +# Use write on stdout or stderr. +# + + +import ldns +import sys +import os +import inspect + + +class_name = "ldns_dname" +method_name = None +error_detected = False +temp_fname = "tmp_dname.txt" + + +def set_error(): + """ + Writes an error message and sets error flag. + """ + global class_name + global method_name + global error_detected + error_detected = True + sys.stderr.write("(line %d): malfunctioning method %s.\n" % \ + (inspect.currentframe().f_back.f_lineno, method_name)) + + +#if not error_detected: +if True: + method_name = class_name + ".__init__()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "test.nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "217.31.205.50") + try: + dname = ldns.ldns_dname("www.nic.cz.") + if not isinstance(dname, ldns.ldns_dname): + set_error() + except: + set_error() + # + # Error when printing a dname wich was created fron an empty string. + # Must find out why. + # + try: + dname = ldns.ldns_dname(rdf1) + if not isinstance(dname, ldns.ldns_dname): + set_error() + except: + set_error() + # Test whether rdf1 and dname independent. + dname.cat(dname) + if dname.__str__() == rdf1.__str__(): + set_error() + # Test whether rdf1 and dname are dependent. + dname = ldns.ldns_dname(rdf1, clone=False) + dname.cat(dname) + if dname.__str__() != rdf1.__str__(): + set_error() + # Test whether constructs from non-dname rdfs. + try: + dname = ldns.ldns_dname(rdf2) + set_error() + except TypeError: + pass + except: + set_error() + try: + dname = ldns.ldns_dname(1) + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".[comparison operators]" + dn1 = ldns.ldns_dname("a.test") + dn2 = ldns.ldns_dname("b.test") + try: + ret = dn1 < dn2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = dn2 < dn1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = dn1 <= dn2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = dn2 <= dn1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = dn1 == dn2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = dn1 == dn1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = dn1 != dn2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = dn1 != dn1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = dn1 > dn2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = dn2 > dn1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = dn1 >= dn2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = dn2 >= dn1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".absolute()" + dname = ldns.ldns_dname("www.nic.cz.") + try: + ret = dname.absolute() + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".cat()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "test.nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "217.31.205.50") + dname = ldns.ldns_dname("www.nic.cz.") + try: + ret = dname.cat(dname) + if ret != ldns.LDNS_STATUS_OK: + set_error() + if dname.__str__() != "www.nic.cz.www.nic.cz.": + set_error() + except: + set_error() + try: + ret = dname.cat(rdf1) + if ret != ldns.LDNS_STATUS_OK: + set_error() + if dname.__str__() != "www.nic.cz.www.nic.cz.test.nic.cz.": + set_error() + except: + set_error() + try: + ret = dname.cat(rdf2) + if ret == ldns.LDNS_STATUS_OK: + set_error() + except: + set_error() + try: + ret = dname.cat("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".cat_clone()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "test.nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "217.31.205.50") + dname = ldns.ldns_dname("www.nic.cz.") + try: + ret = dname.cat_clone(dname) + if not isinstance(ret, ldns.ldns_dname): + set_error() + if ret.__str__() != "www.nic.cz.www.nic.cz.": + set_error() + except: + set_error() + try: + ret = dname.cat_clone(rdf1) + if not isinstance(ret, ldns.ldns_dname): + set_error() + if ret.__str__() != "www.nic.cz.test.nic.cz.": + set_error() + except: + set_error() + try: + ret = dname.cat_clone(rdf2) + if ret != None: + set_error() + except: + set_error() + try: + ret = dname.cat_clone("") + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".interval()" + dn1 = ldns.ldns_dname("a.ns.nic.cz.") + dn2 = ldns.ldns_dname("b.ns.nic.cz.") + dn3 = ldns.ldns_dname("c.ns.nic.cz.") + try: + ret = dn1.interval(dn2, dn3) + if ret != -1: + set_error() + except: + set_error() + try: + ret = dn2.interval(dn1, dn3) + if ret != 1: + set_error() + except: + set_error() + rdf4 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "d.ns.nic.cz.") + rdf5 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "194.0.12.1") + try: + ret = dn1.interval(dn2, rdf4) + if ret != -1: + set_error() + except: + set_error() + try: + ret = dn2.interval(dn1, rdf4) + if ret != 1: + set_error() + except: + set_error() + try: + ret = dn1.interval(dn2, rdf5) + set_error() + except Exception: + pass + except: + set_error() + try: + ret = dn1.interval(dn2, "") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".is_subdomain()" + dn1 = ldns.ldns_dname("nic.cz.") + dn2 = ldns.ldns_dname("www.nic.cz.") + rdf3 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = dn1.is_subdomain(dn2) + if not isinstance(ret, bool): + set_error() + if ret == True: + set_error() + ret = dn2.is_subdomain(dn1) + if ret != True: + set_error() + except: + set_error() + try: + ret = dn1.is_subdomain(rdf3) + if not isinstance(ret, bool): + set_error() + if ret == True: + set_error() + except: + set_error() + rdf4 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "194.0.12.1") + try: + ret = dn1.is_subdomain(rdf4) + if ret != False: + set_error() + except: + set_error() + try: + ret = dn1.is_subdomain("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".label()" + dn = ldns.ldns_dname("nic.cz.") + try: + ret = dn.label(0) + if not isinstance(ret, ldns.ldns_dname): + set_error() + except: + set_error() + try: + ret = dn.label(10) + if ret != None: + set_error() + except: + set_error() + try: + ret = dn.label("") + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".label_count()" + dn = ldns.ldns_dname("www.nic.cz.") + try: + ret = dn.label_count() + if not isinstance(ret, int): + set_error() + if ret != 3: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".left_chop()" + dn = ldns.ldns_dname("www.nic.cz.") + try: + ret = dn.left_chop() + if not isinstance(ret, ldns.ldns_dname): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".make_canonical()" + dn = ldns.ldns_dname("WWW.NIC.CZ.") + try: + dn.make_canonical() + if dn.__str__() != "www.nic.cz.": + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_rdf()" + # Tested via constructor call. + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_str()" + # Tested via constructor call. + + +#if not error_detected: +if True: + method_name = class_name + ".reverse()" + dn = ldns.ldns_dname("www.nic.cz.") + try: + ret = dn.reverse() + if not isinstance(ret, ldns.ldns_dname): + set_error() + if ret.__str__() != "cz.nic.www.": + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".write_to_buffer()" + dn = ldns.ldns_dname("www.nic.cz.") + buf = ldns.ldns_buffer(1024) + try: + ret = dn.write_to_buffer(buf) + if ret != ldns.LDNS_STATUS_OK: + set_error() + if buf.position() != 12: + set_error() + except: + set_error() + try: + ret = dn.write_to_buffer("") + except TypeError: + pass + except: + set_error() + + +if not error_detected: + sys.stdout.write("%s: passed.\n" % (os.path.basename(__file__))) +else: + sys.stdout.write("%s: errors detected.\n" % (os.path.basename(__file__))) + sys.exit(1) diff --git a/contrib/python/examples/test_rdf.py b/contrib/python/examples/test_rdf.py new file mode 100755 index 000000000000..4991288c83f2 --- /dev/null +++ b/contrib/python/examples/test_rdf.py @@ -0,0 +1,805 @@ +#!/usr/bin/env python + +# +# ldns_rdf testing script. +# +# Do not use constructs that differ between Python 2 and 3. +# Use write on stdout or stderr. +# + + +import ldns +import sys +import os +import inspect + + +class_name = "ldns_rdf" +method_name = None +error_detected = False +temp_fname = "tmp_rdf.txt" + + +def set_error(): + """ + Writes an error message and sets error flag. + """ + global class_name + global method_name + global error_detected + error_detected = True + sys.stderr.write("(line %d): malfunctioning method %s.\n" % \ + (inspect.currentframe().f_back.f_lineno, method_name)) + + +#if not error_detected: +if True: + method_name = class_name + ".__init__()" + try: + # Should raise an Exception + rdf = ldns.ldns_rdf() + set_error() + except Exception as e: + pass + + +#if not error_detected: +if True: + method_name = class_name + ".[comparison operators]" + rdf1 = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) + rdf2 = ldns.ldns_rdf.new_frm_str("1.1.1.1", ldns.LDNS_RDF_TYPE_A) + try: + ret = rdf1 < rdf2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rdf2 < rdf1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf1 <= rdf2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rdf2 <= rdf1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf1 == rdf2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf1 == rdf1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rdf1 != rdf2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rdf1 != rdf1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf1 > rdf2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf2 > rdf1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rdf1 >= rdf2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf2 >= rdf1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf_new()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_rdf_new_frm_data()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_rdf_new_frm_str()" + try: + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz") + except: + set_error() + try: + rdf = ldns.ldns_rdf_new_frm_str("", "www.nic.cz") + et_error() + except TypeError: + pass + except: + set_error() + try: + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, 1) + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf_new_frm_fp()" + f = open(temp_fname, "w") + f.write("217.31.205.50") + f.close() + f = open(temp_fname, "r") + try: + status, rdf = ldns.ldns_rdf_new_frm_fp(ldns.LDNS_RDF_TYPE_A, f) + if status != ldns.LDNS_STATUS_OK: + set_error() + if rdf == None: + set_error() + except: + set_error() + try: + # Reading past file end. + status, rdf = ldns.ldns_rdf_new_frm_fp(ldns.LDNS_RDF_TYPE_AAAA, f) + if status == ldns.LDNS_STATUS_OK: + set_error() + if rdf != None: + set_error() + except: + set_error() + f.close() + f = open(temp_fname, "r") + try: + status, rdf = ldns.ldns_rdf_new_frm_fp(ldns.LDNS_RDF_TYPE_AAAA, f) + if status != ldns.LDNS_STATUS_OK: + set_error() + if rdf != None: + set_error() + except: + set_error() + f.close() + os.remove(temp_fname) + try: + status, rdf = ldns.ldns_rdf_new_frm_fp("", f) + except TypeError: + pass + except: + set_error() + try: + status, rdf = ldns.ldns_rdf_new_frm_fp(ldns.LDNS_RDF_TYPE_AAAA, "") + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf_new_frm_fp_l()" + f = open(temp_fname, "w") + f.write("217.31.205.50\n194.0.12.1") + f.close() + f = open(temp_fname, "r") + try: + status, rdf, line = ldns.ldns_rdf_new_frm_fp_l(ldns.LDNS_RDF_TYPE_A, f) + if status != ldns.LDNS_STATUS_OK: + set_error() + if rdf == None: + set_error() + except: + set_error() + try: + status, rdf, line = ldns.ldns_rdf_new_frm_fp_l(ldns.LDNS_RDF_TYPE_A, f) + if status != ldns.LDNS_STATUS_OK: + set_error() + if rdf == None: + set_error() + except: + set_error() + try: + # Reading past file end. + status, rdf, line = ldns.ldns_rdf_new_frm_fp_l(ldns.LDNS_RDF_TYPE_A, f) + if status == ldns.LDNS_STATUS_OK: + set_error() + if rdf != None: + set_error() + except: + set_error() + f.close() + os.remove(temp_fname) + try: + status, rdf = ldns.ldns_rdf_new_frm_fp_l("", f) + except TypeError: + pass + except: + set_error() + try: + status, rdf = ldns.ldns_rdf_new_frm_fp_l(ldns.LDNS_RDF_TYPE_AAAA, "") + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_drf.absolute()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.absolute() + if not isinstance(ret, bool): + set_error() + if not ret: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.address_reverse()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "194.0.12.1") + try: + ret = rdf.address_reverse() + if ret == None: + set_error() + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_AAAA, "::1") + try: + ret = rdf.address_reverse() + if ret == None: + set_error() + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.address_reverse() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.cat()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "cz.") + try: + ret = rdf1.cat(rdf2) + if ret != ldns.LDNS_STATUS_OK: + set_error() + except: + set_error() + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf1.cat(rdf2) + if ret == ldns.LDNS_STATUS_OK: + set_error() + except: + set_error() + try: + ret = rdf2.cat(rdf1) + if ret == ldns.LDNS_STATUS_OK: + set_error() + except: + set_error() + try: + ret = rdf2.cat("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.cat_clone()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "cz.") + try: + ret = rdf1.cat_clone(rdf2) + if ret == None: + set_error() + except: + set_error() + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf1.cat_clone(rdf2) + if ret != None: + set_error() + except: + set_error() + try: + ret = rdf2.cat_clone(rdf1) + if ret != None: + set_error() + except: + set_error() + try: + ret = rdf2.cat_clone("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.clone()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.clone() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.data()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.data() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.dname_compare()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "nic.cz.") + try: + ret = rdf1.dname_compare(rdf2) + if ret != 1: + set_error() + except: + set_error() + try: + ret = rdf2.dname_compare(rdf1) + if ret != -1: + set_error() + except: + set_error() + try: + ret = rdf1.dname_compare(rdf1) + if ret != 0: + set_error() + except: + set_error() + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf1.dname_compare(rdf2) + set_error() + except Exception: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.dname_new_frm_str()" + try: + rdf = ldns.ldns_rdf.dname_new_frm_str("www.nic.cz.") + if rdf == None: + set_error() + except: + set_error() + try: + rdf = ldns.ldns_rdf.dname_new_frm_str("") + if rdf != None: + set_error() + except: + set_error() + try: + rdf = ldns.ldns_rdf.dname_new_frm_str(1) + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.get_type()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.get_type() + if not isinstance(ret, int): + set_error() + if ret != ldns.LDNS_RDF_TYPE_DNAME: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.get_type_str()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.get_type_str() + if not isinstance(ret, str): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.interval()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "a.ns.nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "b.ns.nic.cz.") + rdf3 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "c.ns.nic.cz.") + try: + ret = rdf1.interval(rdf2, rdf3) + if ret != -1: + set_error() + except: + set_error() + try: + ret = rdf2.interval(rdf1, rdf3) + if ret != 1: + set_error() + except: + set_error() + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "194.0.12.1") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "b.ns.nic.cz.") + rdf3 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "c.ns.nic.cz.") + try: + ret = rdf1.interval(rdf2, rdf3) + set_error() + except Exception: + pass + except: + set_error() + try: + ret = rdf2.interval("", rdf3) + set_error() + except TypeError: + pass + except: + set_error() + +#if not error_detected: +if True: + method_name = "ldns_rdf.is_subdomain()" + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "nic.cz.") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf1.is_subdomain(rdf2) + if not isinstance(ret, bool): + set_error() + if ret == True: + set_error() + ret = rdf2.is_subdomain(rdf1) + if ret != True: + set_error() + except: + set_error() + rdf1 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "194.0.12.1") + rdf2 = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf1.is_subdomain(rdf2) + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf2.is_subdomain(rdf1) + if ret != False: + set_error() + except: + set_error() + try: + ret = rdf2.is_subdomain("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.label()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.label(0) + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + try: + ret = rdf.label(10) + if ret != None: + set_error() + except: + set_error() + try: + ret = rdf.label("") + except TypeError: + pass + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf.label(0) + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.label_count()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.label_count() + if not isinstance(ret, int): + set_error() + if ret != 3: + set_error() + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf.label_count() + if not isinstance(ret, int): + set_error() + if ret != 0: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.left_chop()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.left_chop() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf.left_chop() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.make_canonical()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "WWW.NIC.CZ.") + try: + rdf.make_canonical() + if rdf.__str__() != "www.nic.cz.": + set_error() + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + rdf.make_canonical() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.new_frm_str()" + try: + rdf = ldns.ldns_rdf.new_frm_str("www.nic.cz.", ldns.LDNS_RDF_TYPE_DNAME) + except: + set_error() + try: + rdf = ldns.ldns_rdf.new_frm_str("www.nic.cz.", ldns.LDNS_RDF_TYPE_AAAA) + set_error() + except Exception: + pass + except: + set_error() + try: + rdf = ldns.ldns_rdf.new_frm_str("www.nic.cz.", ldns.LDNS_RDF_TYPE_AAAA, raiseException = False) + if rdf != None: + set_error() + except: + set_error() + try: + rdf = ldns.ldns_rdf.new_frm_str("", "www.nic.cz") + et_error() + except TypeError: + pass + except: + set_error() + try: + rdf = ldns.ldns_rdf.new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, 1) + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + f = open(temp_fname, "w") + try: + rdf.print_to_file(f) + except: + set_error() + f.close() + f = open(temp_fname, "r") + if f.read() != "127.0.0.1": + set_error() + f.close() + os.remove(temp_fname) + + +#if not error_detected: +if True: + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.reverse() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + if ret.__str__() != "cz.nic.www.": + set_error() + except: + set_error() + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A, "127.0.0.1") + try: + ret = rdf.reverse() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.set_data()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_rdf.set_size()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_rdf.set_type()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = "ldns_rdf.size()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + try: + ret = rdf.size() + if ret != 12: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.write_to_buffer()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "www.nic.cz.") + buf = ldns.ldns_buffer(1024) + try: + ret = rdf.write_to_buffer(buf) + if ret != ldns.LDNS_STATUS_OK: + set_error() + if buf.position() != 12: + set_error() + except: + set_error() + try: + ret = rdf.write_to_buffer("") + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = "ldns_rdf.write_to_buffer_canonical()" + rdf = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_DNAME, "WWW.NIC.CZ.") + buf = ldns.ldns_buffer(1024) + try: + ret = rdf.write_to_buffer_canonical(buf) + if ret != ldns.LDNS_STATUS_OK: + set_error() + if buf.position() != 12: + set_error() + except: + set_error() + try: + ret = rdf.write_to_buffer_canonical("") + except TypeError: + pass + except: + set_error() + + +if not error_detected: + sys.stdout.write("%s: passed.\n" % (os.path.basename(__file__))) +else: + sys.stdout.write("%s: errors detected.\n" % (os.path.basename(__file__))) + sys.exit(1) diff --git a/contrib/python/examples/test_rr.py b/contrib/python/examples/test_rr.py new file mode 100644 index 000000000000..b7bc1e0d9717 --- /dev/null +++ b/contrib/python/examples/test_rr.py @@ -0,0 +1,2383 @@ +#!/usr/bin/env python + +# +# ldns_rr and ldns_rr_list testing script. +# +# Do not use constructs that differ between Python 2 and 3. +# Use write on stdout or stderr. +# + + +import ldns +import sys +import os +import inspect + + +class_name = "ldns_rr" +method_name = None +error_detected = False +temp_fname = "tmp_rr.txt" + + +def set_error(): + """ + Writes an error message and sets error flag. + """ + global class_name + global method_name + global error_detected + error_detected = True + sys.stderr.write("(line %d): malfunctioning method %s.\n" % \ + (inspect.currentframe().f_back.f_lineno, method_name)) + + + +#if not error_detected: +if True: + method_name = class_name + ".[comparison operators]" + rr1 = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rr2 = ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1") + try: + ret = rr1 < rr2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr2 < rr1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rr1 <= rr2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr2 <= rr1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rr1 == rr2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rr1 == rr1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr1 != rr2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr1 != rr1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rr1 > rr2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rr2 > rr1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr1 >= rr2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rr2 >= rr1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + "__init__()" + try: + rr = ldns.ldns_rr() + set_error() + except Exception: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".a_address()" + rr = ldns.ldns_rr.new_frm_str("www.nic.cz 600 IN A 217.31.205.50") + try: + address = rr.a_address() + if not isinstance(address, ldns.ldns_rdf): + set_error() + if address == None: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("www.nic.cz 600 IN AAAA 2002:d91f:cd32::1") + try: + address = rr.a_address() + if not isinstance(address, ldns.ldns_rdf): + set_error() + if address == None: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("www.nic.cz 600 IN TXT text") + try: + address = rr.a_address() + if isinstance(address, ldns.ldns_rdf): + set_error() + if address != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".a_set_address()" + rdf = ldns.ldns_rdf.new_frm_str("127.0.0.1", ldns.LDNS_RDF_TYPE_A) + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.a_set_address(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + rdf = ldns.ldns_rdf.new_frm_str("::1", ldns.LDNS_RDF_TYPE_AAAA) + rr = ldns.ldns_rr.new_frm_str("test 600 IN AAAA ::") + try: + ret = rr.a_set_address(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr.a_set_address("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".class_by_name()" + try: + ret = ldns.ldns_rr.class_by_name("IN") + if not isinstance(ret, int): + set_error() + if ret != ldns.LDNS_RR_CLASS_IN: + set_error() + except: + set_error() + method_name = class_name + ".class_by_name()" + try: + ret = ldns.ldns_rr.class_by_name("AA") + if not isinstance(ret, int): + set_error() + if ret != 0: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".clone()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN TXT text") + try: + ret = rr.clone() + if not isinstance(ret, ldns.ldns_rr): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".compare_ds()" + pubkey1 = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + pubkey2 = ldns.ldns_rr.new_frm_str("example2. 3600 IN DNSKEY 256 3 3 ALBoD2+1xYpzrE7gjU5EwwBHG2HNiD1977LDZGh+8VNifMGjixMpgUN6xRhFjvRSsC/seMVXmUGq+msUDF2pHnUHbW/dbQbBxVMAqx2jT0LTvAx5wUPGltHHsa92K8VdzD8ynTFwPvjmk7g3hqRRzt4UTQIeK7DYgrOOgvDv+DYWVQctLwYP0ktm85b4cMtIUNRIf/N+K25pfK6BM/tHN8HOm4ECvm2U9zqHHfnxJFdiNK2PydkNeJZZGUOubSFVvaOMhZoEeAgkm3q5QcwXHsLAhacZ ;{id = 30944 (zsk), size = 512b}") + ds1 = ldns.ldns_key_rr2ds(pubkey1, ldns.LDNS_SHA1) + ds2 = ldns.ldns_key_rr2ds(pubkey2, ldns.LDNS_SHA1) + try: + ret = pubkey1.compare_ds(pubkey1) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = pubkey1.compare_ds(pubkey2) + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = pubkey1.compare_ds(ds1) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = pubkey1.compare_ds(ds2) + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + pubkey1.compare_ds("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".compare_no_rdata()" + rr1 = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + rr2 = ldns.ldns_rr.new_frm_str("test 600 IN AAAA ::") + try: + ret = rr1.compare_no_rdata(rr2) + if not isinstance(ret, int): + set_error() + if ret != -27: + set_error() + except: + set_error() + try: + rr1.compare_no_rdata("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_algorithm()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + try: + ret = pubkey.dnskey_algorithm() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.dnskey_algorithm() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_flags()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + try: + ret = pubkey.dnskey_flags() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.dnskey_flags() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_errror() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_key()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + try: + ret = pubkey.dnskey_key() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.dnskey_key() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_errror() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_key_size()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + try: + ret = pubkey.dnskey_key_size() + if not isinstance(ret, int): + set_error() + if ret != 512: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.dnskey_key_size() + if not isinstance(ret, int): + set_error() + if ret != 0: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_key_size_raw()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_protocol()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + try: + ret = pubkey.dnskey_protocol() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.dnskey_protocol() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_set_algorithm()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + rdf = ldns.ldns_rdf.new_frm_str("3", ldns.LDNS_RDF_TYPE_ALG) + try: + ret = pubkey.dnskey_set_algorithm(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = pubkey.dnskey_set_algorithm(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = pubkey.dnskey_set_algorithm("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_set_flags()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + rdf = ldns.ldns_rdf.new_frm_str("256", ldns.LDNS_RDF_TYPE_INT16) + try: + ret = pubkey.dnskey_set_flags(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = pubkey.dnskey_set_flags(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = pubkey.dnskey_set_flags("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_set_key()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + rdf = ldns.ldns_rdf.new_frm_str("AMLdYflByPu1GEPCnu9qPTqbnC8n5mftFmFVTFQI10aefiDqp5DLpjBdTxdmz/GACMZh1+YG/iLj0QYX7qRVIl0rR00iREozqj44YwUILHo3cASSRSeAzyidvlGT8QSMKOlOsD33ygtETpzW0XDmzWhyU3bv0O7lnGpbtqdzP/nsZDbdtf5XI0YBdi91HftqtQpIlMtCg+zIzATO4+QWGt0oDX/+jdB7Y/vBahxnz13stNYeGYslGBSZNgpB7HBKlTwB70sprZ8XmNGhj/NixqB6Bzae", ldns.LDNS_RDF_TYPE_B64) + try: + ret = pubkey.dnskey_set_key(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = pubkey.dnskey_set_key(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = pubkey.dnskey_set_key("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".dnskey_set_protocol()" + pubkey = ldns.ldns_rr.new_frm_str("example1. 3600 IN DNSKEY 256 3 3 APw7tG8Nf7MYXjt2Y6DmyWUVxVy73bRKvKbKoGXhAXJx2vbcGGxfXsScT0i4FIC2wsJ/8zy/otB5vymm3JHBf2+7cQvRdp12UMLAnzlfrbgZUpvV36D+q6ch7kbmFzaBfwRjOKhnZkRLCcMYPAdX1SrgKVNXaOzAl9KytbzGQs5MKEHU+a0PAwKfIvEsS/+pW6gKgBnL0uy4Gr5cYJ5rk48iwFXOlZ/B30gUS5dD+rNRJuR0ZgEkxtVIPVxxhQPtEI53JhlJ2nEy0CqNW88nYLmX402b ;{id = 34898 (zsk), size = 512b}") + rdf = ldns.ldns_rdf.new_frm_str("3", ldns.LDNS_RDF_TYPE_INT8) + try: + ret = pubkey.dnskey_set_protocol(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = pubkey.dnskey_set_protocol(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = pubkey.dnskey_set_protocol("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".get_class()" + rr = ldns.ldns_rr.new_frm_str("test IN A 0.0.0.0", 600) + try: + ret = rr.get_class() + if not isinstance(ret, int): + set_error() + if ret != ldns.LDNS_RR_CLASS_IN: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".get_class_str()" + rr = ldns.ldns_rr.new_frm_str("test CH A 0.0.0.0", 600) + try: + ret = rr.get_class_str() + if not isinstance(ret, str): + set_error() + if ret != "CH": + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".get_type()" + rr = ldns.ldns_rr.new_frm_str("test IN A 0.0.0.0", 600) + try: + ret = rr.get_type() + if not isinstance(ret, int): + set_error() + if ret != 1: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".get_type_str()" + rr = ldns.ldns_rr.new_frm_str("test IN A 0.0.0.0", 600) + try: + ret = rr.get_type_str() + if not isinstance(ret, str): + set_error() + if ret != "A": + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".is_question()" + rr = ldns.ldns_rr.new_frm_str("test IN A 0.0.0.0", 600) + try: + ret = rr.is_question() + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + rr.set_question(True) + try: + ret = rr.is_question() + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".label_count()" + rr = ldns.ldns_rr.new_frm_str("test.dom. IN A 0.0.0.0", 600) + try: + ret = rr.label_count() + if not isinstance(ret, int): + set_error() + if ret != 2: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str(". IN A 0.0.0.0", 600) + try: + ret = rr.label_count() + if not isinstance(ret, int): + set_error(string) + if ret != 0: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".mx_exchange()" + rr = ldns.ldns_rr.new_frm_str("nic.cz. IN MX 15 mail4.nic.cz.", 600) + try: + ret = rr.mx_exchange() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.mx_exchange() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".mx_preference()" + rr = ldns.ldns_rr.new_frm_str("nic.cz. IN MX 15 mail4.nic.cz.", 600) + try: + ret = rr.mx_preference() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.mx_preference() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_fp()" + f = open(temp_fname, "w") + f.write("test 600 IN A 0.0.0.0") + f.close() + f = open(temp_fname, "r") + rr, ttl, origin, prev = ldns.ldns_rr.new_frm_fp(f, + origin=ldns.ldns_dname("nic.cz")) + try: + # Reading past file end. + ret = ldns.ldns_rr.new_frm_fp(f, raiseException=False) + if ret != None: + set_error() + except: + set_error() + try: + # Reading past file end. + rr, ttl, origin, prev = ldns.ldns_rr.new_frm_fp(f) + set_error() + except Exception: + pass + except: + set_error() + f.close() + os.remove(temp_fname) + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_fp_l()" + f = open(temp_fname, "w") + f.write("test 600 IN A 0.0.0.0") + f.close() + f = open(temp_fname, "r") + rr, line, ttl, origin, prev = ldns.ldns_rr.new_frm_fp_l(f, + origin=ldns.ldns_dname("nic.cz")) + try: + # Reading past file end. + ret = ldns.ldns_rr.new_frm_fp_l(f, raiseException=False) + if ret != None: + set_error() + except: + set_error() + try: + # Reading past file end. + rr, ttl, origin, prev = ldns.ldns_rr.new_frm_fp_l(f) + set_error() + except Exception: + pass + except: + set_error() + f.close() + os.remove(temp_fname) + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_str()" + try: + rr = ldns.ldns_rr.new_frm_str("test IN A 0.0.0.0", 600, + origin=ldns.ldns_dname("nic.cz")) + if not isinstance(rr, ldns.ldns_rr): + set_error() + except: + set_error() + try: + rr = ldns.ldns_rr.new_frm_str(10) + set_error() + except TypeError: + pass + except: + set_error() + try: + rr = ldns.ldns_rr.new_frm_str("") + set_error() + except Exception: + pass + except: + set_error() + try: + rr = ldns.ldns_rr.new_frm_str("", raiseException=False) + if rr != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_str_prev()" + try: + rr, prev = ldns.ldns_rr.new_frm_str_prev("test IN A 0.0.0.0", 600, + origin=ldns.ldns_dname("nic.cz")) + if not isinstance(rr, ldns.ldns_rr): + set_error() +# if prev != None: +# set_error() + except: + set_error() + try: + rr = ldns.ldns_rr.new_frm_str_prev(10) + set_error() + except TypeError: + pass + except: + set_error() + try: + rr = ldns.ldns_rr.new_frm_str_prev("") + set_error() + except Exception: + pass + except: + set_error() + try: + rr = ldns.ldns_rr.new_frm_str_prev("", raiseException=False) + if rr != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".new_question_frm_str()" + try: + rr = ldns.ldns_rr.new_question_frm_str("test IN A", 600, + origin=ldns.ldns_dname("nic.cz")) + if not isinstance(rr, ldns.ldns_rr): + set_error() + except: + set_error() + try: + rr = ldns.ldns_rr.new_question_frm_str(10) + set_error() + except TypeError: + pass + except: + set_error() + try: + rr = ldns.ldns_rr.new_question_frm_str("") + set_error() + except Exception: + pass + except: + set_error() + try: + rr = ldns.ldns_rr.new_question_frm_str("", raiseException=False) + if rr != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".ns_nsdname()" + rr = ldns.ldns_rr.new_frm_str("nic.cz. 1800 IN NS a.ns.nic.cz.") + try: + ret = rr.ns_nsdname() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.ns_nsdname() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".owner()" + rr = ldns.ldns_rr.new_frm_str("nic.cz. 1800 IN NS a.ns.nic.cz.") + try: + ret = rr.owner() + if not isinstance(ret, ldns.ldns_dname): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".pop_rdf()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.pop_rdf() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + if ret.get_type() != ldns.LDNS_RDF_TYPE_A: + set_error() + except: + set_error() + try: + ret = rr.pop_rdf() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".print_to_file()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + f = open(temp_fname, "w") + try: + rr.print_to_file(f) + except: + set_error() + f.close() + f = open(temp_fname, "r") + if not f.readline(): + set_error() + f.close() + os.remove(temp_fname) + + +#if not error_detected: +if True: + method_name = class_name + ".push_rdf()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + rdf = ldns.ldns_rdf.new_frm_str("1.1.1.1", ldns.LDNS_RDF_TYPE_A) + try: + ret = rr.push_rdf(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rr.push_rdf("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rd_count()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rd_count() + if not isinstance(ret, int): + set_error() + if ret != 1: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rdf()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rdf(0) + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + try: + ret = rr.rdf(1) + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rdfs()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rdfs() + if len(list(ret)) != 1: + set_error() + except: + set_error() + + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_algorithm()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_algorithm() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_algorithm() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_expiration()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_expiration() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_expiration() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_inception()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_inception() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_inception() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_keytag()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_keytag() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_keytag() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_labels()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_labels() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_labels() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_origttl()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_origttl() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_origttl() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_algorithm()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("3", ldns.LDNS_RDF_TYPE_ALG) + try: + ret = rr.rrsig_set_algorithm(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_algorithm(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_algorithm("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_expiration()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("20130928153754", ldns.LDNS_RDF_TYPE_TIME) + try: + ret = rr.rrsig_set_expiration(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_expiration(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_expiration("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_inception()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("20120728153754", ldns.LDNS_RDF_TYPE_TIME) + try: + ret = rr.rrsig_set_inception(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_inception(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_inception("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_keytag()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("19032", ldns.LDNS_RDF_TYPE_INT16) + try: + ret = rr.rrsig_set_keytag(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_keytag(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_keytag("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_labels()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("1", ldns.LDNS_RDF_TYPE_INT8) + try: + ret = rr.rrsig_set_labels(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_labels(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_labels("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_origttl()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("1", ldns.LDNS_RDF_TYPE_INT8) + try: + ret = rr.rrsig_set_origttl(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_origttl(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_origttl("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_sig()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=", ldns.LDNS_RDF_TYPE_B64) + try: + ret = rr.rrsig_set_sig(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_sig(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_sig("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_signame()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("example.", ldns.LDNS_RDF_TYPE_DNAME) + try: + ret = rr.rrsig_set_signame(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_signame(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_signame("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_set_typecovered()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + rdf = ldns.ldns_rdf.new_frm_str("SOA", ldns.LDNS_RDF_TYPE_TYPE) + try: + ret = rr.rrsig_set_typecovered(rdf) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() +# rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) +# try: +# ret = rr.rrsig_set_typecovered(rdf) +# if not isinstance(ret, bool): +# set_error() +# if ret != False: +# set_error() +# except: +# set_error() + try: + ret = rr.rrsig_set_typecovered("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_sig()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_sig() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_sig() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_signame()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_signame() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_signame() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrsig_typecovered()" + rr = ldns.ldns_rr.new_frm_str("example. 600 IN RRSIG SOA 3 1 600 20130828153754 20120828153754 19031 example. AIoCFhwZJxIgYOBEyo3cxxWFZEsUPqkxnt38xEl1cFAHHC9iQN9mlEg=") + try: + ret = rr.rrsig_typecovered() + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.rrsig_typecovered() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_class()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + rr.set_class(ldns.LDNS_RR_CLASS_CH) + except: + set_error() + try: + rr.set_class("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_owner()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + rdf = ldns.ldns_dname("test2") + try: + rr.set_owner(rdf) + except: + set_error() + try: + rr.set_owner("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_question()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + rr.set_question(True) + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_rd_count()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + rr.set_rd_count(1) + except: + set_error() + try: + rr.set_rd_count("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_rdf()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + rdf = ldns.ldns_rdf.new_frm_str("1.1.1.1", ldns.LDNS_RDF_TYPE_A) + rr.push_rdf(rdf) + try: + ret = rr.set_rdf(rdf, 0) + if not isinstance(ret, ldns.ldns_rdf): + set_error() + except: + set_error() + try: + ret = rr.set_rdf(rdf, 2) + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + try: + rr.set_rdf("", 1) + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_ttl()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + rr.set_ttl(1) + except: + set_error() + try: + rr.set_ttl("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_type()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + rr.set_type(ldns.LDNS_RR_TYPE_A) + except: + set_error() + try: + rr.set_type("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".to_canonical()" + rr = ldns.ldns_rr.new_frm_str("TEST 600 IN A 0.0.0.0") + try: + rr.to_canonical() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".ttl()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.ttl() + if not isinstance(ret, int): + set_error() + if ret != 600: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".type_by_name()" + try: + ret = ldns.ldns_rr.type_by_name("A") + if not isinstance(ret, int): + set_error() + if ret != ldns.LDNS_RR_TYPE_A: + set_error() + except: + set_error() + try: + ret = ldns.ldns_rr.type_by_name("AA") + if not isinstance(ret, int): + set_error() + if ret != 0: + set_error() + except: + set_error() + try: + ret = ldns.ldns_rr.type_by_name(1) + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".uncompressed_size()" + rr = ldns.ldns_rr.new_frm_str("test 600 IN A 0.0.0.0") + try: + ret = rr.uncompressed_size() + if not isinstance(ret, int): + set_error() + if ret != 20: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".write_data_to_buffer()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = class_name + ".write_rrsig_to_buffer()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = class_name + ".write_to_buffer()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +#if not error_detected: +if True: + method_name = class_name + ".write_to_buffer_canonical()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +############################################################################### +############################################################################### + + +class_name = "ldns_rr_descriptor" +method_name = None +error_detected = False +temp_fname = "tmp_rr_descriptor.txt" + + +#if not error_detected: +if True: + method_name = class_name + ".field_type()" + desc_a = ldns.ldns_rr_descriptor.ldns_rr_descriptor(ldns.LDNS_RR_TYPE_A) + try: + ret = desc_a.field_type(0) + if not isinstance(ret, int): + set_error() + if ret != ldns.LDNS_RDF_TYPE_A: + set_error() + except: + set_error() + try: + ret = desc_a.field_type("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".ldns_rr_descriptor()" + try: + ret = ldns.ldns_rr_descriptor.ldns_rr_descriptor(ldns.LDNS_RR_TYPE_A) + if not isinstance(ret, ldns.ldns_rr_descriptor): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".maximum()" + desc_a = ldns.ldns_rr_descriptor.ldns_rr_descriptor(ldns.LDNS_RR_TYPE_A) + try: + ret = desc_a.maximum() + if not isinstance(ret, int): + set_error() + if ret != 1: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".minimum()" + desc_a = ldns.ldns_rr_descriptor.ldns_rr_descriptor(ldns.LDNS_RR_TYPE_A) + try: + ret = desc_a.minimum() + if not isinstance(ret, int): + set_error() + if ret != 1: + set_error() + except: + set_error() + + +############################################################################### +############################################################################### + + +class_name = "ldns_rr_list" +method_name = None +error_detected = False +temp_fname = "tmp_rr_list.txt" + + +#if not error_detected: +if True: + method_name = class_name + ".[comparison operators]" + rrl1 = ldns.ldns_rr_list.new() + rrl1.push_rr(ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0")) + rrl2 = ldns.ldns_rr_list.new() + rrl2.push_rr(ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1")) + try: + ret = rrl1 < rrl2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl2 < rrl1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl1 <= rrl2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl2 <= rrl1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl1 == rrl2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl1 == rrl1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl1 != rrl2 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl1 != rrl1 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl1 > rrl2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl2 > rrl1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl1 >= rrl2 + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl2 >= rrl1 + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".cat()" + rrl1 = ldns.ldns_rr_list.new() + rrl2 = ldns.ldns_rr_list.new() + rrl1.push_rr(ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0")) + rrl2.push_rr(ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1")) + try: + ret = rrl1.cat(rrl2) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl2.cat("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".cat_clone()" + rrl1 = ldns.ldns_rr_list.new() + rrl2 = ldns.ldns_rr_list.new() + rrl1.push_rr(ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0")) + rrl2.push_rr(ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1")) + try: + ret = rrl1.cat_clone(rrl2) + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + try: + ret = rrl2.cat_clone("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".clone()" + rrl = ldns.ldns_rr_list.new() + rrl.push_rr(ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0")) + try: + ret = rrl.clone() + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + +#if not error_detected: +if True: + method_name = class_name + ".contains_rr()" + rrl = ldns.ldns_rr_list.new() + rr1 = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rr2 = ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1") + rrl.push_rr(rr1) + try: + ret = rrl.contains_rr(rr1) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl.contains_rr(rr2) + if not isinstance(ret, bool): + set_error() + if ret != False: + set_error() + except: + set_error() + try: + ret = rrl.contains_rr("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".is_rrset()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + ret = rrl.is_rrset() + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".new()" + try: + ret = ldns.ldns_rr_list.new() + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".new_frm_file()" + try: + ret = ldns.ldns_rr_list.new_frm_file() + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + try: + ret = ldns.ldns_rr_list.new_frm_file("test") + set_error() + except Exception: + pass + except: + set_error() + try: + ret = ldns.ldns_rr_list.new_frm_file("test", raiseException=False) + if isinstance(ret, ldns.ldns_rr_list): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".owner()" + rrl = ldns.ldns_rr_list.new() + try: + ret = rrl.owner() + if isinstance(ret, ldns.ldns_rdf): + set_error() + if ret != None: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + ret = rrl.owner() + if not isinstance(ret, ldns.ldns_dname): + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".pop_rr()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + ret = rrl.pop_rr() + if not isinstance(ret, ldns.ldns_rr): + set_error() + except: + set_error() + try: + ret = rrl.pop_rr() + if isinstance(ret, ldns.ldns_rr): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".pop_rr_list()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rrl.push_rr(rr) + rrl.push_rr(rr) + try: + ret = rrl.pop_rr_list(2) + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + try: + ret = rrl.pop_rr_list(2) + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + try: + ret = rrl.pop_rr_list(2) + if isinstance(ret, ldns.ldns_rr_list): + set_error() + if ret != None: + set_error() + except: + set_error() + try: + ret = rrl.pop_rr_list("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".pop_rrset()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rrl.push_rr(rr) + rrl.push_rr(rr) + try: + ret = rrl.pop_rrset() + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + except: + set_error() + try: + ret = rrl.pop_rrset() + if isinstance(ret, ldns.ldns_rr_list): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".print_to_file()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rrl.push_rr(rr) + rrl.push_rr(rr) + f = open(temp_fname, "w") + try: + rrl.print_to_file(f) + except: + set_error() + f.close() + f = open(temp_fname, "r") + if len(f.readlines()) != 3: + set_error() + f.close() + os.remove(temp_fname) + + +#if not error_detected: +if True: + method_name = class_name + ".push_rr()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + try: + ret = rrl.push_rr(rr) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl.push_rr("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".push_rr_list()" + rrl1 = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl1.push_rr(rr) + rrl2 = rrl1.new() + try: + ret = rrl1.push_rr_list(rrl2) + if not isinstance(ret, bool): + set_error() + if ret != True: + set_error() + except: + set_error() + try: + ret = rrl.push_rr_list("") + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rr()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + ret = rrl.rr(0) + if not isinstance(ret, ldns.ldns_rr): + set_error() + except: + set_error() + try: + ret = rrl.rr(1) + if isinstance(ret, ldns.ldns_rr): + set_error() + if ret != None: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rr_count()" + rrl = ldns.ldns_rr_list.new() + try: + ret = rrl.rr_count() + if not isinstance(ret, int): + set_error() + if ret != 0: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + ret = rrl.rr_count() + if not isinstance(ret, int): + set_error() + if ret != 1: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".rrs()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rrl.push_rr(rr) + try: + ret = list(rrl.rrs()) + if not isinstance(ret, list): + set_error() + if len(ret) != 2: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_rr()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rr = ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1") + ret = rrl.set_rr(rr, 0) + try: + ret = rrl.set_rr(rr, 0) + if not isinstance(ret, ldns.ldns_rr): + set_error() + except: + set_error() + try: + ret = rrl.set_rr(rr, 1) + if isinstance(ret, ldns.ldns_rr): + set_error() + if ret != None: + set_error() + except: + set_error() + try: + ret = rrl.set_rr("", 1) + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".set_rr_count()" + rrl = ldns.ldns_rr_list.new() + try: + rrl.set_rr_count(0) + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + rrl.set_rr_count("") + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".sort()" + rrl = ldns.ldns_rr_list.new() + try: + rrl.sort() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".subtype_by_rdf()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("test1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rr = ldns.ldns_rr.new_frm_str("test2 600 IN A 1.1.1.1") + rrl.push_rr(rr) + rr = ldns.ldns_rr.new_frm_str("test3 600 IN A 0.0.0.0") + rrl.push_rr(rr) + rdf = ldns.ldns_rdf.new_frm_str("0.0.0.0", ldns.LDNS_RDF_TYPE_A) + try: + ret = rrl.subtype_by_rdf(rdf, 0) + if not isinstance(ret, ldns.ldns_rr_list): + set_error() + if ret.rr_count() != 2: + set_error() + except: + set_error() + rdf = ldns.ldns_rdf.new_frm_str("::", ldns.LDNS_RDF_TYPE_AAAA) + try: + ret = rrl.subtype_by_rdf(rdf, 0) + if isinstance(ret, ldns.ldns_rr_list): + set_error() + if ret != None: + set_error() + except: + set_error() + try: + ret = rrl.subtype_by_rdf("", 0) + set_error() + except TypeError: + pass + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".to_canonical()" + rrl = ldns.ldns_rr_list.new() + rr = ldns.ldns_rr.new_frm_str("TEST1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + rrl.to_canonical() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".type()" + rrl = ldns.ldns_rr_list.new() + try: + ret = rrl.type() + if not isinstance(ret, int): + set_error() + if ret != 0: + set_error() + except: + set_error() + rr = ldns.ldns_rr.new_frm_str("TEST1 600 IN A 0.0.0.0") + rrl.push_rr(rr) + try: + ret = rrl.type() + if not isinstance(ret, int): + set_error() + if ret != ldns.LDNS_RR_TYPE_A: + set_error() + except: + set_error() + + +#if not error_detected: +if True: + method_name = class_name + ".write_to_buffer()" + sys.stderr.write("%s not tested.\n" % (method_name)) + + +if not error_detected: + sys.stdout.write("%s: passed.\n" % (os.path.basename(__file__))) +else: + sys.stdout.write("%s: errors detected.\n" % (os.path.basename(__file__))) + sys.exit(1) diff --git a/contrib/python/file_py3.i b/contrib/python/file_py3.i index b3f55e82ab5b..4d9502c54909 100644 --- a/contrib/python/file_py3.i +++ b/contrib/python/file_py3.i @@ -103,7 +103,8 @@ dispose_file(FILE **fp) { %typemap(check, noblock = 1) FILE* { if ($1 == NULL) { - SWIG_exception_fail(SWIG_ValueError, "in method '" "$symname" "', argument " + /* The generated wrapper function raises TypeError on mismatching types. */ + SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " "$argnum"" of type '" "$type""'"); } } diff --git a/contrib/python/ldns.i b/contrib/python/ldns.i index 122ebe18e0a2..35e076f8b7cc 100644 --- a/contrib/python/ldns.i +++ b/contrib/python/ldns.i @@ -78,6 +78,36 @@ #endif %include "typemaps.i" + +/* ========================================================================= */ +/* Preliminary Python code. */ +/* ========================================================================= */ + +%pythoncode +%{ + # + # Use and don't ignore DeprecationWarning and + # PendingDeprecationWarning. + # + import warnings + warnings.filterwarnings("module", category=DeprecationWarning) + warnings.filterwarnings("module", category=PendingDeprecationWarning) +%} + + +/* Tell SWIG how to handle ssize_t as input parameter. */ +%typemap(in, noblock=1) (ssize_t) +{ + int $1_res = 0; + $1_res = SWIG_AsVal_long($input, &$1); + if (!SWIG_IsOK($1_res)) { + SWIG_exception_fail(SWIG_ArgError($1_res), "in method '" + "$symname" "', argument " "$argnum" " of type '" + "$type""'"); + } +} + + %inline %{ struct timeval* ldns_make_timeval(uint32_t sec, uint32_t usec) { @@ -97,8 +127,9 @@ uint32_t ldns_read_timeval_usec(struct timeval* t) { %immutable ldns_error_str; %immutable ldns_signing_algorithms; -//new_frm_fp_l -%apply int *OUTPUT { int *line_nr}; +//*_new_frm_fp_l +%apply int *OUTPUT { (int *line_nr) }; + %apply uint32_t *OUTPUT { uint32_t *default_ttl}; // wire2pkt @@ -192,8 +223,53 @@ typedef struct ldns_dnssec_zone { }; return tuple; } + PyObject* ldns_rr_new_frm_fp_(FILE *fp, uint32_t default_ttl, ldns_rdf* origin, ldns_rdf* prev) + //returns tuple (status, ldns_rr, ttl, origin, prev) + { + uint32_t defttl = default_ttl; + uint32_t *p_defttl = &defttl; + if (defttl == 0) p_defttl = 0; + + /* origin and prev have to be cloned in order to decouple the data + * from the python wrapper + */ + if (origin != NULL) + origin = ldns_rdf_clone(origin); + if (prev != NULL) + prev = ldns_rdf_clone(prev); + + ldns_rdf *p_origin = origin; + ldns_rdf **pp_origin = &p_origin; + //if (p_origin == 0) pp_origin = 0; + + ldns_rdf *p_prev = prev; + ldns_rdf **pp_prev = &p_prev; + //if (p_prev == 0) pp_prev = 0; + + ldns_rr *p_rr = 0; + ldns_rr **pp_rr = &p_rr; + + ldns_status st = ldns_rr_new_frm_fp(pp_rr, fp, p_defttl, pp_origin, pp_prev); + + PyObject* tuple; + tuple = PyTuple_New(5); + int idx = 0; + PyTuple_SetItem(tuple, idx, SWIG_From_int(st)); + idx++; + PyTuple_SetItem(tuple, idx, (st == LDNS_STATUS_OK) ? + SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) : + (Py_INCREF(Py_None), Py_None)); + idx++; + PyTuple_SetItem(tuple, idx, SWIG_From_int(defttl)); + idx++; + PyTuple_SetItem(tuple, idx, SWIG_NewPointerObj(SWIG_as_voidptr(p_origin), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 )); + idx++; + PyTuple_SetItem(tuple, idx, SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 )); + return tuple; + } + PyObject* ldns_rr_new_frm_fp_l_(FILE *fp, uint32_t default_ttl, ldns_rdf* origin, ldns_rdf* prev) - //returns tuple (status, ldns_rr, [line if ret_linenr], ttl, origin, prev) + //returns tuple (status, ldns_rr, line, ttl, origin, prev) { int linenr = 0; int *p_linenr = &linenr; diff --git a/contrib/python/ldns_buffer.i b/contrib/python/ldns_buffer.i index 1e743c007803..f9825c2907b3 100644 --- a/contrib/python/ldns_buffer.i +++ b/contrib/python/ldns_buffer.i @@ -14,8 +14,8 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the organization nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -28,47 +28,44 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************/ + *****************************************************************************/ -%typemap(in,numinputs=0,noblock=1) (ldns_buffer **) + +/* ========================================================================= */ +/* SWIG setting and definitions. */ +/* ========================================================================= */ + +/* Creates a temporary instance of (ldns_buffer *). */ +%typemap(in, numinputs=0, noblock=1) (ldns_buffer **) { - ldns_buffer *$1_buf; - $1 = &$1_buf; + ldns_buffer *$1_buf; + $1 = &$1_buf; } -/* result generation */ -%typemap(argout,noblock=1) (ldns_buffer **) +/* Result generation, appends (ldns_buffer *) after the result. */ +%typemap(argout, noblock=1) (ldns_buffer **) { - $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_buf), SWIGTYPE_p_ldns_struct_buffer, SWIG_POINTER_OWN | 0 )); + $result = SWIG_Python_AppendOutput($result, + SWIG_NewPointerObj(SWIG_as_voidptr($1_buf), + SWIGTYPE_p_ldns_struct_buffer, SWIG_POINTER_OWN | 0)); } -%nodefaultctor ldns_struct_buffer; //no default constructor & destructor -%nodefaultdtor ldns_struct_buffer; +/* + * Limit the number of arguments to 2 and deal with variable + * number of arguments in the Python way. + */ +%varargs(2, char *arg = NULL) ldns_buffer_printf; + +%nodefaultctor ldns_struct_buffer; /* No default constructor. */ +%nodefaultdtor ldns_struct_buffer; /* No default destructor. */ -%delobject ldns_buffer_free; %newobject ldns_buffer_new; -%newobject ldns_dname_new; %newobject ldns_dname_new_frm_data; -%newobject ldns_dname_label; -# limit the number of arguments to 2 and -# deal with variable number of arguments the Python way -%varargs(2, char *arg = NULL) ldns_buffer_printf; +%delobject ldns_buffer_free; %rename(ldns_buffer) ldns_struct_buffer; -#ifdef LDNS_DEBUG -%rename(__ldns_buffer_free) ldns_buffer_free; -%inline %{ -void _ldns_buffer_free (ldns_buffer* b) { - printf("******** LDNS_BUFFER free 0x%lX ************\n", (long unsigned int)b); - ldns_buffer_free(b); -} -%} -#else -%rename(_ldns_buffer_free) ldns_buffer_free; -#endif - %ignore ldns_struct_buffer::_position; %ignore ldns_struct_buffer::_limit; %ignore ldns_struct_buffer::_capacity; @@ -76,301 +73,425 @@ void _ldns_buffer_free (ldns_buffer* b) { %ignore ldns_struct_buffer::_fixed; %ignore ldns_struct_buffer::_status; +%ignore ldns_buffer_new_frm_data; + + +/* ========================================================================= */ +/* Debugging related code. */ +/* ========================================================================= */ + +#ifdef LDNS_DEBUG +%rename(__ldns_buffer_free) ldns_buffer_free; +%inline +%{ + /*! + * @brief Frees the buffer and print a message. + */ + void _ldns_buffer_free (ldns_buffer* b) + { + printf("******** LDNS_BUFFER free 0x%lX ************\n", + (long unsigned int) b); + ldns_buffer_free(b); + } +%} +#else /* !LDNS_DEBUG */ +%rename(_ldns_buffer_free) ldns_buffer_free; +#endif /* LDNS_DEBUG */ + + +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ + +/* None. */ + + +/* ========================================================================= */ +/* Encapsulating Python code. */ +/* ========================================================================= */ + +%feature("docstring") "LDNS buffer." + %extend ldns_struct_buffer { - %pythoncode %{ + %pythoncode + %{ def __init__(self, capacity): - """Creates a new buffer with the specified capacity. + """ + Creates a new buffer with the specified capacity. - :param capacity: the size (in bytes) to allocate for the buffer + :param capacity: Number of bytes to allocate for the buffer. + :type capacity: integer + :throws TypeError: When `capacity` of non-integer type. + :return: (:class:`ldns_buffer`) """ self.this = _ldns.ldns_buffer_new(capacity) __swig_destroy__ = _ldns._ldns_buffer_free def __str__(self): - """Returns the data in the buffer as a string. Buffer data must be char * type.""" + """ + Returns the data in the buffer as a string. + Buffer data must be char * type. + + :return: string + """ return _ldns.ldns_buffer2str(self) def getc(self): - """returns the next character from a buffer. + """ + Returns the next character from a buffer. - Advances the position pointer with 1. When end of buffer is reached returns EOF. This is the buffer's equivalent for getc(). + Advances the position pointer with 1. When end of buffer + is reached returns EOF. This is the buffer's equivalent + for getc(). - :returns: (int) EOF on failure otherwise return the character + :return: (integer) EOF on failure otherwise return + the character. """ return _ldns.ldns_bgetc(self) - #LDNS_BUFFER_METHODS_# - def at(self,at): - """returns a pointer to the data at the indicated position. + # + # LDNS_BUFFER_METHODS_ + # + + def at(self, at): + """ + Returns a pointer to the data at the indicated position. - :param at: - position - :returns: (uint8_t \*) the pointer to the data + :param at: position + :type at: positive integer + :throws TypeError: When `at` of non-integer type. + :return: (uint8_t \*) The pointer to the data. """ - return _ldns.ldns_buffer_at(self,at) - #parameters: const ldns_buffer *,size_t, + return _ldns.ldns_buffer_at(self, at) + #parameters: const ldns_buffer *, size_t, #retvals: uint8_t * - def available(self,count): - """checks if the buffer has count bytes available at the current position + def available(self, count): + """ + Checks whether the buffer has count bytes available at + the current position. - :param count: - how much is available - :returns: (int) true or false + :param count: How much is available. + :type count: integer + :throws TypeError: When `count` of non-integer type. + :return: (bool) True or False. """ - return _ldns.ldns_buffer_available(self,count) - #parameters: ldns_buffer *,size_t, + return _ldns.ldns_buffer_available(self, count) != 0 + #parameters: ldns_buffer *, size_t, #retvals: int - def available_at(self,at,count): - """checks if the buffer has at least COUNT more bytes available. + def available_at(self, at, count): + """ + Checks if the buffer has at least `count` more bytes available. - Before reading or writing the caller needs to ensure enough space is available! + Before reading or writing the caller needs to ensure that + enough space is available! - :param at: - indicated position - :param count: - how much is available - :returns: (int) true or false + :param at: Indicated position. + :type at: positive integer + :param count: How much is available. + :type count: positive integer + :throws TypeError: When `at` or `count` of non-integer type. + :return: (bool) True or False. """ - return _ldns.ldns_buffer_available_at(self,at,count) + return _ldns.ldns_buffer_available_at(self, at, count) != 0 #parameters: ldns_buffer *,size_t,size_t, #retvals: int def begin(self): - """returns a pointer to the beginning of the buffer (the data at position 0). + """ + Returns a pointer to the beginning of the buffer + (the data at position 0). - :returns: (uint8_t \*) the pointer + :return: (uint8_t \*) Pointer. """ return _ldns.ldns_buffer_begin(self) #parameters: const ldns_buffer *, #retvals: uint8_t * def capacity(self): - """returns the number of bytes the buffer can hold. + """ + Returns the number of bytes the buffer can hold. - :returns: (size_t) the number of bytes + :return: (size_t) The number of bytes. """ return _ldns.ldns_buffer_capacity(self) #parameters: ldns_buffer *, #retvals: size_t def clear(self): - """clears the buffer and make it ready for writing. + """ + Clears the buffer and make it ready for writing. - The buffer's limit is set to the capacity and the position is set to 0. + The buffer's limit is set to the capacity and the position + is set to 0. """ _ldns.ldns_buffer_clear(self) #parameters: ldns_buffer *, #retvals: - def copy(self,bfrom): - """Copy contents of the other buffer to this buffer. + def copy(self, bfrom): + """ + Copy contents of the other buffer to this buffer. Silently truncated if this buffer is too small. - :param bfrom: other buffer + :param bfrom: Source buffer. + :type bfrom: :class:`ldns_buffer` + :throws TypeError: When `bfrom` of non-:class:`ldns_buffer` + type. """ - _ldns.ldns_buffer_copy(self,bfrom) - #parameters: ldns_buffer *,ldns_buffer *, + _ldns.ldns_buffer_copy(self, bfrom) + #parameters: ldns_buffer *, ldns_buffer *, #retvals: def current(self): - """returns a pointer to the data at the buffer's current position. + """ + Returns a pointer to the data at the buffer's current position. - :returns: (uint8_t \*) the pointer + :return: (uint8_t \*) A pointer. """ return _ldns.ldns_buffer_current(self) #parameters: ldns_buffer *, #retvals: uint8_t * def end(self): - """returns a pointer to the end of the buffer (the data at the buffer's limit). + """ + Returns a pointer to the end of the buffer (the data + at the buffer's limit). - :returns: (uint8_t \*) the pointer + :return: (uint8_t \*) Pointer. """ return _ldns.ldns_buffer_end(self) #parameters: ldns_buffer *, #retvals: uint8_t * def export(self): - """Makes the buffer fixed and returns a pointer to the data. + """ + Makes the buffer fixed and returns a pointer to the data. - The caller is responsible for free'ing the result. + The caller is responsible for freeing the result. - :returns: (void \*) void + :return: (void \*) Void pointer. """ return _ldns.ldns_buffer_export(self) #parameters: ldns_buffer *, #retvals: void * def flip(self): - """makes the buffer ready for reading the data that has been written to the buffer. + """ + Makes the buffer ready for reading the data that has been + written to the buffer. - The buffer's limit is set to the current position and the position is set to 0. + The buffer's limit is set to the current position and + the position is set to 0. """ _ldns.ldns_buffer_flip(self) #parameters: ldns_buffer *, def invariant(self): + """ + Performs no action. + + In debugging mode this method performs a buffer settings + check. It asserts if something is wrong. + """ _ldns.ldns_buffer_invariant(self) #parameters: ldns_buffer *, def limit(self): - """returns the maximum size of the buffer + """ + Returns the maximum size of the buffer. - :returns: (size_t) the size + :return: (size_t) The size. """ return _ldns.ldns_buffer_limit(self) #parameters: ldns_buffer *, #retvals: size_t def position(self): - """returns the current position in the buffer (as a number of bytes) + """ + Returns the current position in the buffer + (as a number of bytes). - :returns: (size_t) the current position + :return: (size_t) The current position. """ return _ldns.ldns_buffer_position(self) #parameters: ldns_buffer *, #retvals: size_t - def printf(self, str, *args): - """Prints to the buffer, increasing the capacity if required using buffer_reserve(). + def printf(self, string, *args): + """ + Prints to the buffer, increasing the capacity + if required using buffer_reserve(). - The buffer's position is set to the terminating '\0'. Returns the number of characters written (not including the terminating '\0') or -1 on failure. - :param str: a string - :returns: (int) + The buffer's position is set to the terminating '\0'. + Returns the number of characters written (not including + the terminating '\0') or -1 on failure. + + :param string: A string to be written. + :type string: string + :throws: TypeError when `string` not a string. + :return: (int) Number of written characters or -1 on failure. """ - data = str % args - return _ldns.ldns_buffer_printf(self,data) - #parameters: ldns_buffer *,const char *,... + data = string % args + return _ldns.ldns_buffer_printf(self, data) + #parameters: ldns_buffer *, const char *, ... #retvals: int - def read(self,data,count): - """copies count bytes of data at the current position to the given data-array + def read(self, data, count): + """ + Copies count bytes of data at the current position to the given + `data`-array - :param data: - buffer to copy to - :param count: - the length of the data to copy + :param data: Target buffer to copy to. + :type data: void \* + :param count: The length of the data to copy. + :type count: size_t """ _ldns.ldns_buffer_read(self,data,count) - #parameters: ldns_buffer *,void *,size_t, + #parameters: ldns_buffer *, void *, size_t, #retvals: - def read_at(self,at,data,count): - """copies count bytes of data at the given position to the given data-array + def read_at(self, at, data, count): + """ + Copies count bytes of data at the given position to the + given `data`-array. - :param at: - the position in the buffer to start - :param data: - buffer to copy to - :param count: - the length of the data to copy + :param at: The position in the buffer to start reading. + :type at: size_t + :param data: Target buffer to copy to. + :type data: void \* + :param count: The length of the data to copy. + :type count: size_t """ _ldns.ldns_buffer_read_at(self,at,data,count) - #parameters: ldns_buffer *,size_t,void *,size_t, + #parameters: ldns_buffer *, size_t, void *, size_t, #retvals: def read_u16(self): - """returns the 2-byte integer value at the current position in the buffer + """ + Returns the 2-byte integer value at the current position + from the buffer. - :returns: (uint16_t) 2 byte integer + :return: (uint16_t) Word. """ return _ldns.ldns_buffer_read_u16(self) #parameters: ldns_buffer *, #retvals: uint16_t - def read_u16_at(self,at): - """returns the 2-byte integer value at the given position in the buffer + def read_u16_at(self, at): + """ + Returns the 2-byte integer value at the given position + from the buffer. - :param at: - position in the buffer - :returns: (uint16_t) 2 byte integer + :param at: Position in the buffer. + :type at: positive integer + :throws TypeError: When `at` of non-integer type. + :return: (uint16_t) Word. """ - return _ldns.ldns_buffer_read_u16_at(self,at) - #parameters: ldns_buffer *,size_t, + return _ldns.ldns_buffer_read_u16_at(self, at) + #parameters: ldns_buffer *, size_t, #retvals: uint16_t def read_u32(self): - """returns the 4-byte integer value at the current position in the buffer + """ + Returns the 4-byte integer value at the current position + from the buffer. - :returns: (uint32_t) 4 byte integer + :return: (uint32_t) Double-word. """ return _ldns.ldns_buffer_read_u32(self) #parameters: ldns_buffer *, #retvals: uint32_t - def read_u32_at(self,at): - """returns the 4-byte integer value at the given position in the buffer + def read_u32_at(self, at): + """ + Returns the 4-byte integer value at the given position + from the buffer. - :param at: - position in the buffer - :returns: (uint32_t) 4 byte integer + :param at: Position in the buffer. + :type at: positive integer + :throws TypeError: When `at` of non-integer type. + :return: (uint32_t) Double-word. """ - return _ldns.ldns_buffer_read_u32_at(self,at) - #parameters: ldns_buffer *,size_t, + return _ldns.ldns_buffer_read_u32_at(self, at) + #parameters: ldns_buffer *, size_t, #retvals: uint32_t def read_u8(self): - """returns the byte value at the current position in the buffer + """ + Returns the byte value at the current position from the buffer. - :returns: (uint8_t) 1 byte integer + :return: (uint8_t) A byte (not a character). """ return _ldns.ldns_buffer_read_u8(self) #parameters: ldns_buffer *, #retvals: uint8_t - def read_u8_at(self,at): - """returns the byte value at the given position in the buffer + def read_u8_at(self, at): + """ + Returns the byte value at the given position from the buffer. - :param at: - the position in the buffer - :returns: (uint8_t) 1 byte integer + :param at: The position in the buffer. + :type at: positive integer + :throws TypeError: When `at` of non-integer type. + :return: (uint8_t) Byte value. """ - return _ldns.ldns_buffer_read_u8_at(self,at) - #parameters: ldns_buffer *,size_t, + return _ldns.ldns_buffer_read_u8_at(self, at) + #parameters: ldns_buffer *, size_t, #retvals: uint8_t def remaining(self): - """returns the number of bytes remaining between the buffer's position and limit. + """ + Returns the number of bytes remaining between the buffer's + position and limit. - :returns: (size_t) the number of bytes + :return: (size_t) The number of bytes. """ return _ldns.ldns_buffer_remaining(self) #parameters: ldns_buffer *, #retvals: size_t - def remaining_at(self,at): - """returns the number of bytes remaining between the indicated position and the limit. + def remaining_at(self, at): + """ + Returns the number of bytes remaining between the indicated + position and the limit. - :param at: - indicated position - :returns: (size_t) number of bytes + :param at: Indicated position. + :type at: positive integer + :throws TypeError: When `at` of non-integer type. + :return: (size_t) number of bytes """ - return _ldns.ldns_buffer_remaining_at(self,at) + return _ldns.ldns_buffer_remaining_at(self, at) #parameters: ldns_buffer *,size_t, #retvals: size_t - def reserve(self,amount): - """ensures BUFFER can contain at least AMOUNT more bytes. + def reserve(self, amount): + """ + Ensures that the buffer can contain at least `amount` more + bytes. - The buffer's capacity is increased if necessary using buffer_set_capacity(). + The buffer's capacity is increased if necessary using + buffer_set_capacity(). - The buffer's limit is always set to the (possibly increased) capacity. + The buffer's limit is always set to the (possibly increased) + capacity. - :param amount: - amount to use - :returns: (bool) whether this failed or succeeded + :param amount: Amount to use. + :type amount: positive integer + :throws TypeError: When `amount` of non-integer type. + :return: (bool) hether this failed or succeeded. """ - return _ldns.ldns_buffer_reserve(self,amount) - #parameters: ldns_buffer *,size_t, + return _ldns.ldns_buffer_reserve(self, amount) + #parameters: ldns_buffer *, size_t, #retvals: bool def rewind(self): - """make the buffer ready for re-reading the data. + """ + Make the buffer ready for re-reading the data. The buffer's position is reset to 0. """ @@ -378,188 +499,228 @@ void _ldns_buffer_free (ldns_buffer* b) { #parameters: ldns_buffer *, #retvals: - def set_capacity(self,capacity): - """changes the buffer's capacity. + def set_capacity(self, capacity): + """ + Changes the buffer's capacity. - The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity. + The data is reallocated so any pointers to the data may become + invalid. The buffer's limit is set to the buffer's new capacity. - :param capacity: - the capacity to use - :returns: (bool) whether this failed or succeeded + :param capacity: The capacity to use. + :type capacity: positive integer + :throws TypeError: When `capacity` of non-integer type. + :return: (bool) whether this failed or succeeded """ - return _ldns.ldns_buffer_set_capacity(self,capacity) - #parameters: ldns_buffer *,size_t, + return _ldns.ldns_buffer_set_capacity(self, capacity) + #parameters: ldns_buffer *, size_t, #retvals: bool - def set_limit(self,limit): - """changes the buffer's limit. + def set_limit(self, limit): + """ + Changes the buffer's limit. - If the buffer's position is greater than the new limit the position is set to the limit. + If the buffer's position is greater than the new limit + then the position is set to the limit. - :param limit: - the new limit + :param limit: The new limit. + :type limit: positive integer + :throws TypeError: When `limit` of non-integer type. """ - _ldns.ldns_buffer_set_limit(self,limit) - #parameters: ldns_buffer *,size_t, + _ldns.ldns_buffer_set_limit(self, limit) + #parameters: ldns_buffer *, size_t, #retvals: def set_position(self,mark): - """sets the buffer's position to MARK. + """ + Sets the buffer's position to `mark`. The position must be less than or equal to the buffer's limit. - :param mark: - the mark to use + :param mark: The mark to use. + :type mark: positive integer + :throws TypeError: When `mark` of non-integer type. """ _ldns.ldns_buffer_set_position(self,mark) #parameters: ldns_buffer *,size_t, #retvals: - def skip(self,count): - """changes the buffer's position by COUNT bytes. + def skip(self, count): + """ + Changes the buffer's position by `count` bytes. - The position must not be moved behind the buffer's limit or before the beginning of the buffer. + The position must not be moved behind the buffer's limit or + before the beginning of the buffer. - :param count: - the count to use + :param count: The count to use. + :type count: integer + :throws TypeError: When `count` of non-integer type. """ - _ldns.ldns_buffer_skip(self,count) - #parameters: ldns_buffer *,ssize_t, + _ldns.ldns_buffer_skip(self, count) + #parameters: ldns_buffer *, ssize_t, #retvals: def status(self): - """returns the status of the buffer + """ + Returns the status of the buffer. - :returns: (ldns_status) the status + :return: (ldns_status) The status. """ return _ldns.ldns_buffer_status(self) #parameters: ldns_buffer *, #retvals: ldns_status def status_ok(self): - """returns true if the status of the buffer is LDNS_STATUS_OK, false otherwise + """ + Returns True if the status of the buffer is LDNS_STATUS_OK, + False otherwise. - :returns: (bool) true or false + :return: (bool) True or False. """ return _ldns.ldns_buffer_status_ok(self) #parameters: ldns_buffer *, #retvals: bool - def write(self,data,count): - """writes count bytes of data to the current position of the buffer + def write(self, data, count): + """ + Writes count bytes of data to the current position of + the buffer. - :param data: - the data to write - :param count: - the lenght of the data to write + :param data: The data to write. + :type data: void \* + :param count: The length of the data to write. + :type count: size_t """ - _ldns.ldns_buffer_write(self,data,count) - #parameters: ldns_buffer *,const void *,size_t, + _ldns.ldns_buffer_write(self, data, count) + #parameters: ldns_buffer *, const void *, size_t, #retvals: - def write_at(self,at,data,count): - """writes the given data to the buffer at the specified position + def write_at(self, at, data, count): + """ + Writes the given data to the buffer at the specified position + by `at`. - :param at: - the position (in number of bytes) to write the data at - :param data: - pointer to the data to write to the buffer - :param count: - the number of bytes of data to write + :param at: The position (in number of bytes) to write the + data at. + :param data: Pointer to the data to write to the buffer. + :param count: The number of bytes of data to write. """ - _ldns.ldns_buffer_write_at(self,at,data,count) - #parameters: ldns_buffer *,size_t,const void *,size_t, + _ldns.ldns_buffer_write_at(self, at, data, count) + #parameters: ldns_buffer *, size_t, const void *, size_t, #retvals: - def write_string(self,str): - """copies the given (null-delimited) string to the current position at the buffer + def write_string(self, string): + """ + Copies the given (null-delimited) string to the current + position into the buffer. - :param str: - the string to write + :param string: The string to write. + :type string: string + :throws TypeError: When `string` not a string. """ - _ldns.ldns_buffer_write_string(self,str) + _ldns.ldns_buffer_write_string(self,string) #parameters: ldns_buffer *,const char *, #retvals: - def write_string_at(self,at,str): - """copies the given (null-delimited) string to the specified position at the buffer + def write_string_at(self, at, string): + """ + Copies the given (null-delimited) string to the specified + position `at` into the buffer. - :param at: - the position in the buffer - :param str: - the string to write + :param at: The position in the buffer. + :type at: positive integer + :param string: The string to write. + :type string: string + :throws TypeError: When types mismatch. """ - _ldns.ldns_buffer_write_string_at(self,at,str) - #parameters: ldns_buffer *,size_t,const char *, + _ldns.ldns_buffer_write_string_at(self, at, string) + #parameters: ldns_buffer *, size_t, const char *, #retvals: - def write_u16(self,data): - """writes the given 2 byte integer at the current position in the buffer + def write_u16(self, data): + """Writes the given 2 byte integer at the current + position in the buffer. - :param data: - the 16 bits to write + :param data: The word to write. + :type data: uint16_t + :throws TypeError: When `data` of non-integer type. """ - _ldns.ldns_buffer_write_u16(self,data) - #parameters: ldns_buffer *,uint16_t, + _ldns.ldns_buffer_write_u16(self, data) + #parameters: ldns_buffer *, uint16_t, #retvals: - def write_u16_at(self,at,data): - """writes the given 2 byte integer at the given position in the buffer + def write_u16_at(self, at, data): + """ + Writes the given 2 byte integer at the given position + in the buffer. - :param at: - the position in the buffer - :param data: - the 16 bits to write + :param at: The position in the buffer. + :type at: positive integer + :param data: The word to write. + :type data: uint16_t + :throws TypeError: When `at` or `data` of non-integer type. """ _ldns.ldns_buffer_write_u16_at(self,at,data) #parameters: ldns_buffer *,size_t,uint16_t, #retvals: - def write_u32(self,data): - """writes the given 4 byte integer at the current position in the buffer + def write_u32(self, data): + """ + Writes the given 4 byte integer at the current position + in the buffer. - :param data: - the 32 bits to write + :param data: The double-word to write. + :type data: uint32_t + :throws TypeError: When `data` of non-integer type. """ - _ldns.ldns_buffer_write_u32(self,data) - #parameters: ldns_buffer *,uint32_t, + _ldns.ldns_buffer_write_u32(self, data) + #parameters: ldns_buffer *, uint32_t, #retvals: - def write_u32_at(self,at,data): - """writes the given 4 byte integer at the given position in the buffer + def write_u32_at(self, at, data): + """ + Writes the given 4 byte integer at the given position + in the buffer. - :param at: - the position in the buffer - :param data: - the 32 bits to write + :param at: The position in the buffer. + :type at: positive integer + :param data: The double-word to write. + :type data: uint32_t + :throws TypeError: When `at` or `data` of non-integer type. """ - _ldns.ldns_buffer_write_u32_at(self,at,data) + _ldns.ldns_buffer_write_u32_at(self, at, data) #parameters: ldns_buffer *,size_t,uint32_t, #retvals: - def write_u8(self,data): - """writes the given byte of data at the current position in the buffer + def write_u8(self, data): + """ + Writes the given byte of data at the current position + in the buffer. - :param data: - the 8 bits to write + :param data: The byte to write. + :type data: uint8_t + :throws TypeError: When `data` of non-integer type. """ - _ldns.ldns_buffer_write_u8(self,data) - #parameters: ldns_buffer *,uint8_t, + _ldns.ldns_buffer_write_u8(self, data) + #parameters: ldns_buffer *, uint8_t, #retvals: def write_u8_at(self,at,data): - """writes the given byte of data at the given position in the buffer + """ + Writes the given byte of data at the given position + in the buffer. - :param at: - the position in the buffer - :param data: - the 8 bits to write + :param at: The position in the buffer. + :type at: positive integer + :param data: The byte to write. + :type data: uint8_t + :throws TypeError: When `at` or `data` of non-integer type. """ _ldns.ldns_buffer_write_u8_at(self,at,data) #parameters: ldns_buffer *,size_t,uint8_t, #retvals: - #_LDNS_BUFFER_METHODS# - %} + # + # _LDNS_BUFFER_METHODS + # + %} } - diff --git a/contrib/python/ldns_dname.i b/contrib/python/ldns_dname.i index 0aac54c1060b..cd3f53ea3351 100644 --- a/contrib/python/ldns_dname.i +++ b/contrib/python/ldns_dname.i @@ -14,8 +14,8 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the organization nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -28,169 +28,598 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************/ -%pythoncode %{ + *****************************************************************************/ + + +/* ========================================================================= */ +/* SWIG setting and definitions. */ +/* ========================================================================= */ + +/* + * Not here (with the exception of functions defined in this C code sction), + * must be set in ldns_rdf.i. + */ + + +/* ========================================================================= */ +/* Debugging related code. */ +/* ========================================================================= */ + +/* + * Not here (with the exception of functions defined in this C code sction), + * must be set in ldns_rdf.i. + */ + + +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ + +/* None */ + + +/* ========================================================================= */ +/* Encapsulating Python code. */ +/* ========================================================================= */ + +%pythoncode +%{ class ldns_dname(ldns_rdf): - """Domain name + """ + Domain name. - This class contains methods to read and manipulate domain names. - Domain names are stored in ldns_rdf structures, with the type LDNS_RDF_TYPE_DNAME + This class contains methods to read and manipulate domain name drfs. + Domain names are stored in :class:`ldns_rdf` structures, + with the type LDNS_RDF_TYPE_DNAME. This class encapsulates such + rdfs. **Usage** - >>> import ldns - >>> resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf") - >>> dn1 = ldns.ldns_dname("test.nic.cz") - >>> print dn1 - test.nic.cz. - >>> dn2 = ldns.ldns_dname("nic.cz") - >>> if dn2.is_subdomain(dn1): print dn2,"is subdomain of",dn1 - >>> if dn1.is_subdomain(dn2): print dn1,"is subdomain of",dn2 - test.nic.cz. is subdomain of nic.cz. + >>> import ldns + >>> dn1 = ldns.ldns_dname("test.nic.cz") + >>> print dn1 + test.nic.cz. + >>> dn2 = ldns.ldns_dname("nic.cz") + >>> if dn2.is_subdomain(dn1): print dn2, "is sub-domain of", dn1 + >>> if dn1.is_subdomain(dn2): print dn1, "is sub-domain of", dn2 + test.nic.cz. is sub-domain of nic.cz. + + The following two examples show the creation of :class:`ldns_dname` + from :class:`ldns_rdf`. The first shows the creation of + :class:`ldns_dname` instance which is independent of the original + `rdf`. + + + >>> import ldns + >>> rdf = ldns.ldns_rdf.new_frm_str("a.ns.nic.cz", ldns.LDNS_RDF_TYPE_DNAME) + >>> dn = ldns.ldns_dname(rdf) + >>> print dn + a.ns.nic.cz. + + The latter shows the wrapping of a :class:`ldns_rdf` onto + a :class:`ldns_dname` without the creation of a copy. + + >>> import ldns + >>> dn = ldns.ldns_dname(ldns.ldns_rdf.new_frm_str("a.ns.nic.cz", ldns.LDNS_RDF_TYPE_DNAME), clone=False) + >>> print dn + a.ns.nic.cz. """ - def __init__(self, str): - """Creates a new dname rdf from a string. + def __init__(self, initialiser, clone=True): + """ + Creates a new dname rdf from a string or :class:`ldns_rdf`. - :parameter str: str string to use + :param initialiser: string or :class:`ldns_rdf` + :type initialiser: string or :class:`ldns_rdf` containing + a dname + :param clone: Whether to clone or directly grab the parameter. + :type clone: bool + :throws TypeError: When `initialiser` of invalid type. """ - self.this = _ldns.ldns_dname_new_frm_str(str) + if isinstance(initialiser, ldns_rdf) and \ + (initialiser.get_type() == _ldns.LDNS_RDF_TYPE_DNAME): + if clone == True: + self.this = _ldns.ldns_rdf_clone(initialiser) + else: + self.this = initialiser + else: + self.this = _ldns.ldns_dname_new_frm_str(initialiser) + + # + # LDNS_DNAME_CONSTRUCTORS_ + # @staticmethod - def new_frm_str(str): - """Creates a new dname rdf instance from a string. + def new_frm_str(string): + """ + Creates a new dname rdf instance from a string. - This static method is equivalent to using of default class constructor. + This static method is equivalent to using default + :class:`ldns_dname` constructor. - :parameter str: str string to use + :param string: String to use. + :type string: string + :throws TypeError: When `string` not a string. + :return: (:class:`ldns_dname`) dname rdf. """ - return ldns_dname(str) + return ldns_dname(string) - def absolute(self): - """Checks whether the given dname string is absolute (i.e. ends with a '.') + @staticmethod + def new_frm_rdf(rdf, clone=True): + """ + Creates a new dname rdf instance from a dname :class:`ldns_rdf`. + + This static method is equivalent to using the default + :class:`ldns_dname` constructor. + + :param rdf: A dname :class:`ldns_rdf`. + :type rdf: :class:`ldns_rdf` + :throws TypeError: When `rdf` of inappropriate type. + :param clone: Whether to create a clone or to wrap present + instance. + :type clone: bool + :return: (:class:`ldns_dname`) dname rdf. + """ + return ldns_dname(rdf, clone=clone) + + # + # _LDNS_DNAME_CONSTRUCTORS + # + + def write_to_buffer(self, buffer): + """ + Copies the dname data to the buffer in wire format. + + :param buffer: Buffer to append the result to. + :type param: :class:`ldns_buffer` + :throws TypeError: When `buffer` of non-:class:`ldns_buffer` + type. + :return: (ldns_status) ldns_status + """ + return _ldns.ldns_dname2buffer_wire(buffer, self) + #parameters: ldns_buffer *, const ldns_rdf *, + #retvals: ldns_status + + + # + # LDNS_DNAME_METHODS_ + # - :returns: (bool) True or False + def absolute(self): """ - return self.endswith(".") + Checks whether the given dname string is absolute (i.e., + ends with a '.'). + :return: (bool) True or False + """ + string = self.__str__() + return _ldns.ldns_dname_str_absolute(string) != 0 def make_canonical(self): - """Put a dname into canonical fmt - ie. lowercase it + """ + Put a dname into canonical format (i.e., convert to lower case). """ _ldns.ldns_dname2canonical(self) - def __cmp__(self,other): - """Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6. + def __cmp__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. - :param other: - the second dname rdf to compare - :returns: (int) -1 if dname comes before other, 1 if dname comes after other, and 0 if they are equal. + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (int) -1, 0 or 1 if self comes before other, + self is equal or self comes after other respectively. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - return _ldns.ldns_dname_compare(self,other) + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__cmp__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) - def write_to_buffer(self,buffer): - """Copies the dname data to the buffer in wire format. + def __lt__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. - :param buffer: buffer to append the result to - :returns: (ldns_status) ldns_status + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (bool) True when `self` is less than 'other'. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - return _ldns.ldns_dname2buffer_wire(buffer,self) - #parameters: ldns_buffer *,const ldns_rdf *, - #retvals: ldns_status + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__lt__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) == -1 + + def __le__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. + + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (bool) True when `self` is less than or equal to + 'other'. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. + """ + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__le__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) != 1 + + def __eq__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. + + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (bool) True when `self` is equal to 'other'. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. + """ + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__eq__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) == 0 + + def __ne__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. + + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (bool) True when `self` is not equal to 'other'. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. + """ + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__ne__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) != 0 + + def __gt__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. + + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (bool) True when `self` is greater than 'other'. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. + """ + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__gt__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) == 1 - #LDNS_DNAME_METHODS_# + def __ge__(self, other): + """ + Compares two dname rdf according to the algorithm for + ordering in RFC4034 Section 6. + + :param other: The second dname rdf to compare. + :type other: :class:`ldns_dname` + :throws TypeError: When `other` of invalid type. + :return: (bool) True when `self` is greater than or equal to + 'other'. + + .. note:: + The type checking of parameter `other` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. + """ + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(other, ldns_dname)) and \ + isinstance(other, ldns_rdf) and \ + other.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.__ge__() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Operands must be ldns_dname.") + return _ldns.ldns_dname_compare(self, other) != -1 - def cat(self,rd2): - """concatenates rd2 after this dname (rd2 is copied, this dname is modified) + def cat(self, rd2): + """ + Concatenates rd2 after this dname (`rd2` is copied, + `this` dname is modified). - :param rd2: - the rightside - :returns: (ldns_status) LDNS_STATUS_OK on success + :param rd2: The right-hand side. + :type rd2: :class:`ldns_dname` + :throws TypeError: When `rd2` of invalid type. + :return: (ldns_status) LDNS_STATUS_OK on success + + .. note:: + The type checking of parameter `rd2` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - return _ldns.ldns_dname_cat(self,rd2) - #parameters: ldns_rdf *,ldns_rdf *, + if (not isinstance(rd2, ldns_dname)) and \ + isinstance(rd2, ldns_rdf) and \ + rd2.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.cat() method will" + + " drop the support of ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_cat(self, rd2) + #parameters: ldns_rdf *, ldns_rdf *, #retvals: ldns_status - def cat_clone(self,rd2): - """concatenates two dnames together + def cat_clone(self, rd2): + """ + Concatenates two dnames together. - :param rd2: - the rightside - :returns: (ldns_rdf \*) a new rdf with leftside/rightside + :param rd2: The right-hand side. + :type rd2: :class:`ldns_dname` + :throws TypeError: When `rd2` of invalid type. + :return: (:class:`ldns_dname`) A new rdf with + left-hand side + right-hand side content None when + error. + + .. note:: + The type checking of parameter `rd2` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - return _ldns.ldns_dname_cat_clone(self,rd2) - #parameters: const ldns_rdf *,const ldns_rdf *, + if (not isinstance(rd2, ldns_dname)) and \ + isinstance(rd2, ldns_rdf) and \ + rd2.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.cat_clone() method will" + + " drop the support of ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + ret = _ldns.ldns_dname_cat_clone(self, rd2) + if ret != None: + ret = ldns_dname(ret, clone=False) + return ret + #parameters: const ldns_rdf *, const ldns_rdf *, #retvals: ldns_rdf * - def interval(self,middle,next): - """check if middle lays in the interval defined by prev and next prev <= middle < next. + def interval(self, middle, next): + """ + Check whether `middle` lays in the interval defined by + `this` and `next` (`this` <= `middle` < `next`). - This is usefull for nsec checking + This method is useful for nsec checking. - :param middle: - the dname to check - :param next: - the next dname return 0 on error or unknown, -1 when middle is in the interval, +1 when not - :returns: (int) + :param middle: The dname to check. + :type middle: :class:`ldns_dname` + :param next: The boundary. + :type next: :class:`ldns_dname` + :throws TypeError: When `middle` or `next` of + non-:class:`ldns_rdf` type. + :throws Exception: When non-dname rdfs compared. + :return: (int) 0 on error or unknown, + -1 when middle is in the interval, 1 when not. + + .. note:: + The type checking of parameters is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - return _ldns.ldns_dname_interval(self,middle,next) - #parameters: const ldns_rdf *,const ldns_rdf *,const ldns_rdf *, + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(middle, ldns_rdf)) or \ + (not isinstance(next, ldns_rdf)): + raise TypeError("Parameters must be derived from ldns_dname.") + if (self.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ + (middle.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ + (next.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("All operands must be dname rdfs.") + if (not isinstance(middle, ldns_dname)) or \ + (not isinstance(next, ldns_dname)): + warnings.warn("The ldns_dname.interval() method will" + + " drop the possibility to compare ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_interval(self, middle, next) + #parameters: const ldns_rdf *, const ldns_rdf *, const ldns_rdf *, #retvals: int - def is_subdomain(self,parent): - """Tests wether the name sub falls under parent (i.e. is a subdomain of parent). + def is_subdomain(self, parent): + """ + Tests whether the name of the instance falls under + `parent` (i.e., is a sub-domain of `parent`). This function will return false if the given dnames are equal. - :param parent: - (ldns_rdf) the parent's name - :returns: (bool) true if sub falls under parent, otherwise false + :param parent: The parent's name. + :type parent: :class:`ldns_dname` + :throws TypeError: When `parent` of non-:class:`ldns_rdf` + or derived type. + :return: (bool) True if `this` falls under `parent`, otherwise + False. + + .. note:: + The type checking of parameters is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - return _ldns.ldns_dname_is_subdomain(self,parent) - #parameters: const ldns_rdf *,const ldns_rdf *, + if (not isinstance(parent, ldns_dname)) and \ + isinstance(parent, ldns_rdf) and \ + parent.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_dname.is_subdomain() method will" + + " drop the support of ldns_rdf." + + " Convert arguments to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_is_subdomain(self, parent) + #parameters: const ldns_rdf *, const ldns_rdf *, #retvals: bool - def label(self,labelpos): - """look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label. + def label(self, labelpos): + """ + Look inside the rdf and retrieve a specific label. The labels are numbered starting from 0 (left most). - - :param labelpos: - return the label with this number - :returns: (ldns_rdf \*) a ldns_rdf* with the label as name or NULL on error + + :param labelpos: Index of the label. (Labels are numbered + 0, which is the left most.) + :type labelpos: integer + :throws TypeError: When `labelpos` of non-integer type. + :return: (:class:`ldns_dname`) A new rdf with the label + as name or None on error. """ - return _ldns.ldns_dname_label(self,labelpos) - #parameters: const ldns_rdf *,uint8_t, + ret = _ldns.ldns_dname_label(self, labelpos) + if ret != None: + ret = ldns_dname(ret, clone=False) + return ret + #parameters: const ldns_rdf *, uint8_t, #retvals: ldns_rdf * def label_count(self): - """count the number of labels inside a LDNS_RDF_DNAME type rdf. + """ + Counts the number of labels. - :returns: (uint8_t) the number of labels + :return: (uint8_t) the number of labels. Will return 0 + if not a dname. """ return _ldns.ldns_dname_label_count(self) #parameters: const ldns_rdf *, #retvals: uint8_t def left_chop(self): - """chop one label off the left side of a dname. + """ + Chop one label off the left side of a dname. - so wwww.nlnetlabs.nl, becomes nlnetlabs.nl + (e.g., wwww.nlnetlabs.nl, becomes nlnetlabs.nl) - :returns: (ldns_rdf \*) the remaining dname + :return: (:class:`ldns_dname`) The remaining dname or None + when error. """ - return _ldns.ldns_dname_left_chop(self) + return ldns_dname(_ldns.ldns_dname_left_chop(self), clone=False) #parameters: const ldns_rdf *, #retvals: ldns_rdf * def reverse(self): - """Returns a clone of the given dname with the labels reversed. + """ + Returns a clone of the given dname with the labels reversed. - :returns: (ldns_rdf \*) clone of the dname with the labels reversed. + :return: (:class:`ldns_dname`) A clone of the dname with + the labels reversed. """ - return _ldns.ldns_dname_reverse(self) + return ldns_dname(_ldns.ldns_dname_reverse(self), clone=False) #parameters: const ldns_rdf *, #retvals: ldns_rdf * - #_LDNS_DNAME_METHODS# + # + # _LDNS_DNAME_METHODS + # %} - diff --git a/contrib/python/ldns_dnssec.i b/contrib/python/ldns_dnssec.i index 6c0656484666..3c29bb4406c9 100644 --- a/contrib/python/ldns_dnssec.i +++ b/contrib/python/ldns_dnssec.i @@ -247,6 +247,29 @@ ldns_status ldns_dnssec_zone_sign_defcb(ldns_dnssec_zone *zone, ldns_rr_list *ne return ldns_dnssec_zone_sign(zone, new_rrs, key_list, ldns_dnssec_default_replace_signatures, NULL); } + +ldns_status ldns_dnssec_zone_add_rr_(ldns_dnssec_zone *zone, ldns_rr *rr) +{ + ldns_rr *new_rr; + ldns_status status; + + new_rr = ldns_rr_clone(rr); + + /* + * A clone of the RR is created to be stored in the DNSSEC zone. + * The Python engine frees a RR object as soon it's reference count + * reaches zero. The code must avoid double freeing or accessing of freed + * memory. + */ + + status = ldns_dnssec_zone_add_rr(zone, new_rr); + + if (status != LDNS_STATUS_OK) { + ldns_rr_free(new_rr); + } + + return status; +} %} %extend ldns_dnssec_zone { @@ -413,7 +436,7 @@ ldns_status ldns_dnssec_zone_sign_defcb(ldns_dnssec_zone *zone, ldns_rr_list *ne The RR to add :returns: (ldns_status) LDNS_STATUS_OK on success, an error code otherwise """ - return _ldns.ldns_dnssec_zone_add_rr(self,rr) + return _ldns.ldns_dnssec_zone_add_rr_(self,rr) #parameters: ldns_dnssec_zone *,ldns_rr *, #retvals: ldns_status diff --git a/contrib/python/ldns_packet.i b/contrib/python/ldns_packet.i index a1ad6b7c8214..9316479f13b3 100644 --- a/contrib/python/ldns_packet.i +++ b/contrib/python/ldns_packet.i @@ -217,7 +217,7 @@ This simple example instances a resolver in order to resolve NS for nic.cz. def opcode2str(self): """Converts a packet opcode to its mnemonic and returns that as an allocated null-terminated string.""" - return _ldns.ldns_pkt_opcode2str(sefl.get_opcode()) + return _ldns.ldns_pkt_opcode2str(self.get_opcode()) def rcode2str(self): """Converts a packet rcode to its mnemonic and returns that as an allocated null-terminated string.""" diff --git a/contrib/python/ldns_rdf.i b/contrib/python/ldns_rdf.i index 5a7e30079646..edff4d624992 100644 --- a/contrib/python/ldns_rdf.i +++ b/contrib/python/ldns_rdf.i @@ -1,5 +1,5 @@ /****************************************************************************** - * ldns_rdata.i: LDNS record data + * ldns_rdf.i: LDNS record data * * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz) * Karel Slany (slany AT fit.vutbr.cz) @@ -14,8 +14,8 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the organization nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -28,399 +28,815 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************/ + *****************************************************************************/ -//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 (Python_str_Check($input)) { -#ifdef SWIG_Python_str_AsChar - tmp = ldns_dname_new_frm_str(SWIG_Python_str_AsChar($input)); -#else - tmp = ldns_dname_new_frm_str(PyString_AsString($input)); -#endif - if (tmp == NULL) { - %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); - } - $1 = ($1_ltype) tmp; - } else { - res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_ldns_struct_rdf, 0 | 0 ); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "ldns_rdf const *", $symname, $argnum); - } - $1 = ($1_ltype) argp; - } -} -%typemap(in,numinputs=0,noblock=1) (ldns_rdf **) +/* ========================================================================= */ +/* SWIG setting and definitions. */ +/* ========================================================================= */ + +/* Creates a temporary instance of (ldns_rdf *). */ +%typemap(in, numinputs=0, noblock=1) (ldns_rdf **) { - ldns_rdf *$1_rdf; - $1 = &$1_rdf; + ldns_rdf *$1_rdf = NULL; + $1 = &$1_rdf; } -// result generation -%typemap(argout,noblock=1) (ldns_rdf **) +/* Result generation, appends (ldns_rdf *) after the result. */ +%typemap(argout, noblock=1) (ldns_rdf **) { - $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_rdf), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 )); + $result = SWIG_Python_AppendOutput($result, + SWIG_NewPointerObj(SWIG_as_voidptr($1_rdf), + SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0)); } -%nodefaultctor ldns_struct_rdf; //no default constructor & destructor -%nodefaultdtor ldns_struct_rdf; +/* + * Automatic conversion of const (ldns_rdf *) parameter from string. + * Argument default value. + */ +%typemap(arginit, noblock=1) const ldns_rdf * +{ + char *$1_str = NULL; +} + +/* + * Automatic conversion of const (ldns_rdf *) parameter from string. + * Preparation of arguments. + */ +%typemap(in, noblock=1) const ldns_rdf * (void* argp, $1_ltype tmp = 0, int res) +{ + if (Python_str_Check($input)) { + $1_str = SWIG_Python_str_AsChar($input); + if ($1_str == NULL) { + %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); + } + tmp = ldns_dname_new_frm_str($1_str); + if (tmp == NULL) { + %argument_fail(SWIG_TypeError, "char *", $symname, $argnum); + } + $1 = ($1_ltype) tmp; + } else { + res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_ldns_struct_rdf, 0 | 0); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "ldns_rdf const *", $symname, $argnum); + } + $1 = ($1_ltype) argp; + } +} + +/* + * Automatic conversion of const (ldns_rdf *) parameter from string. + * Freeing of allocated memory (in Python 3 when daling with strings). + */ +%typemap(freearg, noblock=1) const ldns_rdf * +{ + if ($1_str != NULL) { + /* Is not NULL only when a conversion form string occurred. */ + SWIG_Python_str_DelForPy3($1_str); /* Is a empty macro for Python < 3. */ + } +} + +%nodefaultctor ldns_struct_rdf; /* No default constructor. */ +%nodefaultdtor ldns_struct_rdf; /* No default destructor. */ + + +/* + * This file must contain all %newobject and %delobject tags also for + * ldns_dname. This is because the ldns_dname is a derived class from ldns_rdf. + */ -%newobject ldns_dname_new; -%newobject ldns_dname_new_frm_str; -%newobject ldns_dname_new_frm_data; %newobject ldns_rdf_new; %newobject ldns_rdf_new_frm_str; %newobject ldns_rdf_new_frm_data; +%newobject ldns_rdf_address_reverse; +%newobject ldns_rdf_clone; +%newobject ldns_rdf2str; + +%newobject ldns_dname_new; +%newobject ldns_dname_new_frm_str; +%newobject ldns_dname_new_frm_data; + +%newobject ldns_dname_cat_clone; +%newobject ldns_dname_label; +%newobject ldns_dname_left_chop; +%newobject ldns_dname_reverse; + %delobject ldns_rdf_deep_free; %delobject ldns_rdf_free; + +/* + * Should the ldns_rdf_new() also be marked as deleting its data parameter? + */ +%delobject ldns_rdf_set_data; /* Because data are directly coupled into rdf. */ + %rename(ldns_rdf) ldns_struct_rdf; -%inline %{ -const char *ldns_rdf_type2str(const ldns_rdf *rdf) -{ - if (rdf) { - switch(ldns_rdf_get_type(rdf)) { - case LDNS_RDF_TYPE_NONE: return 0; - case LDNS_RDF_TYPE_DNAME: return "DNAME"; - case LDNS_RDF_TYPE_INT8: return "INT8"; - case LDNS_RDF_TYPE_INT16: return "INT16"; - case LDNS_RDF_TYPE_INT32: return "INT32"; - case LDNS_RDF_TYPE_PERIOD: return "PERIOD"; - case LDNS_RDF_TYPE_TSIGTIME: return "TSIGTIME"; - case LDNS_RDF_TYPE_A: return "A"; - case LDNS_RDF_TYPE_AAAA: return "AAAA"; - case LDNS_RDF_TYPE_STR: return "STR"; - case LDNS_RDF_TYPE_APL: return "APL"; - case LDNS_RDF_TYPE_B32_EXT: return "B32_EXT"; - case LDNS_RDF_TYPE_B64: return "B64"; - case LDNS_RDF_TYPE_HEX: return "HEX"; - case LDNS_RDF_TYPE_NSEC: return "NSEC"; - case LDNS_RDF_TYPE_NSEC3_SALT: return "NSEC3_SALT"; - case LDNS_RDF_TYPE_TYPE: return "TYPE"; - case LDNS_RDF_TYPE_CLASS: return "CLASS"; - case LDNS_RDF_TYPE_CERT_ALG: return "CER_ALG"; - case LDNS_RDF_TYPE_ALG: return "ALG"; - case LDNS_RDF_TYPE_UNKNOWN: return "UNKNOWN"; - case LDNS_RDF_TYPE_TIME: return "TIME"; - case LDNS_RDF_TYPE_LOC: return "LOC"; - case LDNS_RDF_TYPE_WKS: return "WKS"; - case LDNS_RDF_TYPE_SERVICE: return "SERVICE"; - case LDNS_RDF_TYPE_NSAP: return "NSAP"; - case LDNS_RDF_TYPE_ATMA: return "ATMA"; - case LDNS_RDF_TYPE_IPSECKEY: return "IPSECKEY"; - case LDNS_RDF_TYPE_TSIG: return "TSIG"; - case LDNS_RDF_TYPE_INT16_DATA: return "INT16_DATA"; - case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: return "NSEC3_NEXT_OWNER"; - } - } - return 0; -} -%} +/* ========================================================================= */ +/* Debugging related code. */ +/* ========================================================================= */ #ifdef LDNS_DEBUG %rename(__ldns_rdf_deep_free) ldns_rdf_deep_free; %rename(__ldns_rdf_free) ldns_rdf_free; -%inline %{ -void _ldns_rdf_free (ldns_rdf* r) { - printf("******** LDNS_RDF free 0x%lX ************\n", (long unsigned int)r); - ldns_rdf_free(r); -} +%inline +%{ + /*! + * @brief Prints information about deallocated rdf and deallocates. + */ + void _ldns_rdf_deep_free (ldns_rdf *r) + { + printf("******** LDNS_RDF deep free 0x%lX ************\n", + (long unsigned int) r); + ldns_rdf_deep_free(r); + } + + /*! + * @brief Prints information about deallocated rdf and deallocates. + */ + void _ldns_rdf_free (ldns_rdf* r) + { + printf("******** LDNS_RDF free 0x%lX ************\n", + (long unsigned int) r); + ldns_rdf_free(r); + } %} -#else +#else /* !LDNS_DEBUG */ %rename(_ldns_rdf_deep_free) ldns_rdf_deep_free; %rename(_ldns_rdf_free) ldns_rdf_free; -#endif +#endif /* LDNS_DEBUG */ + + +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ -%newobject ldns_rdf2str; +%inline +%{ + /*! + * @brief returns a human readable string containing rdf type. + */ + const char *ldns_rdf_type2str(const ldns_rdf *rdf) + { + if (rdf) { + switch(ldns_rdf_get_type(rdf)) { + case LDNS_RDF_TYPE_NONE: return 0; + case LDNS_RDF_TYPE_DNAME: return "DNAME"; + case LDNS_RDF_TYPE_INT8: return "INT8"; + case LDNS_RDF_TYPE_INT16: return "INT16"; + case LDNS_RDF_TYPE_INT32: return "INT32"; + case LDNS_RDF_TYPE_A: return "A"; + case LDNS_RDF_TYPE_AAAA: return "AAAA"; + case LDNS_RDF_TYPE_STR: return "STR"; + case LDNS_RDF_TYPE_APL: return "APL"; + case LDNS_RDF_TYPE_B32_EXT: return "B32_EXT"; + case LDNS_RDF_TYPE_B64: return "B64"; + case LDNS_RDF_TYPE_HEX: return "HEX"; + case LDNS_RDF_TYPE_NSEC: return "NSEC"; + case LDNS_RDF_TYPE_TYPE: return "TYPE"; + case LDNS_RDF_TYPE_CLASS: return "CLASS"; + case LDNS_RDF_TYPE_CERT_ALG: return "CER_ALG"; + case LDNS_RDF_TYPE_ALG: return "ALG"; + case LDNS_RDF_TYPE_UNKNOWN: return "UNKNOWN"; + case LDNS_RDF_TYPE_TIME: return "TIME"; + case LDNS_RDF_TYPE_PERIOD: return "PERIOD"; + case LDNS_RDF_TYPE_TSIGTIME: return "TSIGTIME"; + case LDNS_RDF_TYPE_TSIG: return "TSIG"; + case LDNS_RDF_TYPE_INT16_DATA: return "INT16_DATA"; + case LDNS_RDF_TYPE_SERVICE: return "SERVICE"; + case LDNS_RDF_TYPE_LOC: return "LOC"; + case LDNS_RDF_TYPE_WKS: return "WKS"; + case LDNS_RDF_TYPE_NSAP: return "NSAP"; + case LDNS_RDF_TYPE_ATMA: return "ATMA"; + case LDNS_RDF_TYPE_IPSECKEY: return "IPSECKEY"; + case LDNS_RDF_TYPE_NSEC3_SALT: return "NSEC3_SALT"; + case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: + return "NSEC3_NEXT_OWNER"; + } + } + return 0; + } +%} + + +/* ========================================================================= */ +/* Encapsulating Python code. */ +/* ========================================================================= */ %feature("docstring") ldns_struct_rdf "Resource record data field. -The data is a network ordered array of bytes, which size is specified by the (16-bit) size field. To correctly parse it, use the type specified in the (16-bit) type field with a value from ldns_rdf_type." +The data is a network ordered array of bytes, which size is specified +by the (16-bit) size field. To correctly parse it, use the type +specified in the (16-bit) type field with a value from ldns_rdf_type." %extend ldns_struct_rdf { - %pythoncode %{ + %pythoncode + %{ def __init__(self): - raise Exception("This class can't be created directly. Please use: ldns_rdf_new, ldns_rdf_new_frm_data, ldns_rdf_new_frm_str, ldns_rdf_new_frm_fp, ldns_rdf_new_frm_fp_l") + """ + Cannot be created directly from Python. + """ + raise Exception("This class can't be created directly. " + + "Please use: ldns_rdf_new, ldns_rdf_new_frm_data, " + + "ldns_rdf_new_frm_str, ldns_rdf_new_frm_fp, " + + "ldns_rdf_new_frm_fp_l") __swig_destroy__ = _ldns._ldns_rdf_deep_free - #LDNS_RDF_CONSTRUCTORS_# + # + # LDNS_RDF_CONSTRUCTORS_ + # + @staticmethod - def new_frm_str(str, rr_type, raiseException = True): - """Creates a new rdf from a string of a given type. + def new_frm_str(string, rr_type, raiseException = True): + """ + Creates a new rdf from a string of a given type. - :param str: string to use - :param rr_type: the type of RDF. See predefined `RDF_TYPE_` constants - :param raiseException: if True, an exception occurs in case a RDF object can't be created - :returns: RDF object or None. If the object can't be created and raiseException is True, an exception occurs. + :param string: string to use + :type string: string + :param rr_type: The type of the rdf. See predefined `RDF_TYPE_` + constants. + :type rr_type: integer + :param raiseException: If True, an exception occurs in case + a RDF object can't be created. + :type raiseException: bool + :throws TypeError: When parameters of mismatching types. + :throws Exception: When raiseException set and rdf couldn't + be created. + :return: :class:`ldns_rdf` object or None. If the object + can't be created and `raiseException` is True, + an exception occurs. **Usage** - >>> rdf = ldns.ldns_rdf.new_frm_str("74.125.43.99",ldns.LDNS_RDF_TYPE_A) - >>> print rdf, rdf.get_type_str() - A 74.125.43.99 - >>> name = ldns.ldns_resolver.new_frm_file().get_name_by_addr(rdf) - >>> if (name): print name - 99.43.125.74.in-addr.arpa. 85277 IN PTR bw-in-f99.google.com. + + >>> rdf = ldns.ldns_rdf.new_frm_str("74.125.43.99", ldns.LDNS_RDF_TYPE_A) + >>> print rdf, rdf.get_type_str() + A 74.125.43.99 + >>> name = ldns.ldns_resolver.new_frm_file().get_name_by_addr(rdf) + >>> if (name): print name + 99.43.125.74.in-addr.arpa. 85277 IN PTR bw-in-f99.google.com. """ - rr = _ldns.ldns_rdf_new_frm_str(rr_type, str) - if not rr: - if (raiseException): raise Exception("Can't create query packet, error: %d" % status) + rr = _ldns.ldns_rdf_new_frm_str(rr_type, string) + if (not rr) and raiseException: + raise Exception("Can't create query packet, " + + "error: %d" % status) return rr - #_LDNS_RDF_CONSTRUCTORS# + + # + # _LDNS_RDF_CONSTRUCTORS + # def __str__(self): - """Converts the rdata field to presentation format""" + """ + Converts the rdata field to presentation format. + """ return _ldns.ldns_rdf2str(self) - def __cmp__(self,other): - """compares two rdf's on their wire formats. + def __cmp__(self, other): + """ + Compares two rdfs on their wire formats. - (To order dnames according to rfc4034, use ldns_dname_compare) + (To order dnames according to rfc4034, use ldns_dname_compare.) - :param other: - the second one RDF - :returns: (int) 0 if equal -1 if self comes before other +1 if other comes before self + :param other: The second one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (int) -1, 0 or 1 if self comes before other, + is equal or self comes after other respectively. """ - return _ldns.ldns_rdf_compare(self,other) - - def print_to_file(self,output): - """Prints the data in the rdata field to the given file stream (in presentation format).""" - _ldns.ldns_rdf_print(output,self) + return _ldns.ldns_rdf_compare(self, other) + + def __lt__(self, other): + """ + Compares two rdfs on their formats. + + :param other: The socond one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (bool) True when `self` is less than 'other'. + """ + return _ldns.ldns_rdf_compare(self, other) == -1 + + def __le__(self, other): + """ + Compares two rdfs on their formats. + + :param other: The socond one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (bool) True when `self` is less than or equal to + 'other'. + """ + return _ldns.ldns_rdf_compare(self, other) != 1 + + def __eq__(self, other): + """ + Compares two rdfs on their formats. + + :param other: The socond one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (bool) True when `self` is equal to 'other'. + """ + return _ldns.ldns_rdf_compare(self, other) == 0 + + def __ne__(self, other): + """ + Compares two rdfs on their formats. + + :param other: The socond one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (bool) True when `self` is not equal to 'other'. + """ + return _ldns.ldns_rdf_compare(self, other) != 0 + + def __gt__(self, other): + """ + Compares two rdfs on their formats. + + :param other: The socond one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (bool) True when `self` is greater than 'other'. + """ + return _ldns.ldns_rdf_compare(self, other) == 1 + + def __ge__(self, other): + """ + Compares two rdfs on their formats. + + :param other: The socond one RDF. + :type other: :class:`ldns_rdf` + :throws TypeError: When `other` of non-:class:`ldns_rdf` type. + :return: (bool) True when `self` is greater than or equal to + 'other'. + """ + return _ldns.ldns_rdf_compare(self, other) != -1 + + def print_to_file(self, output): + """ + Prints the data in the rdata field to the given `output` file + stream (in presentation format). + """ + _ldns.ldns_rdf_print(output, self) def get_type_str(self): - """Converts type to string""" + """ + Returns the type of the rdf as a human readable string. + + :return: String containing rdf type. + """ return ldns_rdf_type2str(self) def write_to_buffer(self, buffer): - """Copies the rdata data to the buffer in wire format. + """ + Copies the rdata data to the buffer in wire format. - :param buffer: buffer to append the result to - :returns: (ldns_status) ldns_status + :param buffer: Buffer to append the rdf to. + :type param: :class:`ldns_buffer` + :throws TypeError: When `buffer` of non-:class:`ldns_buffer` + type. + :return: (ldns_status) ldns_status """ return _ldns.ldns_rdf2buffer_wire(buffer, self) - #parameters: ldns_buffer *,const ldns_rdf *, + #parameters: ldns_buffer *, const ldns_rdf *, #retvals: ldns_status def write_to_buffer_canonical(self, buffer): - """Copies the rdata data to the buffer in wire format If the rdata is a dname, the letters will be lowercased during the conversion. + """ + Copies the rdata data to the buffer in wire format. + If the rdata is a dname, the letters will be converted + to lower case during the conversion. - :param buffer: LDNS buffer - :returns: (ldns_status) ldns_status + :param buffer: LDNS buffer. + :type buffer: :class:`ldns_buffer` + :throws TypeError: When `buffer` of non-:class:`ldns_buffer` + type. + :return: (ldns_status) ldns_status """ return _ldns.ldns_rdf2buffer_wire_canonical(buffer, self) - #parameters: ldns_buffer *,const ldns_rdf *, + #parameters: ldns_buffer *, const ldns_rdf *, #retvals: ldns_status - #LDNS_RDF_METHODS_# + # + # LDNS_RDF_METHODS_ + # + def address_reverse(self): - """reverses an rdf, only actually useful for AAAA and A records. + """ + Reverses an rdf, only actually useful for AAAA and A records. The returned rdf has the type LDNS_RDF_TYPE_DNAME! - :returns: (ldns_rdf \*) the reversed rdf (a newly created rdf) + :return: (:class:`ldns_rdf`) The reversed rdf + (a newly created rdf). """ return _ldns.ldns_rdf_address_reverse(self) #parameters: ldns_rdf *, #retvals: ldns_rdf * def clone(self): - """clones a rdf structure. + """ + Clones a rdf structure. - The data is copied. + The data are copied. - :returns: (ldns_rdf \*) a new rdf structure + :return: (:class:`ldns_rdf`) A new rdf structure. """ return _ldns.ldns_rdf_clone(self) #parameters: const ldns_rdf *, #retvals: ldns_rdf * def data(self): - """returns the data of the rdf. + """ + Returns the data of the rdf. - :returns: (uint8_t \*) uint8_t* pointer to the rdf's data + :return: (uint8_t \*) uint8_t* pointer to the rdf's data. """ return _ldns.ldns_rdf_data(self) #parameters: const ldns_rdf *, #retvals: uint8_t * def get_type(self): - """returns the type of the rdf. + """ + Returns the type of the rdf. - We need to insert _get_ here to prevent conflict the the rdf_type TYPE. + We need to prepend the prefix get_ here to prevent conflict + with the rdf_type TYPE. - :returns: (ldns_rdf_type) ldns_rdf_type with the type + :return: (ldns_rdf_type) Identifier of the type. """ return _ldns.ldns_rdf_get_type(self) #parameters: const ldns_rdf *, #retvals: ldns_rdf_type - def set_data(self,data): - """sets the size of the rdf. + def set_data(self, data): + """ + Sets the data portion of the rdf. + + The data are not copied, but are assigned to the rdf, + `data` are decoupled from the Python engine. - :param data: + :param data: Data to be set. + :type data: void \* """ - _ldns.ldns_rdf_set_data(self,data) - #parameters: ldns_rdf *,void *, + _ldns.ldns_rdf_set_data(self, data) + #parameters: ldns_rdf *, void *, #retvals: - def set_size(self,size): - """sets the size of the rdf. + def set_size(self, size): + """ + Sets the size of the rdf. - :param size: - the new size + :param size: The new size. + :type size: integer + :throws TypeError: When size of non-integer type. """ _ldns.ldns_rdf_set_size(self,size) #parameters: ldns_rdf *,size_t, #retvals: - def set_type(self,atype): - """sets the size of the rdf. + def set_type(self, atype): + """ + Sets the type of the rdf. - :param atype: + :param atype: rdf type + :type atype: integer + :throws TypeError: When atype of non-integer type. """ - _ldns.ldns_rdf_set_type(self,atype) - #parameters: ldns_rdf *,ldns_rdf_type, + _ldns.ldns_rdf_set_type(self, atype) + #parameters: ldns_rdf *, ldns_rdf_type, #retvals: def size(self): - """returns the size of the rdf. + """ + Returns the size of the rdf. - :returns: (size_t) uint16_t with the size + :return: (size_t) uint16_t with the size. """ return _ldns.ldns_rdf_size(self) #parameters: const ldns_rdf *, #retvals: size_t @staticmethod - def dname_new_frm_str(str): - """Creates a new dname rdf instance from a string. + def dname_new_frm_str(string): + """ + Creates a new dname rdf instance from a given string. - This static method is equivalent to using of default class constructor. + This static method is equivalent to using of default + :class:`ldns_rdf` constructor. - :parameter str: str string to use + :parameter string: String to use. + :type string: string + :throws TypeError: When not a string used. + :return: :class:`ldns_rdf` or None if error. + + .. warning:: + + It is scheduled to be deprecated and removed. Use + :class:`ldns_dname` constructor instead. """ - return _ldns.ldns_dname_new_frm_str(str) + warnings.warn("The ldns_rdf.dname_new_frm_str() method is" + + " scheduled to be deprecated in future releases." + + " Use ldsn_dname constructor instead.", + PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_new_frm_str(string) def absolute(self): - """Checks whether the given dname string is absolute (i.e. ends with a '.') + """ + Checks whether the given dname string is absolute + (i.e., ends with a '.'). + + :return: (bool) True or False - :returns: (bool) True or False + .. note:: + + This method was malfunctioning in ldns-1.3.16 and also + possibly earlier. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname` to use the method. """ - return self.endswith(".") + warnings.warn("The ldns_rdf.absolute() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + if self.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + string = self.__str__() + return _ldns.ldns_dname_str_absolute(string) != 0 + else: + return False def make_canonical(self): - """Put a dname into canonical fmt - ie. lowercase it """ + Put a dname into canonical format (i.e., convert to lower case). + + Performs no action if not a dname. + + .. warning:: + + This method is scheduled to be deprecated and removed. + Convert :class:`ldns_rdf` to :class:`ldns_dname` to use + the method. + """ + warnings.warn("The ldns_rdf.make_canonical() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) _ldns.ldns_dname2canonical(self) - def dname_compare(self,other): - """Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6. - - :param other: - the second dname rdf to compare - :returns: (int) -1 if dname comes before other, 1 if dname comes after other, and 0 if they are equal. + def dname_compare(self, other): """ - return _ldns.ldns_dname_compare(self,other) + Compares two dname rdf according to the algorithm + for ordering in RFC4034 Section 6. - def cat(self,rd2): - """concatenates rd2 after this dname (rd2 is copied, this dname is modified) + :param other: The second dname rdf to compare. + :type other: :class:`ldns_rdf` + :throws TypeError: When not a :class:`ldns_rdf` used. + :throws Exception: When not dnames compared. + :return: (int) -1, 0 or 1 if `self` comes before `other`, + `self` is equal or `self` comes after `other` respectively. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. + """ + warnings.warn("The ldns_rdf.dname_compare() method is" + + " scheduled to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if not isinstance(other, ldns_rdf): + raise TypeError("Parameter must be derived from ldns_rdf.") + if (self.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ + (other.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("Both operands must be dname rdfs.") + return _ldns.ldns_dname_compare(self, other) + + def cat(self, rd2): + """ + Concatenates `rd2` after `this` dname (`rd2` is copied, + `this` dname is modified). - :param rd2: - the rightside - :returns: (ldns_status) LDNS_STATUS_OK on success + :param rd2: The right-hand side. + :type rd2: :class:`ldns_rdf` + :throws TypeError: When `rd2` of non-:class:`ldns_rdf` or + non-:class:`ldns_dname` type. + :return: (ldns_status) LDNS_STATUS_OK on success. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ - return _ldns.ldns_dname_cat(self,rd2) - #parameters: ldns_rdf *,ldns_rdf *, + warnings.warn("The ldns_rdf.cat() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_cat(self, rd2) + #parameters: ldns_rdf *, ldns_rdf *, #retvals: ldns_status - def cat_clone(self,rd2): - """concatenates two dnames together - - :param rd2: - the rightside - :returns: (ldns_rdf \*) a new rdf with leftside/rightside + def cat_clone(self, rd2): + """ + Concatenates two dnames together. + + :param rd2: The right-hand side. + :type rd2: :class:`ldns_rdf` + :throws TypeError: When `rd2` of non-:class:`ldns_rdf` or + non-:class:`ldns_dname` type. + :return: (:class:`ldns_rdf`) A new rdf with + left-hand side + right-hand side content None when + error. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ - return _ldns.ldns_dname_cat_clone(self,rd2) - #parameters: const ldns_rdf *,const ldns_rdf *, + warnings.warn("The ldns_rdf.cat_clone() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_cat_clone(self, rd2) + #parameters: const ldns_rdf *, const ldns_rdf *, #retvals: ldns_rdf * - def interval(self,middle,next): - """check if middle lays in the interval defined by prev and next prev <= middle < next. - - This is usefull for nsec checking - - :param middle: - the dname to check - :param next: - the next dname return 0 on error or unknown, -1 when middle is in the interval, +1 when not - :returns: (int) + def interval(self, middle, next): """ - return _ldns.ldns_dname_interval(self,middle,next) - #parameters: const ldns_rdf *,const ldns_rdf *,const ldns_rdf *, + Check whether the `middle` lays in the interval defined by + `this` and `next` (`this` <= `middle` < `next`). + + This method is useful for nsec checking + + :param middle: The dname to check. + :type middle: :class:`ldns_rdf` + :param next: The boundary. + :type next: :class:`ldns_rdf` + :throws TypeError: When `middle` or `next` of + non-:class:`ldns_rdf` type. + :throws Exception: When non-dname rdfs compared. + :return: (int) 0 on error or unknown, + -1 when middle is in the interval, 1 when not. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. + """ + warnings.warn("The ldns_rdf.interval() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + # + # The wrapped function generates asserts instead of setting + # error status. They cannot be caught from Python so a check + # is necessary. + # + if (not isinstance(middle, ldns_rdf)) or \ + (not isinstance(next, ldns_rdf)): + raise TypeError("Parameters must be derived from ldns_rdf.") + if (self.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ + (middle.get_type() != _ldns.LDNS_RDF_TYPE_DNAME) or \ + (next.get_type() != _ldns.LDNS_RDF_TYPE_DNAME): + raise Exception("All operands must be dname rdfs.") + return _ldns.ldns_dname_interval(self, middle, next) + #parameters: const ldns_rdf *, const ldns_rdf *, const ldns_rdf *, #retvals: int - def is_subdomain(self,parent): - """Tests wether the name sub falls under parent (i.e. is a subdomain of parent). + def is_subdomain(self, parent): + """ + Tests whether the name of the given instance falls under + `parent` (i.e., is a sub-domain of `parent`). - This function will return false if the given dnames are equal. + This function will return False if the given dnames + are equal. - :param parent: - (ldns_rdf) the parent's name - :returns: (bool) true if sub falls under parent, otherwise false + :param parent: The parent's name. + :type parent: :class:`ldns_rdf` + :throws TypeError: When `parent` of non-:class:`ldns_rdf` type. + :return: (bool) True if `this` falls under `parent`, otherwise + False. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ - return _ldns.ldns_dname_is_subdomain(self,parent) - #parameters: const ldns_rdf *,const ldns_rdf *, + warnings.warn("The ldns_rdf.is_subdomain() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_is_subdomain(self, parent) + #parameters: const ldns_rdf *, const ldns_rdf *, #retvals: bool - def label(self,labelpos): - """look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label. + def label(self, labelpos): + """ + Look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try + and retrieve a specific label. The labels are numbered starting from 0 (left most). - :param labelpos: - return the label with this number - :returns: (ldns_rdf \*) a ldns_rdf* with the label as name or NULL on error + :param labelpos: Index of the label. (Labels are numbered + 0, which is the left most.) + :type labelpos: integer + :throws TypeError: When `labelpos` of non-integer type. + :return: (:class:`ldns_rdf`) A new rdf with the label + as name or None on error. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ - return _ldns.ldns_dname_label(self,labelpos) - #parameters: const ldns_rdf *,uint8_t, + warnings.warn("The ldns_rdf.label() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) + return _ldns.ldns_dname_label(self, labelpos) + #parameters: const ldns_rdf *, uint8_t, #retvals: ldns_rdf * def label_count(self): - """count the number of labels inside a LDNS_RDF_DNAME type rdf. + """ + Count the number of labels inside a LDNS_RDF_DNAME type rdf. - :returns: (uint8_t) the number of labels + :return: (uint8_t) The number of labels. Will return 0 if + not a dname. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ + warnings.warn("The ldns_rdf.label_count() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) return _ldns.ldns_dname_label_count(self) #parameters: const ldns_rdf *, #retvals: uint8_t def left_chop(self): - """chop one label off the left side of a dname. + """ + Chop one label off the left side of a dname. - so wwww.nlnetlabs.nl, becomes nlnetlabs.nl + (e.g., wwww.nlnetlabs.nl, becomes nlnetlabs.nl) - :returns: (ldns_rdf \*) the remaining dname + :return: (:class:`ldns_rdf`) The remaining dname or None when + error. + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ + warnings.warn("The ldns_rdf.left_chop() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) return _ldns.ldns_dname_left_chop(self) #parameters: const ldns_rdf *, #retvals: ldns_rdf * def reverse(self): - """Returns a clone of the given dname with the labels reversed. + """ + Returns a clone of the given dname with the labels reversed. + + When reversing non-dnames a "." (root name) dname is returned. - :returns: (ldns_rdf \*) clone of the dname with the labels reversed. + :return: (:class:`ldns_rdf`) Clone of the dname with the labels + reversed or ".". + + .. warning:: + + It is scheduled to be deprecated and removed. Convert + :class:`ldns_rdf` to :class:`ldns_dname`. """ + warnings.warn("The ldns_rdf.reverse() method is scheduled" + + " to be deprecated in future releases." + + " Convert the ldns_rdf to ldsn_dname and the use its" + + " methods.", PendingDeprecationWarning, stacklevel=2) return _ldns.ldns_dname_reverse(self) #parameters: const ldns_rdf *, #retvals: ldns_rdf * - #_LDNS_RDF_METHODS# - %} + # + # _LDNS_RDF_METHODS + # + %} } diff --git a/contrib/python/ldns_rr.i b/contrib/python/ldns_rr.i index 1a9f3f1c21bb..726c6cd902af 100644 --- a/contrib/python/ldns_rr.i +++ b/contrib/python/ldns_rr.i @@ -14,8 +14,8 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the organization nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -28,1153 +28,1849 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - ******************************************************************************/ + *****************************************************************************/ -%typemap(in,numinputs=0,noblock=1) (ldns_rr **) + +/* ========================================================================= */ +/* SWIG setting and definitions. */ +/* ========================================================================= */ + +/* Creates a temporary instance of (ldns_rr *). */ +%typemap(in, numinputs=0, noblock=1) (ldns_rr **) { - ldns_rr *$1_rr; - $1 = &$1_rr; + ldns_rr *$1_rr; + $1 = &$1_rr; } -/* result generation */ -%typemap(argout,noblock=1) (ldns_rr **) +/* Result generation, appends (ldns_rr *) after the result. */ +%typemap(argout, noblock=1) (ldns_rr **) { - $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 )); + $result = SWIG_Python_AppendOutput($result, + SWIG_NewPointerObj(SWIG_as_voidptr($1_rr), + SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 )); } -%nodefaultctor ldns_struct_rr; //no default constructor & destructor -%nodefaultdtor ldns_struct_rr; +%nodefaultctor ldns_struct_rr; /* No default constructor. */ +%nodefaultdtor ldns_struct_rr; /* No default destructor. */ %ignore ldns_struct_rr::_rdata_fields; %newobject ldns_rr_clone; %newobject ldns_rr_new; +%newobject ldns_rr_new_frm_type; %newobject ldns_rr_pop_rdf; %delobject ldns_rr_free; %rename(ldns_rr) ldns_struct_rr; -#ifdef LDNS_DEBUG -%rename(__ldns_rr_free) ldns_rr_free; -%inline %{ -void _ldns_rr_free (ldns_rr* r) { - printf("******** LDNS_RR free 0x%lX ************\n", (long unsigned int)r); - ldns_rr_free(r); -} -%} -#else -%rename(_ldns_rr_free) ldns_rr_free; -#endif - %newobject ldns_rr2str; %newobject ldns_rr_type2str; %newobject ldns_rr_class2str; %newobject ldns_read_anchor_file; -// clone rdf data on pull +/* Clone rdf data on pull. */ + +/* Clone will fail with NULL argument. */ %newobject _ldns_rr_rdf; %rename(__ldns_rr_rdf) ldns_rr_rdf; -%inline %{ -ldns_rdf* _ldns_rr_rdf(ldns_rr* rr, size_t i) { - return ldns_rdf_clone(ldns_rr_rdf(rr, i)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rdf(ldns_rr *rr, size_t i) + { + ldns_rdf *rdf; + rdf = ldns_rr_rdf(rr, i); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_algorithm; %rename(__ldns_rr_rrsig_algorithm) ldns_rr_rrsig_algorithm; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_algorithm(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_algorithm(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_algorithm(ldns_rr *rr) { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_algorithm(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_dnskey_algorithm; %rename(__ldns_rr_dnskey_algorithm) ldns_rr_dnskey_algorithm; -%inline %{ -ldns_rdf* _ldns_rr_dnskey_algorithm(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_dnskey_algorithm(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_dnskey_algorithm(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_dnskey_algorithm(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_dnskey_flags; %rename(__ldns_rr_dnskey_flags) ldns_rr_dnskey_flags; -%inline %{ -ldns_rdf* _ldns_rr_dnskey_flags(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_dnskey_flags(rr)); -} +%inline + %{ + ldns_rdf * _ldns_rr_dnskey_flags(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_dnskey_flags(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_dnskey_key; %rename(__ldns_rr_dnskey_key) ldns_rr_dnskey_key; -%inline %{ -ldns_rdf* _ldns_rr_dnskey_key(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_dnskey_key(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_dnskey_key(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_dnskey_key(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_dnskey_protocol; %rename(__ldns_rr_dnskey_protocol) ldns_rr_dnskey_protocol; -%inline %{ -ldns_rdf* _ldns_rr_dnskey_protocol(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_dnskey_protocol(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_dnskey_protocol(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_dnskey_protocol(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_owner; %rename(__ldns_rr_owner) ldns_rr_owner; -%inline %{ -ldns_rdf* _ldns_rr_owner(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_owner(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_owner(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_owner(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_a_address; %rename(__ldns_rr_a_address) ldns_rr_a_address; -%inline %{ -ldns_rdf* _ldns_rr_a_address(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_a_address(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_a_address(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_a_address(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_mx_exchange; %rename(__ldns_rr_mx_exchange) ldns_rr_mx_exchange; -%inline %{ -ldns_rdf* _ldns_rr_mx_exchange(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_mx_exchange(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_mx_exchange(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_mx_exchange(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_mx_preference; %rename(__ldns_rr_mx_preference) ldns_rr_mx_preference; -%inline %{ -ldns_rdf* _ldns_rr_mx_preference(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_mx_preference(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_mx_preference(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_mx_preference(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_ns_nsdname; %rename(__ldns_rr_ns_nsdname) ldns_rr_ns_nsdname; -%inline %{ -ldns_rdf* _ldns_rr_ns_nsdname(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_ns_nsdname(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_ns_nsdname(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_ns_nsdname(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_expiration; %rename(__ldns_rr_rrsig_expiration) ldns_rr_rrsig_expiration; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_expiration(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_expiration(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_expiration(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_expiration(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_inception; %rename(__ldns_rr_rrsig_inception) ldns_rr_rrsig_inception; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_inception(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_inception(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_inception(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_inception(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_keytag; %rename(__ldns_rr_rrsig_keytag) ldns_rr_rrsig_keytag; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_keytag(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_keytag(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_keytag(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_keytag(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_labels; %rename(__ldns_rr_rrsig_labels) ldns_rr_rrsig_labels; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_labels(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_labels(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_labels(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_labels(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_origttl; %rename(__ldns_rr_rrsig_origttl) ldns_rr_rrsig_origttl; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_origttl(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_origttl(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_origttl(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_origttl(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_sig; %rename(__ldns_rr_rrsig_sig) ldns_rr_rrsig_sig; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_sig(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_sig(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_sig(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_sig(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_signame; %rename(__ldns_rr_rrsig_signame) ldns_rr_rrsig_signame; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_signame(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_signame(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_signame(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_signame(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} %newobject _ldns_rr_rrsig_typecovered; %rename(__ldns_rr_rrsig_typecovered) ldns_rr_rrsig_typecovered; -%inline %{ -ldns_rdf* _ldns_rr_rrsig_typecovered(ldns_rr* rr) { - return ldns_rdf_clone(ldns_rr_rrsig_typecovered(rr)); -} +%inline +%{ + ldns_rdf * _ldns_rr_rrsig_typecovered(ldns_rr *rr) + { + ldns_rdf *rdf; + rdf = ldns_rr_rrsig_typecovered(rr); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} -// end of pull cloning +/* End of pull cloning. */ -// clone rdf data on push +/* Clone rdf data on push. */ %rename(__ldns_rr_a_set_address) ldns_rr_a_set_address; -%inline %{ -bool _ldns_rr_a_set_address(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_a_set_address(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_a_set_address(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_a_set_address(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_dnskey_set_algorithm) ldns_rr_dnskey_set_algorithm; -%inline %{ -bool _ldns_rr_dnskey_set_algorithm(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_dnskey_set_algorithm(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_dnskey_set_algorithm(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_dnskey_set_algorithm(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_dnskey_set_flags) ldns_rr_dnskey_set_flags; -%inline %{ -bool _ldns_rr_dnskey_set_flags(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_dnskey_set_flags(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_dnskey_set_flags(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_dnskey_set_flags(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_dnskey_set_key) ldns_rr_dnskey_set_key; -%inline %{ -bool _ldns_rr_dnskey_set_key(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_dnskey_set_key(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_dnskey_set_key(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_dnskey_set_key(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_dnskey_set_protocol) ldns_rr_dnskey_set_protocol; -%inline %{ -bool _ldns_rr_dnskey_set_protocol(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_dnskey_set_protocol(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_dnskey_set_protocol(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_dnskey_set_protocol(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_push_rdf) ldns_rr_push_rdf; -%inline %{ -bool _ldns_rr_push_rdf(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_push_rdf(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_push_rdf(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_push_rdf(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_algorithm) ldns_rr_rrsig_set_algorithm; -%inline %{ -bool _ldns_rr_rrsig_set_algorithm(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_algorithm(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_algorithm(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_algorithm(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_expiration) ldns_rr_rrsig_set_expiration; -%inline %{ -bool _ldns_rr_rrsig_set_expiration(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_expiration(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_expiration(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_expiration(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_inception) ldns_rr_rrsig_set_inception; -%inline %{ -bool _ldns_rr_rrsig_set_inception(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_inception(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_inception(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_inception(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_keytag) ldns_rr_rrsig_set_keytag; -%inline %{ -bool _ldns_rr_rrsig_set_keytag(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_keytag(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_keytag(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_keytag(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_labels) ldns_rr_rrsig_set_labels; -%inline %{ -bool _ldns_rr_rrsig_set_labels(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_labels(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_labels(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_labels(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_origttl) ldns_rr_rrsig_set_origttl; -%inline %{ -bool _ldns_rr_rrsig_set_origttl(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_origttl(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_origttl(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_origttl(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_sig) ldns_rr_rrsig_set_sig; -%inline %{ -bool _ldns_rr_rrsig_set_sig(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_sig(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_sig(ldns_rr *rr, ldns_rdf *rdf) { + return ldns_rr_rrsig_set_sig(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_signame) ldns_rr_rrsig_set_signame; -%inline %{ -bool _ldns_rr_rrsig_set_signame(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_signame(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_signame(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_signame(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_rrsig_set_typecovered) ldns_rr_rrsig_set_typecovered; -%inline %{ -bool _ldns_rr_rrsig_set_typecovered(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_rrsig_set_typecovered(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + bool _ldns_rr_rrsig_set_typecovered(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_rrsig_set_typecovered(rr, ldns_rdf_clone(rdf)); + } %} %rename(__ldns_rr_set_owner) ldns_rr_set_owner; -%inline %{ -void _ldns_rr_set_owner(ldns_rr* rr, ldns_rdf* rdf) { - return ldns_rr_set_owner(rr, ldns_rdf_clone(rdf)); -} +%inline +%{ + void _ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *rdf) + { + return ldns_rr_set_owner(rr, ldns_rdf_clone(rdf)); + } %} +%newobject _ldns_rr_set_rdf; %rename(__ldns_rr_set_rdf) ldns_rr_set_rdf; -%inline %{ - ldns_rdf* _ldns_rr_set_rdf(ldns_rr* rr, ldns_rdf* rdf, size_t pos) { - return ldns_rr_set_rdf(rr, ldns_rdf_clone(rdf), pos); -} +%inline +%{ + ldns_rdf * _ldns_rr_set_rdf(ldns_rr *rr, ldns_rdf *rdf, size_t pos) + { + /* May leak memory on unsuccessful calls. */ + ldns_rdf *new, *ret; + + new = ldns_rdf_clone(rdf); + + if ((ret = ldns_rr_set_rdf(rr, new, pos)) == NULL) { + ldns_rdf_deep_free(new); + } + + return ret; + } %} -// end of push cloning +/* End of push cloning. */ %rename(_ldns_rr_new_frm_str) ldns_rr_new_frm_str; %rename(_ldns_rr_new_frm_fp_l) ldns_rr_new_frm_fp_l; %rename(_ldns_rr_new_frm_fp) ldns_rr_new_frm_fp; -%feature("docstring") ldns_struct_rr "Resource Record (RR) -The RR is the basic DNS element that contains actual data. This class allows to create RR and manipulate with the content." +/* ========================================================================= */ +/* Debugging related code. */ +/* ========================================================================= */ + + +#ifdef LDNS_DEBUG +%rename(__ldns_rr_free) ldns_rr_free; +%inline %{ + void _ldns_rr_free (ldns_rr *r) + { + printf("******** LDNS_RR free 0x%lX ************\n", (long unsigned int)r); + ldns_rr_free(r); + } +%} +#else /* !LDNS_DEBUG */ +%rename(_ldns_rr_free) ldns_rr_free; +#endif /* LDNS_DEBUG */ + + +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ + +/* None. */ + + +/* ========================================================================= */ +/* Encapsulating Python code. */ +/* ========================================================================= */ + + +%feature("docstring") ldns_struct_rr "Resource Record (RR). + +The RR is the basic DNS element that contains actual data. This class allows +to create RR and manipulate with the content. + +Use :meth:`ldns_rr_new`, :meth:`ldns_rr_new_frm_type`, :meth:`new_frm_fp`, +:meth:`new_frm_fp_l`, :meth:`new_frm_str` or :meth:`new_question_frm_str` +to create :class:`ldns_rr` instances. +" %extend ldns_struct_rr { - %pythoncode %{ + %pythoncode + %{ def __init__(self): - raise Exception("This class can't be created directly. Please use: ldns_rr_new, ldns_rr_new_frm_type, new_frm_fp(), new_frm_fp_l(), new_frm_str() or new_question_frm_str") + raise Exception("This class can't be created directly. " + + "Please use: ldns_rr_new(), ldns_rr_new_frm_type(), " + + "new_frm_fp(), new_frm_fp_l(), new_frm_str() or " + + "new_question_frm_str()") __swig_destroy__ = _ldns._ldns_rr_free - #LDNS_RR_CONSTRUCTORS_# + # + # LDNS_RR_CONSTRUCTORS_ + # + @staticmethod - def new_frm_str(str, default_ttl=0, origin=None, prev=None, raiseException=True): - """Creates an rr object from a string. + def new_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True): + """ + Creates an rr object from a string. - The string should be a fully filled-in rr, like ownername [space] TTL [space] CLASS [space] TYPE [space] RDATA. + The string should be a fully filled-in rr, like "owner_name + [space] TTL [space] CLASS [space] TYPE [space] RDATA." - :param str: the string to convert - :param default_ttl: default ttl value for the rr. If 0 DEF_TTL will be used - :param origin: when the owner is relative add this - :param prev: the previous ownername - :param raiseException: if True, an exception occurs in case a rr instance can't be created - :returns: - * rr - (ldnsrr) RR instance or None. If the object can't be created and raiseException is True, an exception occurs. + :param string: The string to convert. + :type string: str + :param default_ttl: Default ttl value for the rr. + If 0 DEF_TTL will be used. + :type default_ttl: int + :param origin: When the owner is relative add this. + :type origin: :class:`ldns_dname` + :param prev: The previous owner name. + :type prev: :class:`ldns_rdf` + :param raiseException: If True, an exception occurs in case a rr + instance can't be created. + :throws Exception: If `raiseExceprion` is set and fails. + :throws TypeError: When parameters of incorrect types. + :return: (:class:`ldns_rr`) RR instance or None. + + .. note:: + The type checking of `origin` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. **Usage** >>> import ldns - >>> rr = ldns.ldns_rr.new_frm_str("www.nic.cz. IN A 192.168.1.1",300) + >>> rr = ldns.ldns_rr.new_frm_str("www.nic.cz. IN A 192.168.1.1", 300) >>> print rr www.nic.cz. 300 IN A 192.168.1.1 + >>> rr = ldns.ldns_rr.new_frm_str("test.nic.cz. 600 IN A 192.168.1.2") + >>> print rr + test.nic.cz. 600 IN A 192.168.1.2 + """ - status, rr, prev = _ldns.ldns_rr_new_frm_str_(str, default_ttl, origin, prev) + if (not isinstance(origin, ldns_dname)) and \ + isinstance(origin, ldns_rdf) and \ + origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_rr.new_frm_str() method will" + + " drop the possibility to accept ldns_rdf as origin." + + " Convert argument to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + status, rr, prev = _ldns.ldns_rr_new_frm_str_(string, default_ttl, + origin, prev) if status != LDNS_STATUS_OK: - if (raiseException): raise Exception("Can't create RR, error: %d" % status) + if (raiseException): + raise Exception("Can't create RR, error: %d" % status) return None return rr @staticmethod - def new_question_frm_str(str, default_ttl=0, origin=None, prev=None, raiseException=True): - """Creates an rr object from a string. + def new_question_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True): + """ + Creates an rr object from a string. - The string is like new_frm_str but without rdata. + The string is like :meth:`new_frm_str` but without rdata. - :param str: the string to convert - :param origin: when the owner is relative add this - :param prev: the previous ownername - :param raiseException: if True, an exception occurs in case a rr instance can't be created - :returns: - * rr - (ldnsrr) RR instance or None. If the object can't be created and raiseException is True, an exception occurs. + :param string: The string to convert. + :type string: str + :param origin: When the owner is relative add this. + :type origin: :class:`ldns_dname` + :param prev: The previous owner name. + :type prev: :class:`ldns_rdf` + :param raiseException: If True, an exception occurs in case + a rr instance can't be created. + :throws Exception: If `raiseExceprion` is set and fails. + :throws TypeError: When parameters of incorrect types. + :return: (:class:`ldns_rr`) RR instance or None. If the object + can't be created and `raiseException` is True, + an exception occurs. + + .. note:: + The type checking of `origin` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - status, rr, prev = _ldns.ldns_rr_new_question_frm_str_(str, origin, prev) + if (not isinstance(origin, ldns_dname)) and \ + isinstance(origin, ldns_rdf) and \ + origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_rr.new_question_frm_str() method will" + + " drop the possibility to accept ldns_rdf as origin." + + " Convert argument to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + status, rr, prev = _ldns.ldns_rr_new_question_frm_str_(string, + origin, prev) if status != LDNS_STATUS_OK: - if (raiseException): raise Exception("Can't create RR, error: %d" % status) + if (raiseException): + raise Exception("Can't create RR, error: %d" % status) return None return rr @staticmethod - def new_frm_str_prev(str, default_ttl=0, origin=None, prev=None, raiseException=True): - """Creates an rr object from a string. + def new_frm_str_prev(string, default_ttl=0, origin=None, prev=None, raiseException=True): + """ + Creates an rr object from a string. - The string should be a fully filled-in rr, like ownername [space] TTL [space] CLASS [space] TYPE [space] RDATA. + The string should be a fully filled-in rr, like "owner_name + [space] TTL [space] CLASS [space] TYPE [space] RDATA". - :param str: the string to convert - :param default_ttl: default ttl value for the rr. If 0 DEF_TTL will be used - :param origin: when the owner is relative add this - :param prev: the previous ownername - :param raiseException: if True, an exception occurs in case a rr instance can't be created - :returns: - * rr - (ldnsrr) RR instance or None. If the object can't be created and raiseException is True, an exception occurs. + :param string: The string to convert. + :type string: str + :param default_ttl: Default ttl value for the rr. + If 0 DEF_TTL will be used. + :type default_ttl: int + :param origin: When the owner is relative add this. + :type origin: :class:`ldns_dname` + :param prev: The previous owner name. + :type prev: :class:`ldns_rdf` + :param raiseException: If True, an exception occurs in case when + a rr instance can't be created. + :throws Exception: If `raiseExceprion` is set and fails. + :throws TypeError: When parameters of incorrect types. + :return: None when fails, otherwise a tuple containing: + + * rr - (:class:`ldns_rr`) RR instance or None. + If the object can't be created and `raiseException` + is True, an exception occurs. - * prev - (ldns_rdf) ownername found in this string or None + * prev - (:class:`ldns_rdf`) Owner name found in this string + or None. + + .. note:: + The type checking of `origin` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - status, rr, prev = _ldns.ldns_rr_new_frm_str_(str, default_ttl, origin, prev) + if (not isinstance(origin, ldns_dname)) and \ + isinstance(origin, ldns_rdf) and \ + origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_rr.new_frm_str_prev() method will" + + " drop the possibility to accept ldns_rdf as origin." + + " Convert argument to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + status, rr, prev = _ldns.ldns_rr_new_frm_str_(string, default_ttl, + origin, prev) if status != LDNS_STATUS_OK: - if (raiseException): raise Exception("Can't create RR, error: %d" % status) + if (raiseException): + raise Exception("Can't create RR, error: %d" % status) return None return rr, prev @staticmethod def new_frm_fp(file, default_ttl=0, origin=None, prev=None, raiseException=True): - """Creates a new rr from a file containing a string. + """ + Creates a new rr from a file containing a string. - :param file: file pointer - :param default_ttl: If 0 DEF_TTL will be used - :param origin: when the owner is relative add this. - :param prev: when the owner is whitespaces use this. - :param raiseException: if True, an exception occurs in case a resolver object can't be created - :returns: - * rr - (ldns_rr) RR object or None. If the object can't be created and raiseException is True, an exception occurs. + :param file: Opened file. + :param default_ttl: If 0 DEF_TTL will be used. + :type default_ttl: int + :param origin: When the owner is relative add this. + :type origin: :class:`ldns_dname` + :param prev: When the owner is white spaces use this. + :type prev: :class:`ldns_rdf` + :param raiseException: If True, an exception occurs in case + a resolver object can't be created. + :throws Exception: If `raiseException` is set and the input + cannot be read. + :throws TypeError: When parameters of incorrect types. + :return: None when fails, otherwise a tuple containing: - * ttl - (int) None or TTL if the file contains a $TTL directive + * rr - (:class:`ldns_rr`) RR object or None. If the object + can't be created and `raiseException` is True, + an exception occurs. - * origin - (ldns_rdf) None or dname if the file contains a $ORIGIN directive + * ttl - (int) None or TTL if the file contains a TTL + directive. - * prev - (ldns_rdf) None or updated value of prev parameter + * origin - (:class:`ldns_rdf`) None or dname rdf if the file + contains a ORIGIN directive. + + * prev - (:class:`ldns_rdf`) None or updated value + of prev parameter. + + .. note:: + The type checking of `origin` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - res = _ldns.ldns_rr_new_frm_fp_l_(file, default_ttl, origin, prev, 0) + if (not isinstance(origin, ldns_dname)) and \ + isinstance(origin, ldns_rdf) and \ + origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_rr.new_frm_fp() method will" + + " drop the possibility to accept ldns_rdf as origin." + + " Convert argument to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + res = _ldns.ldns_rr_new_frm_fp_(file, default_ttl, origin, prev) if res[0] != LDNS_STATUS_OK: - if (raiseException): raise Exception("Can't create RR, error: %d" % res[0]) + if (raiseException): + raise Exception("Can't create RR, error: %d" % res[0]) return None return res[1:] @staticmethod def new_frm_fp_l(file, default_ttl=0, origin=None, prev=None, raiseException=True): - """Creates a new rr from a file containing a string. + """ + Creates a new rr from a file containing a string. - :param file: file pointer - :param default_ttl: If 0 DEF_TTL will be used - :param origin: when the owner is relative add this. - :param prev: when the owner is whitespaces use this. - :param raiseException: if True, an exception occurs in case a resolver object can't be created - :returns: - * rr - (ldns_rr) RR object or None. If the object can't be created and raiseException is True, an exception occurs. + :param file: Opened file. + :param default_ttl: If 0 DEF_TTL will be used. + :type default_ttl: int + :param origin: When the owner is relative add this. + :type origin: :class:`ldns_dname` + :param prev: When the owner is white spaces use this. + :type prev: :class:`ldns_rdf` + :param raiseException: Iif True, an exception occurs in case + a resolver object can't be created. + :throws Exception: If `raiseException` is set and the input + cannot be read. + :throws TypeError: When parameters of incorrect types. + :return: None when fails, otherwise a tuple containing: + + * rr - (:class:`ldns_rr`) RR object or None. If the object + can't be created and `raiseException` is True, + an exception occurs. - * line - (int) line number (for debugging) + * line - (int) line number (for debugging). - * ttl - (int) None or TTL if the file contains a $TTL directive + * ttl - (int) None or TTL if the file contains a TTL + directive . - * origin - (ldns_rdf) None or dname if the file contains a $ORIGIN directive + * origin - (:class:`ldns_rdf`) None or dname rdf if the file + contains a ORIGIN directive. - * prev - (ldns_rdf) None or updated value of prev parameter + * prev - (:class:`ldns_rdf`) None or updated value of prev + parameter. + + .. note:: + The type checking of `origin` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - res = _ldns.ldns_rr_new_frm_fp_l_(file, default_ttl, origin, prev, 1) + if (not isinstance(origin, ldns_dname)) and \ + isinstance(origin, ldns_rdf) and \ + origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_rr.new_frm_fp_l() method will" + + " drop the possibility to accept ldns_rdf as origin." + + " Convert argument to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + res = _ldns.ldns_rr_new_frm_fp_l_(file, default_ttl, origin, prev) if res[0] != LDNS_STATUS_OK: - if (raiseException): raise Exception("Can't create RR, error: %d" % res[0]) + if (raiseException): + raise Exception("Can't create RR, error: %d" % res[0]) return None return res[1:] - #_LDNS_RR_CONSTRUCTORS# + # + # _LDNS_RR_CONSTRUCTORS + # def __str__(self): - """converts the data in the resource record to presentation format""" + """ + Converts the data in the resource record to presentation format. + + :return: (str) + """ return _ldns.ldns_rr2str(self) def __cmp__(self, other): - """compares two rrs. + """ + Compares two rrs. + + The TTL is not looked at. + + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (int) 0 if equal, -1 if `self` comes before `other`, + 1 if `other` RR comes before `self`. + """ + return _ldns.ldns_rr_compare(self, other) + + def __lt__(self, other): + """ + Compares two rrs. The TTL is not looked at. - :param other: - the second RR one - :returns: (int) 0 if equal -1 if self comes before other RR +1 if other RR comes before self + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (bool) True when `self` is less than 'other'. """ - return _ldns.ldns_rr_compare(self,other) + return _ldns.ldns_rr_compare(self, other) == -1 + + def __le__(self, other): + """ + Compares two rrs. + + The TTL is not looked at. + + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (bool) True when `self` is less than or equal to + 'other'. + """ + return _ldns.ldns_rr_compare(self, other) != 1 + + def __eq__(self, other): + """ + Compares two rrs. + + The TTL is not looked at. + + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (bool) True when `self` is equal to 'other'. + """ + return _ldns.ldns_rr_compare(self, other) == 0 + + def __ne__(self, other): + """ + Compares two rrs. + + The TTL is not looked at. + + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (bool) True when `self` is not equal to 'other'. + """ + return _ldns.ldns_rr_compare(self, other) != 0 + + def __gt__(self, other): + """ + Compares two rrs. + + The TTL is not looked at. + + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (bool) True when `self` is greater than 'other'. + """ + return _ldns.ldns_rr_compare(self, other) == 1 + + def __ge__(self, other): + """ + Compares two rrs. + + The TTL is not looked at. + + :param other: The second RR one. + :type other: :class:`ldns_rr` + :throws TypeError: When `other` of non-:class:`ldns_rr` type. + :return: (bool) True when `self` is greater than or equal to + 'other'. + """ + return _ldns.ldns_rr_compare(self, other) != -1 + + @staticmethod + def class_by_name(string): + """ + Retrieves a class identifier value by looking up its name. + + :param string: Class name. + :type string: str + :throws TypeError: when `string` of inappropriate type. + :return: (int) Class identifier value, or 0 if not valid + class name given. + """ + return _ldns.ldns_get_rr_class_by_name(string) def rdfs(self): - """returns the list of rdata records.""" - for i in range(0,self.rd_count()): + """ + Returns a generator object of rdata records. + + :return: Generator of :class:`ldns_rdf`. + """ + for i in range(0, self.rd_count()): yield self.rdf(i) - def print_to_file(self,output): - """Prints the data in the resource record to the given file stream (in presentation format).""" - _ldns.ldns_rr_print(output,self) - #parameters: FILE *,const ldns_rr *, + def print_to_file(self, output): + """ + Prints the data in the resource record to the given file stream + (in presentation format). + + :param output: Opened file stream. + :throws TypeError: When `output` not a file. + """ + _ldns.ldns_rr_print(output, self) + #parameters: FILE *, const ldns_rr *, def get_type_str(self): - """Converts an RR type value to its string representation, and returns that string.""" + """ + Converts an RR type value to its string representation, + and returns that string. + + :return: (str) containing type identification. + """ return _ldns.ldns_rr_type2str(self.get_type()) #parameters: const ldns_rr_type, def get_class_str(self): - """Converts an RR class value to its string representation, and returns that string.""" + """ + Converts an RR class value to its string representation, + and returns that string. + + :return: (str) containing class identification. + """ return _ldns.ldns_rr_class2str(self.get_class()) #parameters: const ldns_rr_class, @staticmethod - def dnskey_key_size_raw(keydata,len,alg): - """get the length of the keydata in bits""" - return _ldns.ldns_rr_dnskey_key_size_raw(keydata,len,alg) + def dnskey_key_size_raw(keydata, len, alg): + """ + Get the length of the keydata in bits. + + :param keydata: Key raw data. + :type keydata: unsigned char \* + :param len: Number of bytes of `keydata`. + :type len: size_t + :param alg: Algorithm identifier. + :type alg: ldns_algorithm + + :return: (size_t) The length of key data in bits. + """ + return _ldns.ldns_rr_dnskey_key_size_raw(keydata, len, alg) #parameters: const unsigned char *,const size_t,const ldns_algorithm, #retvals: size_t def write_to_buffer(self,buffer,section): - """Copies the rr data to the buffer in wire format. + """ + Copies the rr data to the buffer in wire format. - :param buffer: buffer to append the result to buffer - :param section: the section in the packet this rr is supposed to be in (to determine whether to add rdata or not) - :returns: (ldns_status) ldns_status + :param buffer: Buffer to append the result to. + :type buffer: :class:`ldns_buffer` + :param section: The section in the packet this rr is supposed + to be in (to determine whether to add rdata or not). + :type section: int + :throws TypeError: when arguments of mismatching types passed. + :return: (ldns_status) ldns_status """ - return _ldns.ldns_rr2buffer_wire(buffer,self,section) + return _ldns.ldns_rr2buffer_wire(buffer, self, section) #parameters: ldns_buffer *,const ldns_rr *,int, #retvals: ldns_status def write_to_buffer_canonical(self,buffer,section): - """Copies the rr data to the buffer in wire format, in canonical format according to RFC3597 (every dname in rdata fields of RR's mentioned in that RFC will be lowercased). + """ + Copies the rr data to the buffer in wire format, in canonical + format according to RFC3597 (every dname in rdata fields + of RR's mentioned in that RFC will be converted to lower-case). - :param buffer: buffer to append the result to buffer - :param section: the section in the packet this rr is supposed to be in (to determine whether to add rdata or not) - :returns: (ldns_status) ldns_status + :param buffer: Buffer to append the result to. + :type buffer: :class:`ldns_buffer` + :param section: The section in the packet this rr is supposed + to be in (to determine whether to add rdata or not). + :type section: int + :throws TypeError: when arguments of mismatching types passed. + :return: (ldns_status) ldns_status """ return _ldns.ldns_rr2buffer_wire_canonical(buffer,self,section) #parameters: ldns_buffer *,const ldns_rr *,int, #retvals: ldns_status - def write_data_to_buffer(self,buffer): - """Converts an rr's rdata to wireformat, while excluding the ownername and all the stuff before the rdata. + def write_data_to_buffer(self, buffer): + """ + Converts an rr's rdata to wire format, while excluding the + owner name and all the stuff before the rdata. - This is needed in DNSSEC keytag calculation, the ds calcalution from the key and maybe elsewhere. + This is needed in DNSSEC key-tag calculation, the ds + calculation from the key and maybe elsewhere. - :param buffer: buffer to append the result to - :returns: (ldns_status) ldns_status + :param buffer: Buffer to append the result to. + :type buffer: :class:`ldns_buffer` + :throws TypeError: when `buffer` of non-:class:`ldns_buffer` + type. + :return: (ldns_status) ldns_status """ return _ldns.ldns_rr_rdata2buffer_wire(buffer,self) - #parameters: ldns_buffer *,const ldns_rr *, + #parameters: ldns_buffer *, const ldns_rr *, #retvals: ldns_status - def write_rrsig_to_buffer(self,buffer): - """Converts a rrsig to wireformat BUT EXCLUDE the rrsig rdata + def write_rrsig_to_buffer(self, buffer): + """ + Converts a rrsig to wire format BUT EXCLUDE the rrsig rdata. This is needed in DNSSEC verification. - :param buffer: buffer to append the result to - :returns: (ldns_status) ldns_status + :param buffer: Buffer to append the result to. + :type buffer: :class:`ldns_buffer` + :throws TypeError: when `buffer` of non-:class:`ldns_buffer` + type. + :return: (ldns_status) ldns_status """ return _ldns.ldns_rrsig2buffer_wire(buffer,self) #parameters: ldns_buffer *,const ldns_rr *, #retvals: ldns_status - #LDNS_RR_METHODS_# + # + # LDNS_RR_METHODS_ + # + def a_address(self): - """returns the address of a LDNS_RR_TYPE_A rr + """ + Returns the address rdf of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA + rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the address or NULL on failure + :return: (:class:`ldns_rdf`) with the address or None on + failure. """ return _ldns._ldns_rr_a_address(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * - def a_set_address(self,f): - """sets the address of a LDNS_RR_TYPE_A rr + def a_set_address(self, f): + """ + Sets the address of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA rr. - :param f: - the address to set - :returns: (bool) true on success, false otherwise + :param f: The address to be set. + :type f: :class:`ldns_rdf` + :throws TypeError: When `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_a_set_address(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_a_set_address(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool def clone(self): - """clones a rr and all its data + """ + Clones a rr and all its data. - :returns: (ldns_rr \*) the new rr or NULL on failure + :return: (:class:`ldns_rr`) The new rr or None on failure. """ return _ldns.ldns_rr_clone(self) #parameters: const ldns_rr *, #retvals: ldns_rr * - - def compare_ds(self,rr2): - """returns true of the given rr's are equal. + + def compare_ds(self, rr2): + """ + Returns True if the given rr's are equal. - Also returns true if one record is a DS that represents the same DNSKEY record as the other record + Also returns True if one record is a DS that represents the + same DNSKEY record as the other record. - :param rr2: - the second rr - :returns: (bool) true if equal otherwise false + :param rr2: The second rr. + :type rr2: :class:`ldns_rr` + :throws TypeError: When `rr2` of non-:class:`ldns_rr` type. + :return: (bool) True if equal otherwise False. """ - return _ldns.ldns_rr_compare_ds(self,rr2) - #parameters: const ldns_rr *,const ldns_rr *, + return _ldns.ldns_rr_compare_ds(self, rr2) + #parameters: const ldns_rr *, const ldns_rr *, #retvals: bool - def compare_no_rdata(self,rr2): - """compares two rrs, up to the rdata. + def compare_no_rdata(self, rr2): + """ + Compares two rrs, up to the rdata. - :param rr2: - the second one - :returns: (int) 0 if equal -1 if rr1 comes before rr2 +1 if rr2 comes before rr1 + :param rr2: Rhe second rr. + :type rr2: :class:`ldns_rr` + :throws TypeError: When `rr2` of non-:class:`ldns_rr` type. + :return: (int) 0 if equal, negative integer if `self` comes + before `rr2`, positive integer if `rr2` comes before `self`. """ - return _ldns.ldns_rr_compare_no_rdata(self,rr2) - #parameters: const ldns_rr *,const ldns_rr *, + return _ldns.ldns_rr_compare_no_rdata(self, rr2) + #parameters: const ldns_rr *, const ldns_rr *, #retvals: int def dnskey_algorithm(self): - """returns the algorithm of a LDNS_RR_TYPE_DNSKEY rr + """ + Returns the algorithm of a LDNS_RR_TYPE_DNSKEY rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the algorithm or NULL on failure + :return: (:class:`ldns_rdf`) with the algorithm or None + on failure. """ return _ldns._ldns_rr_dnskey_algorithm(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def dnskey_flags(self): - """returns the flags of a LDNS_RR_TYPE_DNSKEY rr + """ + Returns the flags of a LDNS_RR_TYPE_DNSKEY rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the flags or NULL on failure + :return: (:class:`ldns_rdf`) with the flags or None on failure. """ return _ldns._ldns_rr_dnskey_flags(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def dnskey_key(self): - """returns the key data of a LDNS_RR_TYPE_DNSKEY rr + """ + Returns the key data of a LDNS_RR_TYPE_DNSKEY rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the key data or NULL on failure + :return: (:class:`ldns_rdf`) with the key data or None on + failure. """ return _ldns._ldns_rr_dnskey_key(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def dnskey_key_size(self): - """get the length of the keydata in bits + """ + Get the length of the keydata in bits. - :returns: (size_t) the keysize in bits + :return: (size_t) the keysize in bits. """ return _ldns.ldns_rr_dnskey_key_size(self) #parameters: const ldns_rr *, #retvals: size_t def dnskey_protocol(self): - """returns the protocol of a LDNS_RR_TYPE_DNSKEY rr + """ + Returns the protocol of a LDNS_RR_TYPE_DNSKEY rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the protocol or NULL on failure + :return: (:class:`ldns_rdf`) with the protocol or None on + failure. """ return _ldns._ldns_rr_dnskey_protocol(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * - def dnskey_set_algorithm(self,f): - """sets the algorithm of a LDNS_RR_TYPE_DNSKEY rr + def dnskey_set_algorithm(self, f): + """ + Sets the algorithm of a LDNS_RR_TYPE_DNSKEY rr - :param f: - the algorithm to set - :returns: (bool) true on success, false otherwise + :param f: The algorithm to set. + :type f: :class:`ldns_rdf` + :throws TypeError: When `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_dnskey_set_algorithm(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_dnskey_set_algorithm(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def dnskey_set_flags(self,f): - """sets the flags of a LDNS_RR_TYPE_DNSKEY rr + def dnskey_set_flags(self, f): + """ + Sets the flags of a LDNS_RR_TYPE_DNSKEY rr. - :param f: - the flags to set - :returns: (bool) true on success, false otherwise + :param f: The flags to be set. + :type f: :class:`ldns_rdf` + :throws TypeError: When `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_dnskey_set_flags(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_dnskey_set_flags(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def dnskey_set_key(self,f): - """sets the key data of a LDNS_RR_TYPE_DNSKEY rr + def dnskey_set_key(self, f): + """ + Sets the key data of a LDNS_RR_TYPE_DNSKEY rr. - :param f: - the key data to set - :returns: (bool) true on success, false otherwise + :param f: The key data to set. + :type f: :class:`ldns_rdf` + :throws TypeError: When `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_dnskey_set_key(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_dnskey_set_key(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool def dnskey_set_protocol(self,f): - """sets the protocol of a LDNS_RR_TYPE_DNSKEY rr + """ + Sets the protocol of a LDNS_RR_TYPE_DNSKEY rr. - :param f: - the protocol to set - :returns: (bool) true on success, false otherwise + :param f: The protocol to set. + :type f: :class:`ldns_rdf` + :throws TypeError: When `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ return _ldns._ldns_rr_dnskey_set_protocol(self,f) #parameters: ldns_rr *,ldns_rdf *, #retvals: bool def get_class(self): - """returns the class of the rr. + """ + Returns the class of the rr. - :returns: (ldns_rr_class) the class of the rr + :return: (int) The class identifier of the rr. """ return _ldns.ldns_rr_get_class(self) #parameters: const ldns_rr *, #retvals: ldns_rr_class def get_type(self): - """returns the type of the rr. + """ + Returns the type of the rr. - :returns: (ldns_rr_type) the type of the rr + :return: (int) The type identifier of the rr. """ return _ldns.ldns_rr_get_type(self) #parameters: const ldns_rr *, #retvals: ldns_rr_type + def is_question(self): + """ + Returns the question flag of a rr structure. + + :return: (bool) True if question flag is set. + """ + return _ldns.ldns_rr_is_question(self) + def label_count(self): - """counts the number of labels of the ownername. + """ + Counts the number of labels of the owner name. - :returns: (uint8_t) the number of labels + :return: (int) The number of labels. """ return _ldns.ldns_rr_label_count(self) #parameters: ldns_rr *, #retvals: uint8_t def mx_exchange(self): - """returns the mx host of a LDNS_RR_TYPE_MX rr + """ + Returns the mx host of a LDNS_RR_TYPE_MX rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the name of the MX host or NULL on failure + :return: (:class:`ldns_rdf`) with the name of the MX host + or None on failure. """ return _ldns._ldns_rr_mx_exchange(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def mx_preference(self): - """returns the mx pref. - - of a LDNS_RR_TYPE_MX rr + """ + Returns the mx preference of a LDNS_RR_TYPE_MX rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the preference or NULL on failure + :return: (:class:`ldns_rdf`) with the preference or None + on failure. """ return _ldns._ldns_rr_mx_preference(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def ns_nsdname(self): - """returns the name of a LDNS_RR_TYPE_NS rr + """ + Returns the name of a LDNS_RR_TYPE_NS rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the name or NULL on failure + :return: (:class:`ldns_rdf`) A dname rdf with the name or + None on failure. """ return _ldns._ldns_rr_ns_nsdname(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def owner(self): - """returns the owner name of an rr structure. + """ + Returns the owner name of an rr structure. - :returns: (ldns_rdf \*) ldns_rdf * + :return: (:class:`ldns_dname`) Owner name or None on failure. """ - return _ldns._ldns_rr_owner(self) + rdf = _ldns._ldns_rr_owner(self) + if rdf: + rdf = ldns_dname(rdf, clone=False) + return rdf #parameters: const ldns_rr *, #retvals: ldns_rdf * def pop_rdf(self): - """removes a rd_field member, it will be popped from the last position. + """ + Removes a rd_field member, it will be popped from the last + position. - :returns: (ldns_rdf \*) rdf which was popped (null if nothing) + :return: (:class:`ldns_rdf`) rdf which was popped, None if + nothing. """ return _ldns.ldns_rr_pop_rdf(self) #parameters: ldns_rr *, #retvals: ldns_rdf * def push_rdf(self,f): - """sets rd_field member, it will be placed in the next available spot. + """ + Sets rd_field member, it will be placed in the next available + spot. - :param f: - :returns: (bool) bool + :param f: The rdf to be appended. + :type f: :class:`ldns_rdf` + :throws TypeError: When `f` of non-:class:`ldns_rdf` type. + :return: (bool) Returns True if success, False otherwise. """ - return _ldns._ldns_rr_push_rdf(self,f) - #parameters: ldns_rr *,const ldns_rdf *, + return _ldns._ldns_rr_push_rdf(self, f) + #parameters: ldns_rr *, const ldns_rdf *, #retvals: bool def rd_count(self): - """returns the rd_count of an rr structure. + """ + Returns the rd_count of an rr structure. - :returns: (size_t) the rd count of the rr + :return: (size_t) the rd count of the rr. """ return _ldns.ldns_rr_rd_count(self) #parameters: const ldns_rr *, #retvals: size_t - def rdf(self,nr): - """returns the rdata field member counter. + def rdf(self, nr): + """ + Returns the rdata field with the given index. - :param nr: - the number of the rdf to return - :returns: (ldns_rdf \*) ldns_rdf * + :param nr: The index of the rdf to return. + :type nr: positive int + :throws TypeError: When `nr` not a positive integer. + :return: (:class:`ldns_rdf`) The given rdf or None if fails. """ - return _ldns._ldns_rr_rdf(self,nr) - #parameters: const ldns_rr *,size_t, + return _ldns._ldns_rr_rdf(self, nr) + #parameters: const ldns_rr *, size_t, #retvals: ldns_rdf * def rrsig_algorithm(self): - """returns the algorithm of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the algorithm identifier of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the algorithm or NULL on failure + :return: (:class:`ldns_rdf`) with the algorithm or None + on failure. """ return _ldns._ldns_rr_rrsig_algorithm(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_expiration(self): - """returns the expiration time of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the expiration time of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the expiration time or NULL on failure + :return: (:class:`ldns_rdf`) with the expiration time or None + on failure. """ return _ldns._ldns_rr_rrsig_expiration(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_inception(self): - """returns the inception time of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the inception time of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the inception time or NULL on failure + :return: (:class:`ldns_rdf`) with the inception time or None + on failure. """ return _ldns._ldns_rr_rrsig_inception(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_keytag(self): - """returns the keytag of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the keytag of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the keytag or NULL on failure + :return: (:class:`ldns_rdf`) with the keytag or None on failure. """ return _ldns._ldns_rr_rrsig_keytag(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_labels(self): - """returns the number of labels of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the number of labels of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the number of labels or NULL on failure + :return: (:class:`ldns_rdf`) with the number of labels or None + on failure. """ return _ldns._ldns_rr_rrsig_labels(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_origttl(self): - """returns the original TTL of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the original TTL of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the original TTL or NULL on failure + :return: (:class:`ldns_rdf`) with the original TTL or None + on failure. """ return _ldns._ldns_rr_rrsig_origttl(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * - def rrsig_set_algorithm(self,f): - """sets the algorithm of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_algorithm(self, f): + """ + Sets the algorithm of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the algorithm to set - :returns: (bool) true on success, false otherwise + :param f: The algorithm to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_algorithm(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_algorithm(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_expiration(self,f): - """sets the expireation date of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_expiration(self, f): + """ + Sets the expireation date of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the expireation date to set - :returns: (bool) true on success, false otherwise + :param f: The expireation date to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_expiration(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_expiration(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_inception(self,f): - """sets the inception date of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_inception(self, f): + """ + Sets the inception date of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the inception date to set - :returns: (bool) true on success, false otherwise + :param f: The inception date to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_inception(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_inception(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_keytag(self,f): - """sets the keytag of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_keytag(self, f): + """ + Sets the keytag of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the keytag to set - :returns: (bool) true on success, false otherwise + :param f: The keytag to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_keytag(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_keytag(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_labels(self,f): - """sets the number of labels of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_labels(self, f): + """ + Sets the number of labels of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the number of labels to set - :returns: (bool) true on success, false otherwise + :param f: The number of labels to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_labels(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_labels(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_origttl(self,f): - """sets the original TTL of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_origttl(self, f): + """ + Sets the original TTL of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the original TTL to set - :returns: (bool) true on success, false otherwise + :param f: The original TTL to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_origttl(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_origttl(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_sig(self,f): - """sets the signature data of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_sig(self, f): + """ + Sets the signature data of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the signature data to set - :returns: (bool) true on success, false otherwise + :param f: The signature data to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_sig(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_sig(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_signame(self,f): - """sets the signers name of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_signame(self, f): + """ + Sets the signers name of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the signers name to set - :returns: (bool) true on success, false otherwise + :param f: The signers name to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_signame(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_signame(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool - def rrsig_set_typecovered(self,f): - """sets the typecovered of a LDNS_RR_TYPE_RRSIG rr + def rrsig_set_typecovered(self, f): + """ + Sets the typecovered of a LDNS_RR_TYPE_RRSIG rr. - :param f: - the typecovered to set - :returns: (bool) true on success, false otherwise + :param f: The type covered to set. + :type f: :class:`ldns_rdf` + :throws TypeError: when `f` of non-:class:`ldns_rdf` type. + :return: (bool) True on success, False otherwise. """ - return _ldns._ldns_rr_rrsig_set_typecovered(self,f) - #parameters: ldns_rr *,ldns_rdf *, + return _ldns._ldns_rr_rrsig_set_typecovered(self, f) + #parameters: ldns_rr *, ldns_rdf *, #retvals: bool def rrsig_sig(self): - """returns the signature data of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the signature data of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the signature data or NULL on failure + :return: (:class:`ldns_rdf`) with the signature data or None + on failure. """ return _ldns._ldns_rr_rrsig_sig(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_signame(self): - """returns the signers name of a LDNS_RR_TYPE_RRSIG RR + """ + Returns the signers name of a LDNS_RR_TYPE_RRSIG RR. - :returns: (ldns_rdf \*) a ldns_rdf* with the signers name or NULL on failure + :return: (:class:`ldns_rdf`) with the signers name or None + on failure. """ return _ldns._ldns_rr_rrsig_signame(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * def rrsig_typecovered(self): - """returns the type covered of a LDNS_RR_TYPE_RRSIG rr + """ + Returns the type covered of a LDNS_RR_TYPE_RRSIG rr. - :returns: (ldns_rdf \*) a ldns_rdf* with the type covered or NULL on failure + :return: (:class:`ldns_rdf`) with the type covered or None + on failure. """ return _ldns._ldns_rr_rrsig_typecovered(self) #parameters: const ldns_rr *, #retvals: ldns_rdf * - def set_class(self,rr_class): - """sets the class in the rr. + def set_class(self, rr_class): + """ + Sets the class in the rr. - :param rr_class: - set to this class + :param rr_class: Set to this class. + :type rr_class: int + :throws TypeError: when `rr_class` of non-integer type. """ - _ldns.ldns_rr_set_class(self,rr_class) - #parameters: ldns_rr *,ldns_rr_class, + _ldns.ldns_rr_set_class(self, rr_class) + #parameters: ldns_rr *, ldns_rr_class, #retvals: - def set_owner(self,owner): - """sets the owner in the rr structure. + def set_owner(self, owner): + """ + Sets the owner in the rr structure. - :param owner: + :param owner: Owner name. + :type owner: :class:`ldns_dname` + :throws TypeError: when `owner` of non-:class:`ldns_dname` type. + + .. note:: + The type checking of `owner` is benevolent. + It allows also to pass a dname :class:`ldns_rdf` object. + This will probably change in future. """ - _ldns._ldns_rr_set_owner(self,owner) - #parameters: ldns_rr *,ldns_rdf *, - #retvals: + if (not isinstance(owner, ldns_dname)) and \ + isinstance(owner, ldns_rdf) and \ + owner.get_type() == _ldns.LDNS_RDF_TYPE_DNAME: + warnings.warn("The ldns_rr.new_frm_str() method will" + + " drop the possibility to accept ldns_rdf as owner." + + " Convert argument to ldns_dname.", + PendingDeprecationWarning, stacklevel=2) + _ldns._ldns_rr_set_owner(self, owner) + #parameters: ldns_rr *, ldns_rdf *, + #retvals: + + def set_question(self, question): + """ + Sets the question flag in the rr structure. + + :param question: Question flag. + :type question: bool + """ + _ldns.ldns_rr_set_question(self, question) + #parameters: ldns_rr *, bool, + #retvals: - def set_rd_count(self,count): - """sets the rd_count in the rr. + def set_rd_count(self, count): + """ + Sets the rd_count in the rr. - :param count: - set to this count + :param count: Set to this count. + :type count: positive int + :throws TypeError: when `count` of non-integer type. """ - _ldns.ldns_rr_set_rd_count(self,count) - #parameters: ldns_rr *,size_t, + _ldns.ldns_rr_set_rd_count(self, count) + #parameters: ldns_rr *, size_t, #retvals: - def set_rdf(self,f,position): - """sets a rdf member, it will be set on the position given. + def set_rdf(self, f, position): + """ + Sets a rdf member, it will be set on the position given. The old value is returned, like pop. - :param f: - :param position: - the position the set the rdf - :returns: (ldns_rdf \*) the old value in the rr, NULL on failyre + :param f: The rdf to be set. + :type f: :class:`ldns_rdf` + :param position: The position the set the rdf. + :type position: positive int + :throws TypeError: when mismatching types passed. + :return: (:class:`ldns_rdf`) the old value in the rr, None + on failure. """ - return _ldns._ldns_rr_set_rdf(self,f,position) - #parameters: ldns_rr *,const ldns_rdf *,size_t, + return _ldns._ldns_rr_set_rdf(self, f, position) + #parameters: ldns_rr *, const ldns_rdf *, size_t, #retvals: ldns_rdf * - def set_ttl(self,ttl): - """sets the ttl in the rr structure. + def set_ttl(self, ttl): + """ + Sets the ttl in the rr structure. - :param ttl: - set to this ttl + :param ttl: Set to this ttl. + :type ttl: positive int + :throws TypeError: when `ttl` of non-integer type. """ - _ldns.ldns_rr_set_ttl(self,ttl) - #parameters: ldns_rr *,uint32_t, + _ldns.ldns_rr_set_ttl(self, ttl) + #parameters: ldns_rr *, uint32_t, #retvals: - def set_type(self,rr_type): - """sets the type in the rr. + def set_type(self, rr_type): + """ + Sets the type in the rr. - :param rr_type: - set to this type + :param rr_type: Set to this type. + :type rr_type: ineteger + :throws TypeError: when `rr_type` of non-integer type. """ - _ldns.ldns_rr_set_type(self,rr_type) - #parameters: ldns_rr *,ldns_rr_type, - #retvals: + _ldns.ldns_rr_set_type(self, rr_type) + #parameters: ldns_rr *, ldns_rr_type, + #retvals: + + def to_canonical(self): + """ + Converts each dname in a rr to its canonical form. + """ + _ldns.ldns_rr2canonical(self) def ttl(self): - """returns the ttl of an rr structure. + """ + Returns the ttl of an rr structure. - :returns: (uint32_t) the ttl of the rr + :return: (int) the ttl of the rr. """ return _ldns.ldns_rr_ttl(self) #parameters: const ldns_rr *, #retvals: uint32_t + @staticmethod + def type_by_name(string): + """ + Retrieves a rr type identifier value by looking up its name. + + Returns 0 if invalid name passed. + + :param string: RR type name. + :type string: str + :throws TypeError: when `string` of inappropriate type. + :return: (int) RR type identifier, or 0 if no matching value + to identifier found. + """ + return _ldns.ldns_get_rr_type_by_name(string) + def uncompressed_size(self): - """calculates the uncompressed size of an RR. + """ + Calculates the uncompressed size of an RR. - :returns: (size_t) size of the rr + :return: (inetger) size of the rr. """ return _ldns.ldns_rr_uncompressed_size(self) #parameters: const ldns_rr *, #retvals: size_t - #_LDNS_RR_METHODS# - %} + # + # _LDNS_RR_METHODS + # + %} } -%nodefaultctor ldns_struct_rr_list; //no default constructor & destructor -%nodefaultdtor ldns_struct_rr_list; + +/* ========================================================================= */ +/* SWIG setting and definitions. */ +/* ========================================================================= */ + + +%nodefaultctor ldns_struct_rr_list; /* No default constructor. */ +%nodefaultdtor ldns_struct_rr_list; /* No default destructor. */ %ignore ldns_struct_rr_list::_rrs; +%newobject ldns_rr_list_cat_clone; %newobject ldns_rr_list_clone; %newobject ldns_rr_list_pop_rr; %newobject ldns_rr_list_pop_rr_list; %newobject ldns_rr_list_pop_rrset; %newobject ldns_rr_list_rr; %newobject ldns_rr_list_new; +%newobject ldns_get_rr_list_hosts_frm_file; +%newobject ldns_rr_list_subtype_by_rdf; +%newobject ldns_rr_list2str; %delobject ldns_rr_list_deep_free; %delobject ldns_rr_list_free; -%rename(ldns_rr_list) ldns_struct_rr_list; -#ifdef LDNS_DEBUG -%rename(__ldns_rr_list_deep_free) ldns_rr_list_deep_free; -%rename(__ldns_rr_list_free) ldns_rr_list_free; -%inline %{ -void _ldns_rr_list_free(ldns_rr_list* r) { - printf("******** LDNS_RR_LIST deep free 0x%lX ************\n", (long unsigned int)r); - ldns_rr_list_deep_free(r); -} -%} -#else -%rename(_ldns_rr_list_deep_free) ldns_rr_list_deep_free; -%rename(_ldns_rr_list_free) ldns_rr_list_free; -#endif - -/* clone data on push */ +/* Clone data on push. */ %rename(__ldns_rr_list_push_rr) ldns_rr_list_push_rr; -%inline %{ -void _ldns_rr_list_push_rr(ldns_rr_list* r, ldns_rr *rr) { - ldns_rr_list_push_rr(r, ldns_rr_clone(rr)); -} +%inline +%{ + bool _ldns_rr_list_push_rr(ldns_rr_list* r, ldns_rr *rr) + { + bool ret; + ldns_rr *new; + + new = ldns_rr_clone(rr); + if (!(ret = ldns_rr_list_push_rr(r, new))) { + ldns_rr_free(new); + } + return ret; + } %} %rename(__ldns_rr_list_push_rr_list) ldns_rr_list_push_rr_list; -%inline %{ -void _ldns_rr_list_push_rr_list(ldns_rr_list* r, ldns_rr_list *r2) { - ldns_rr_list_push_rr_list(r, ldns_rr_list_clone(r2)); -} +%inline +%{ + bool _ldns_rr_list_push_rr_list(ldns_rr_list* r, ldns_rr_list *r2) + { + bool ret; + ldns_rr_list *new; + + new = ldns_rr_list_clone(r2); + if (!(ret = ldns_rr_list_push_rr_list(r, new))) { + ldns_rr_list_deep_free(new); + } + return ret; + } %} + +%newobject _ldns_rr_list_set_rr; +%rename(__ldns_rr_list_set_rr) ldns_rr_list_set_rr; +%inline +%{ + ldns_rr * _ldns_rr_list_set_rr(ldns_rr_list * rrl, ldns_rr *rr, + size_t idx) + { + ldns_rr *ret; + ldns_rr *new; + + new = ldns_rr_clone(rr); + if ((ret = ldns_rr_list_set_rr(rrl, new, idx)) == NULL) { + ldns_rr_free(new); + } + return ret; + } +%} + + %rename(__ldns_rr_list_cat) ldns_rr_list_cat; -%inline %{ -void _ldns_rr_list_cat(ldns_rr_list* r, ldns_rr_list *r2) { - ldns_rr_list_cat(r, ldns_rr_list_clone(r2)); -} +%inline +%{ + bool _ldns_rr_list_cat(ldns_rr_list *r, ldns_rr_list *r2) + { + return ldns_rr_list_cat(r, ldns_rr_list_clone(r2)); + } %} -/* clone data on pull */ +/* End clone data on push. */ -%newobject _ldns_rr_list_rr; +/* Clone data on pull. */ + +%newobject _ldns_rr_list_rr; %rename(__ldns_rr_list_rr) ldns_rr_list_rr; -%inline %{ -ldns_rr* _ldns_rr_list_rr(ldns_rr_list* r, int i) { - return ldns_rr_clone(ldns_rr_list_rr(r, i)); -} +%inline +%{ + ldns_rr * _ldns_rr_list_rr(ldns_rr_list *r, int i) + { + ldns_rr *rr; + rr = ldns_rr_list_rr(r, i); + return (rr != NULL) ? ldns_rr_clone(rr) : NULL; + } %} -%newobject ldns_rr_list2str; - +%newobject _ldns_rr_list_owner; %rename(__ldns_rr_list_owner) ldns_rr_list_owner; -%inline %{ -ldns_rdf* _ldns_rr_list_owner(ldns_rr_list* r) { - return ldns_rdf_clone(ldns_rr_list_owner(r)); -} +%inline +%{ + ldns_rdf * _ldns_rr_list_owner(ldns_rr_list *r) + { + ldns_rdf *rdf; + rdf = ldns_rr_list_owner(r); + return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL; + } %} +/* End clone data on pull. */ + + +/* ========================================================================= */ +/* Debugging related code. */ +/* ========================================================================= */ + + +%rename(ldns_rr_list) ldns_struct_rr_list; +#ifdef LDNS_DEBUG +%rename(__ldns_rr_list_deep_free) ldns_rr_list_deep_free; +%rename(__ldns_rr_list_free) ldns_rr_list_free; +%inline +%{ + void _ldns_rr_list_deep_free(ldns_rr_list *r) + { + printf("******** LDNS_RR_LIST deep free 0x%lX ************\n", + (long unsigned int) r); + ldns_rr_list_deep_free(r); + } + + void _ldns_rr_list_free(ldns_rr_list *r) + { + printf("******** LDNS_RR_LIST deep free 0x%lX ************\n", + (long unsigned int) r); + ldns_rr_list_free(r); + } +%} +#else +%rename(_ldns_rr_list_deep_free) ldns_rr_list_deep_free; +%rename(_ldns_rr_list_free) ldns_rr_list_free; +#endif + + +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ + + +/* None. */ + + +/* ========================================================================= */ +/* Encapsulating Python code. */ +/* ========================================================================= */ + %feature("docstring") ldns_struct_rr_list "List of Resource Records. @@ -1183,7 +1879,8 @@ This class contains a list of RR's (see :class:`ldns.ldns_rr`). %extend ldns_struct_rr_list { - %pythoncode %{ + %pythoncode + %{ def __init__(self): self.this = _ldns.ldns_rr_list_new() if not self.this: @@ -1191,394 +1888,694 @@ This class contains a list of RR's (see :class:`ldns.ldns_rr`). __swig_destroy__ = _ldns._ldns_rr_list_deep_free - #LDNS_RR_LIST_CONSTRUCTORS_# + # + # LDNS_RR_LIST_CONSTRUCTORS_ + # + + @staticmethod + def new(raiseException=True): + """ + Creates an empty RR List object. + + :param raiseException: Set to True if an exception should + signal an error. + :type raiseException: bool + :throws Exception: when `raiseException` is True and error + occurs. + :return: :class:`ldns_rr_list` Empty RR list. + """ + rrl = _ldns.ldns_rr_list_new() + if (not rrl) and raiseException: + raise Exception("Can't create RR List.") + return rrl + @staticmethod def new_frm_file(filename="/etc/hosts", raiseException=True): - """Creates an RR List object from a file content + """ + Creates an RR List object from file content. - Goes through a file and returns a rr_list containing all the defined hosts in there. + Goes through a file and returns a rr list containing + all the defined hosts in there. - :param filename: the filename to use - :returns: RR List object or None. If the object can't be created and raiseException is True, an exception occurs. + :param filename: The filename to use. + :type filename: str + :param raiseException: Set to True if an exception should + signal an error. + :type raiseException: bool + :throws TypeError: when `filename` of inappropriate type. + :throws Exception: when `raiseException` is True and error + occurs. + :return: RR List object or None. If the object can't be + created and `raiseException` is True, an exception occurs. **Usage** - >>> alist = ldns.ldns_rr_list.new_frm_file() - >>> print alist - localhost. 3600 IN A 127.0.0.1 - ... + + >>> alist = ldns.ldns_rr_list.new_frm_file() + >>> print alist + localhost. 3600 IN A 127.0.0.1 + ... """ rr = _ldns.ldns_get_rr_list_hosts_frm_file(filename) - if (not rr) and (raiseException): raise Exception("Can't create RR List, error: %d" % status) + if (not rr) and (raiseException): + raise Exception("Can't create RR List.") return rr - #_LDNS_RR_LIST_CONSTRUCTORS# + + # + # _LDNS_RR_LIST_CONSTRUCTORS + # def __str__(self): - """converts a list of resource records to presentation format""" + """ + Converts a list of resource records to presentation format. + + :return: (str) Presentation format. + """ return _ldns.ldns_rr_list2str(self) - def print_to_file(self,output): - """print a rr_list to output param[in] output the fd to print to param[in] list the rr_list to print""" - _ldns.ldns_rr_list_print(output,self) + def print_to_file(self, output): + """ + Print a rr_list to output. + + :param output: Opened file to print to. + :throws TypeError: when `output` of inappropriate type. + """ + _ldns.ldns_rr_list_print(output, self) def to_canonical(self): - """converts each dname in each rr in a rr_list to its canonical form.""" + """ + Converts each dname in each rr in a rr_list to its canonical + form. + """ _ldns.ldns_rr_list2canonical(self) #parameters: ldns_rr_list *, #retvals: def rrs(self): - """returns the list of rr records.""" - for i in range(0,self.rr_count()): + """ + Returns a generator object of a list of rr records. + + :return: (generator) generator object. + """ + for i in range(0, self.rr_count()): yield self.rr(i) def is_rrset(self): - """checks if an rr_list is a rrset.""" + """ + Checks if the rr list is a rr set. + + :return: (bool) True if rr list is a rr set. + """ return _ldns.ldns_is_rrset(self) - def __cmp__(self,rrl2): - """compares two rr listss. + def __cmp__(self, rrl2): + """ + Compares two rr lists. - :param rrl2: - the second one - :returns: (int) 0 if equal -1 if this list comes before rrl2 +1 if rrl2 comes before this list + :param rrl2: The second one. + :type rrl2: :class:`ldns_rr_list` + :throws TypeError: when `rrl2` of non-:class:`ldns_rr_list` + type. + :return: (int) 0 if equal, -1 if this list comes before + `rrl2`, 1 if `rrl2` comes before this list. """ - return _ldns.ldns_rr_list_compare(self,rrl2) + return _ldns.ldns_rr_list_compare(self, rrl2) + + def __lt__(self, other): + """ + Compares two rr lists. + + :param other: The second one. + :type other: :class:`ldns_rr_list` + :throws TypeError: when `other` of non-:class:`ldns_rr_list` + type. + :return: (bool) True when `self` is less than 'other'. + """ + return _ldns.ldns_rr_list_compare(self, other) == -1 + + def __le__(self, other): + """ + Compares two rr lists. + + :param other: The second one. + :type other: :class:`ldns_rr_list` + :throws TypeError: when `other` of non-:class:`ldns_rr_list` + type. + :return: (bool) True when `self` is less than or equal to + 'other'. + """ + return _ldns.ldns_rr_list_compare(self, other) != 1 + + def __eq__(self, other): + """ + Compares two rr lists. + + :param other: The second one. + :type other: :class:`ldns_rr_list` + :throws TypeError: when `other` of non-:class:`ldns_rr_list` + type. + :return: (bool) True when `self` is equal to 'other'. + """ + return _ldns.ldns_rr_list_compare(self, other) == 0 + + def __ne__(self, other): + """ + Compares two rr lists. + + :param other: The second one. + :type other: :class:`ldns_rr_list` + :throws TypeError: when `other` of non-:class:`ldns_rr_list` + type. + :return: (bool) True when `self` is not equal to 'other'. + """ + return _ldns.ldns_rr_list_compare(self, other) != 0 + + def __gt__(self, other): + """ + Compares two rr lists. + + :param other: The second one. + :type other: :class:`ldns_rr_list` + :throws TypeError: when `other` of non-:class:`ldns_rr_list` + type. + :return: (bool) True when `self` is greater than 'other'. + """ + return _ldns.ldns_rr_list_compare(self, other) == 1 + + def __ge__(self, other): + """ + Compares two rr lists. + + :param other: The second one. + :type other: :class:`ldns_rr_list` + :throws TypeError: when `other` of non-:class:`ldns_rr_list` + type. + :return: (bool) True when `self` is greater than or equal to + 'other'. + """ + return _ldns.ldns_rr_list_compare(self, other) != -1 def write_to_buffer(self, buffer): - """Copies the rr_list data to the buffer in wire format. + """ + Copies the rr_list data to the buffer in wire format. - :param buffer: output buffer to append the result to - :returns: (ldns_status) ldns_status + :param buffer: Output buffer to append the result to. + :type buffer: :class:`ldns_buffer` + :throws TypeError: when `buffer` of non-:class:`ldns_buffer` + type. + :return: (ldns_status) ldns_status """ - return _ldns.ldns_rr_list2buffer_wire(buffer,self) + return _ldns.ldns_rr_list2buffer_wire(buffer, self) + + # + # LDNS_RR_LIST_METHODS_ + # - #LDNS_RR_LIST_METHODS_# - def cat(self,right): - """concatenates two ldns_rr_lists together. + def cat(self, right): + """ + Concatenates two ldns_rr_lists together. - This modifies rr list (to extend it and add the pointers from right). + This modifies rr list (to extend it and adds RRs from right). - :param right: - the rightside - :returns: (bool) a left with right concatenated to it + :param right: The right-hand side. + :type right: :class:`ldns_rr_list` + :throws TypeError: when `right` of non-:class:`ldns_rr_list` + type. + :return: (bool) True if success. """ - return _ldns._ldns_rr_list_cat(self,right) - #parameters: ldns_rr_list *,ldns_rr_list *, + return _ldns._ldns_rr_list_cat(self, right) + #parameters: ldns_rr_list *, ldns_rr_list *, #retvals: bool - def cat_clone(self,right): - """concatenates two ldns_rr_lists together, but makes clones of the rr's (instead of pointer copying). + def cat_clone(self, right): + """ + Concatenates two ldns_rr_lists together, creates a new list + of the rr's (instead of appending the content to an existing + list). - :param right: - the rightside - :returns: (ldns_rr_list \*) a new rr_list with leftside/rightside concatenated + :param right: The right-hand side. + :type right: :class:`ldns_rr_list` + :throws TypeError: when `right` of non-:class:`ldns_rr_list` + type. + :return: (:class:`ldns_rr_list`) rr list with left-hand side + + right-hand side concatenated, on None on error. """ - return _ldns.ldns_rr_list_cat_clone(self,right) - #parameters: ldns_rr_list *,ldns_rr_list *, + return _ldns.ldns_rr_list_cat_clone(self, right) + #parameters: ldns_rr_list *, ldns_rr_list *, #retvals: ldns_rr_list * def clone(self): - """clones an rrlist. + """ + Clones an rrlist. - :returns: (ldns_rr_list \*) the cloned rr list + :return: (:class:`ldns_rr_list`) the cloned rr list, + or None on error. """ return _ldns.ldns_rr_list_clone(self) #parameters: const ldns_rr_list *, #retvals: ldns_rr_list * - def contains_rr(self,rr): - """returns true if the given rr is one of the rrs in the list, or if it is equal to one + def contains_rr(self, rr): + """ + Returns True if the given rr is one of the rrs in the list, + or if it is equal to one. - :param rr: - the rr to check - :returns: (bool) true if rr_list contains rr, false otherwise + :param rr: The rr to check. + :type rr: :class:`ldns_rr` + :throws TypeError: when `rr` of non-:class:`ldns_rr` type. + :return: (bool) True if rr_list contains `rr`, False otherwise. """ - return _ldns.ldns_rr_list_contains_rr(self,rr) - #parameters: const ldns_rr_list *,ldns_rr *, + return _ldns.ldns_rr_list_contains_rr(self, rr) + #parameters: const ldns_rr_list *, ldns_rr *, #retvals: bool def owner(self): - """Returns the owner domain name rdf of the first element of the RR If there are no elements present, NULL is returned. + """ + Returns the owner domain name rdf of the first element of + the RR. If there are no elements present, None is returned. - :returns: (ldns_rdf \*) dname of the first element, or NULL if the list is empty + :return: (:class:`ldns_dname`) dname of the first element, + or None if the list is empty. """ - return _ldns._ldns_rr_list_owner(self) + rdf = _ldns._ldns_rr_list_owner(self) + if rdf: + rdf = ldns_dname(rdf, clone=False) + return rdf #parameters: const ldns_rr_list *, #retvals: ldns_rdf * def pop_rr(self): - """pops the last rr from an rrlist. + """ + Pops the last rr from an rrlist. - :returns: (ldns_rr \*) NULL if nothing to pop. Otherwise the popped RR + :return: (:class:`ldns_rr`) None if nothing to pop. + Otherwise the popped RR. """ rr = _ldns.ldns_rr_list_pop_rr(self) - #if hasattr(self, "_python_rr_refs") and rr in self._python_rr_refs: - # self._python_rr_refs.remove(rr) return rr #parameters: ldns_rr_list *, #retvals: ldns_rr * - def pop_rr_list(self,size): - """pops an rr_list of size s from an rrlist. + def pop_rr_list(self, size): + """ + Pops an rr_list of size s from an rrlist. - :param size: - the number of rr's to pop - :returns: (ldns_rr_list \*) NULL if nothing to pop. Otherwise the popped rr_list + :param size: The number of rr's to pop. + :type size: positive int + :throws TypeError: when `size` of inappropriate type. + :return: (:class:`ldns_rr_list`) None if nothing to pop. + Otherwise the popped rr list. """ - return _ldns.ldns_rr_list_pop_rr_list(self,size) - #parameters: ldns_rr_list *,size_t, + return _ldns.ldns_rr_list_pop_rr_list(self, size) + #parameters: ldns_rr_list *, size_t, #retvals: ldns_rr_list * def pop_rrset(self): - """pops the first rrset from the list, the list must be sorted, so that all rr's from each rrset are next to each other + """ + Pops the first rrset from the list, the list must be sorted, + so that all rr's from each rrset are next to each other. - :returns: (ldns_rr_list \*) + :return: (:class:`ldns_rr_list`) the first rrset, or None when + empty. """ return _ldns.ldns_rr_list_pop_rrset(self) #parameters: ldns_rr_list *, #retvals: ldns_rr_list * - def push_rr(self,rr): - """pushes an rr to an rrlist. + def push_rr(self, rr): + """ + Pushes an rr to an rrlist. - :param rr: - the rr to push - :returns: (bool) false on error, otherwise true + :param rr: The rr to push. + :type rr: :class:`ldns_rr` + :throws TypeError: when `rr` of non-:class:`ldns_rr` type. + :return: (bool) False on error, otherwise True. """ - #if hasattr(self, "_python_rr_refs"): - # self._python_rr_refs.add(rr) - #else: - # self._python_rr_refs = set([rr]) - return _ldns._ldns_rr_list_push_rr(self,rr) - #parameters: ldns_rr_list *,const ldns_rr *, + return _ldns._ldns_rr_list_push_rr(self, rr) + #parameters: ldns_rr_list *, const ldns_rr *, #retvals: bool - def push_rr_list(self,push_list): - """pushes an rr_list to an rrlist. + def push_rr_list(self, push_list): + """ + Pushes an rr list to an rr list. - :param push_list: - the rr_list to push - :returns: (bool) false on error, otherwise true + :param push_list: The rr_list to push. + :type push_list: :class:`ldns_rr_list` + :throws TypeError: when `push_list` of non-:class:`ldns_rr_list` + type. + :returns: (bool) False on error, otherwise True. """ - return _ldns._ldns_rr_list_push_rr_list(self,push_list) - #parameters: ldns_rr_list *,const ldns_rr_list *, + return _ldns._ldns_rr_list_push_rr_list(self, push_list) + #parameters: ldns_rr_list *, const ldns_rr_list *, #retvals: bool - def rr(self,nr): - """returns a specific rr of an rrlist. + def rr(self, nr): + """ + Returns a specific rr of an rrlist. - :param nr: - return this rr - :returns: (ldns_rr \*) the rr at position nr + :param nr: Index of the desired rr. + :type nr: positive int + :throws TypeError: when `nr` of inappropriate type. + :return: (:class:`ldns_rr`) The rr at position `nr`, or None + if failed. """ - return _ldns._ldns_rr_list_rr(self,nr) - #parameters: const ldns_rr_list *,size_t, + return _ldns._ldns_rr_list_rr(self, nr) + #parameters: const ldns_rr_list *, size_t, #retvals: ldns_rr * def rr_count(self): - """returns the number of rr's in an rr_list. + """ + Returns the number of rr's in an rr_list. - :returns: (size_t) the number of rr's + :return: (int) The number of rr's. """ return _ldns.ldns_rr_list_rr_count(self) #parameters: const ldns_rr_list *, #retvals: size_t - def set_rr(self,r,count): - """set a rr on a specific index in a ldns_rr_list + def set_rr(self, r, idx): + """ + Set a rr on a specific index in a ldns_rr_list. - :param r: - the rr to set - :param count: - index into the rr_list - :returns: (ldns_rr \*) the old rr which was stored in the rr_list, or NULL is the index was too large set a specific rr + :param r: The rr to set. + :type r: :class:`ldns_rr` + :param idx: Index into the rr_list. + :type idx: positive int + :throws TypeError: when parameters of inappropriate types. + :return: (:class:`ldns_rr`) the old rr which was stored in + the rr_list, or None if the index was too large + to set a specific rr. """ - return _ldns.ldns_rr_list_set_rr(self,r,count) - #parameters: ldns_rr_list *,const ldns_rr *,size_t, + return _ldns._ldns_rr_list_set_rr(self, r, idx) + #parameters: ldns_rr_list *, const ldns_rr *, size_t, #retvals: ldns_rr * - def set_rr_count(self,count): - """sets the number of rr's in an rr_list. + def set_rr_count(self, count): + """ + Sets the number of rr's in an rr_list. - :param count: - the number of rr in this list + :param count: The number of rr in this list. + :type count: positive int + :throws TypeError: when `count` of non-integer type. + :throws Exception: when `count` out of acceptable range. + + .. warning:: + Don't use this method unless you really know what you + are doing. """ - _ldns.ldns_rr_list_set_rr_count(self,count) - #parameters: ldns_rr_list *,size_t, + # The function C has a tendency to generate an assertion fail when + # the count exceeds the list's capacity -- therefore the checking + # code. + if isinstance(count, int) and \ + ((count < 0) or (count > self._rr_capacity)): + raise Exception("Given count %d is out of range " % (count) + + "of the rr list's capacity %d." % (self._rr_capacity)) + _ldns.ldns_rr_list_set_rr_count(self, count) + #parameters: ldns_rr_list *, size_t, #retvals: def sort(self): - """sorts an rr_list (canonical wire format). - - the sorting is done inband. + """ + Sorts an rr_list (canonical wire format). """ _ldns.ldns_rr_list_sort(self) #parameters: ldns_rr_list *, #retvals: - def subtype_by_rdf(self,r,pos): - """Return the rr_list which matches the rdf at position field. + def subtype_by_rdf(self, r, pos): + """ + Return the rr_list which matches the rdf at position field. - Think type-covered stuff for RRSIG + Think type-covered stuff for RRSIG. - :param r: - the rdf to use for the comparison - :param pos: - at which position can we find the rdf - :returns: (ldns_rr_list \*) a new rr list with only the RRs that match + :param r: The rdf to use for the comparison. + :type r: :class:`ldns_rdf` + :param pos: At which position we can find the rdf. + :type pos: positive int + :throws TypeError: when parameters of inappropriate types. + :return: (:class:`ldns_rr_list`) a new rr list with only + the RRs that match, or None when nothing matches. """ - return _ldns.ldns_rr_list_subtype_by_rdf(self,r,pos) - #parameters: ldns_rr_list *,ldns_rdf *,size_t, + return _ldns.ldns_rr_list_subtype_by_rdf(self, r, pos) + #parameters: ldns_rr_list *, ldns_rdf *, size_t, #retvals: ldns_rr_list * def type(self): - """Returns the type of the first element of the RR If there are no elements present, 0 is returned (LDNS_RR_TYPE_A). + """ + Returns the type of the first element of the RR. + + If there are no elements present, 0 is returned. - :returns: (ldns_rr_type) rr_type of the first element, or 0 if the list is empty + :return: (int) rr_type of the first element, + or 0 if the list is empty. """ return _ldns.ldns_rr_list_type(self) #parameters: const ldns_rr_list *, #retvals: ldns_rr_type - #_LDNS_RR_LIST_METHODS# - %} + + # + # _LDNS_RR_LIST_METHODS + # + %} } + +/* ========================================================================= */ +/* SWIG setting and definitions. */ +/* ========================================================================= */ + + %newobject ldns_rr_descript; -%nodefaultctor ldns_struct_rr_descriptor; //no default constructor & destructor -%nodefaultdtor ldns_struct_rr_descriptor; +%nodefaultctor ldns_struct_rr_descriptor; /* No default constructor. */ +%nodefaultdtor ldns_struct_rr_descriptor; /* No default destructor.*/ %rename(ldns_rr_descriptor) ldns_struct_rr_descriptor; +/* ========================================================================= */ +/* Debugging related code. */ +/* ========================================================================= */ + +/* None. */ + + +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ + + +%inline +%{ + /* + * Does nothing, but keeps the SWIG wrapper quiet about absent destructor. + */ + void ldns_rr_descriptor_dummy_free(const ldns_rr_descriptor *rd) + { + (void) rd; + } +%} + +/* ========================================================================= */ +/* Encapsulating Python code. */ +/* ========================================================================= */ -%feature("docstring") ldns_struct_rr_descriptor "Resource Record descriptor -This structure contains, for all rr types, the rdata fields that are defined." + +%feature("docstring") ldns_struct_rr_descriptor "Resource Record descriptor. + +This structure contains, for all rr types, the rdata fields that are defined. + +In order to create a class instance use :meth:`ldns_rr_descriptor`. +" %extend ldns_struct_rr_descriptor { - %pythoncode %{ - def __init__(self): - raise Exception("This class can't be created directly. Please use: ldns_rr_descript") - #LDNS_RR_DESCRIPTOR_METHODS_# - def field_type(self,field): - """returns the rdf type for the given rdata field number of the rr type for the given descriptor. + %pythoncode + %{ + def __init__(self, rr_type): + """ + Returns the resource record descriptor for the given type. + + :param rr_type: RR type. + :type rr_type: int + :throws TypeError: when `rr_type` of inappropriate type. + :return: (:class:`ldns_rr_descriptor`) RR descriptor class. + """ + self.this = self.ldns_rr_descriptor(rr_type) + + def __str__(self): + raise Exception("The content of this class cannot be printed.") + + __swig_destroy__ = _ldns.ldns_rr_descriptor_dummy_free + + # + # LDNS_RR_DESCRIPTOR_CONSTRUCTORS_ + # + + @staticmethod + def ldns_rr_descriptor(rr_type): + """ + Returns the resource record descriptor for the given type. + + :param rr_type: RR type. + :type rr_type: int + :throws TypeError: when `rr_type` of inappropriate type. + :return: (:class:`ldns_rr_descriptor`) RR descriptor class. + """ + return _ldns.ldns_rr_descript(rr_type) + #parameters: uint16_t + #retvals: const ldns_rr_descriptor * + + # + # _LDNS_RR_DESCRIPTOR_CONSTRUCTORS + # + + # + # LDNS_RR_DESCRIPTOR_METHODS_ + # + + def field_type(self, field): + """ + Returns the rdf type for the given rdata field number of the + rr type for the given descriptor. - :param field: - the field number - :returns: (ldns_rdf_type) the rdf type for the field + :param field: The field number. + :type field: positive int + :throws TypeError: when `field` of non-inetger type. + :return: (int) the rdf type for the field. """ - return _ldns.ldns_rr_descriptor_field_type(self,field) - #parameters: const ldns_rr_descriptor *,size_t, + return _ldns.ldns_rr_descriptor_field_type(self, field) + #parameters: const ldns_rr_descriptor *, size_t, #retvals: ldns_rdf_type def maximum(self): - """returns the maximum number of rdata fields of the rr type this descriptor describes. + """ + Returns the maximum number of rdata fields of the rr type this + descriptor describes. - :returns: (size_t) the maximum number of rdata fields + :return: (int) the maximum number of rdata fields. """ return _ldns.ldns_rr_descriptor_maximum(self) #parameters: const ldns_rr_descriptor *, #retvals: size_t def minimum(self): - """returns the minimum number of rdata fields of the rr type this descriptor describes. + """ + Returns the minimum number of rdata fields of the rr type this + descriptor describes. - :returns: (size_t) the minimum number of rdata fields + :return: (int) the minimum number of rdata fields. """ return _ldns.ldns_rr_descriptor_minimum(self) #parameters: const ldns_rr_descriptor *, #retvals: size_t - #_LDNS_RR_DESCRIPTOR_METHODS# - %} + # + # _LDNS_RR_DESCRIPTOR_METHODS + # + %} } -/* -rrsig checking wrappers +/* ========================================================================= */ +/* Added C code. */ +/* ========================================================================= */ - copying of rr pointers into the good_keys list leads to double free - problems, therefore we provide two options - either ignore the keys - or get list of indexes of the keys. The latter allows fetching of the - keys later on from the original key set -*/ + +/* + * rrsig checking wrappers + * + * Copying of rr pointers into the good_keys list leads to double free + * problems, therefore we provide two options - either ignore the keys + * or get list of indexes of the keys. The latter allows fetching of the + * keys later on from the original key set. + */ %rename(__ldns_verify_rrsig_keylist) ldns_verify_rrsig_keylist; -%inline %{ -ldns_status ldns_verify_rrsig_keylist_status_only(ldns_rr_list *rrset, - ldns_rr *rrsig, - const ldns_rr_list *keys) { +%inline +%{ + ldns_status ldns_verify_rrsig_keylist_status_only(ldns_rr_list *rrset, + ldns_rr *rrsig, const ldns_rr_list *keys) + { ldns_rr_list *good_keys = ldns_rr_list_new(); - ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys, good_keys); + ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys, + good_keys); ldns_rr_list_free(good_keys); return status; -} + } %} %rename(__ldns_verify_rrsig_keylist) ldns_verify_rrsig_keylist; -%inline %{ -PyObject* ldns_verify_rrsig_keylist_(ldns_rr_list *rrset, - ldns_rr *rrsig, - const ldns_rr_list *keys) { - PyObject* tuple; - PyObject* keylist; - ldns_rr_list *good_keys = ldns_rr_list_new(); - ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys, good_keys); +%inline +%{ + PyObject* ldns_verify_rrsig_keylist_(ldns_rr_list *rrset, + ldns_rr *rrsig, const ldns_rr_list *keys) + { + PyObject* tuple; + PyObject* keylist; + ldns_rr_list *good_keys = ldns_rr_list_new(); + ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys, + good_keys); - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple, 0, SWIG_From_int(status)); - keylist = PyList_New(0); - if (status == LDNS_STATUS_OK) { - unsigned int i; - for (i = 0; i < ldns_rr_list_rr_count(keys); i++) - if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) - PyList_Append(keylist, SWIG_From_int(i)); - } - PyTuple_SetItem(tuple, 1, keylist); - ldns_rr_list_free(good_keys); - return tuple; - } + tuple = PyTuple_New(2); + PyTuple_SetItem(tuple, 0, SWIG_From_int(status)); + keylist = PyList_New(0); + if (status == LDNS_STATUS_OK) { + unsigned int i; + for (i = 0; i < ldns_rr_list_rr_count(keys); i++) { + if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) { + PyList_Append(keylist, SWIG_From_int(i)); + } + } + } + PyTuple_SetItem(tuple, 1, keylist); + ldns_rr_list_free(good_keys); + return tuple; + } %} %rename(__ldns_verify_rrsig_keylist_notime) ldns_verify_rrsig_keylist_notime; -%inline %{ -ldns_status ldns_verify_rrsig_keylist_notime_status_only(ldns_rr_list *rrset, - ldns_rr *rrsig, - const ldns_rr_list *keys) { +%inline +%{ + ldns_status ldns_verify_rrsig_keylist_notime_status_only(ldns_rr_list *rrset, + ldns_rr *rrsig, const ldns_rr_list *keys) + { ldns_rr_list *good_keys = ldns_rr_list_new(); - ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys, good_keys); + ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys, + good_keys); ldns_rr_list_free(good_keys); return status; -} + } %} %rename(__ldns_verify_rrsig_keylist_notime) ldns_verify_rrsig_keylist_notime; -%inline %{ -PyObject* ldns_verify_rrsig_keylist_notime_(ldns_rr_list *rrset, - ldns_rr *rrsig, - const ldns_rr_list *keys) { - PyObject* tuple; - PyObject* keylist; - ldns_rr_list *good_keys = ldns_rr_list_new(); - ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys, good_keys); +%inline +%{ + PyObject* ldns_verify_rrsig_keylist_notime_(ldns_rr_list *rrset, + ldns_rr *rrsig, const ldns_rr_list *keys) + { + PyObject* tuple; + PyObject* keylist; + ldns_rr_list *good_keys = ldns_rr_list_new(); + ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys, + good_keys); - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple, 0, SWIG_From_int(status)); - keylist = PyList_New(0); - if (status == LDNS_STATUS_OK) { - unsigned int i; - for (i = 0; i < ldns_rr_list_rr_count(keys); i++) - if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) - PyList_Append(keylist, SWIG_From_int(i)); - } - PyTuple_SetItem(tuple, 1, keylist); - ldns_rr_list_free(good_keys); - return tuple; - } + tuple = PyTuple_New(2); + PyTuple_SetItem(tuple, 0, SWIG_From_int(status)); + keylist = PyList_New(0); + if (status == LDNS_STATUS_OK) { + unsigned int i; + for (i = 0; i < ldns_rr_list_rr_count(keys); i++) { + if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) { + PyList_Append(keylist, SWIG_From_int(i)); + } + } + } + PyTuple_SetItem(tuple, 1, keylist); + ldns_rr_list_free(good_keys); + return tuple; + } %} -/* -- end of rrsig checking wrappers */ - +/* End of rrsig checking wrappers. */ |
