]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Support for Python's rich comparison methods into ldns_dname, ldns_rdf,
authorWillem Toorop <willem@NLnetLabs.nl>
Tue, 4 Sep 2012 07:34:21 +0000 (07:34 +0000)
committerWillem Toorop <willem@NLnetLabs.nl>
Tue, 4 Sep 2012 07:34:21 +0000 (07:34 +0000)
ldns_rr and ldns_rr_list classes. These are necessary for the proper
function of binary comparison operators (<, ==, ...) in Python 3,
because the __cmp__() special method isn't supported in Python 3.

From Karel Slany. Thanks!

contrib/python/Changelog
contrib/python/examples/test_dname.py
contrib/python/examples/test_rdf.py
contrib/python/examples/test_rr.py
contrib/python/ldns_dname.i
contrib/python/ldns_rdf.i
contrib/python/ldns_rr.i

index 0b87e23b52f87310b808d9d86c6c9500c0cb379b..54bc431c061c58d81519a8a2738a47153a130393 100644 (file)
@@ -1,4 +1,6 @@
 1.6.14
+       * 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
index 692f03566ed4f6d2174abc0cd749c4732ca16e98..d69170737acc073f45e4d7e97f2039be786e213d 100755 (executable)
@@ -79,6 +79,109 @@ if True:
         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()"
index b45d1afc8fd40add6241677333006308a9452150..4991288c83f25f0bd9b95e8d94f46fb783601abc 100755 (executable)
@@ -43,6 +43,109 @@ if True:
         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()"
index f8d78e8ba4c402e808ef284bbfa8b79247b6c87c..b7bc1e0d9717ff092e3f09e00264c6ed03f6822e 100644 (file)
@@ -32,36 +32,108 @@ def set_error():
        (inspect.currentframe().f_back.f_lineno, method_name))
 
 
+
 #if not error_detected:
-#if True:
-#    method_name = class_name + ".__cmp__()"
-#    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 ret != True:
-#            set_error()
-#    except:
-#        set_error()
-#    try:
-#        ret = rr1 == rr2
-#        if ret != False:
-#            set_error()
-#    except:
-#        set_error()
-#    try:
-#        ret = rr1 > rr2
-#        if ret != False:
-#            set_error()
-#    except:
-#        set_error()
-#    try:
-#        ret = rr1 != ""
-#        set_error()
-#    except TypeError:
-#        pass
-#    except:
-#        set_error()
+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:
@@ -1684,37 +1756,108 @@ temp_fname = "tmp_rr_list.txt"
 
 
 #if not error_detected:
-#if True:
-#    method_name = class_name + ".__cmp__()"
-#    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 ret != True:
-#            set_error()
-#    except:
-#        set_error()
-#    try:
-#        ret = rrl1 == rrl2
-#        if ret != False:
-#            set_error()
-#    except:
-#        set_error()
-#    try:
-#        ret = rrl1 > rrl2
-#        if ret != False:
-#            set_error()
-#    except:
-#        set_error()
-#    try:
-#        ret = rrl1 != ""
-#        set_error()
-#    except TypeError:
-#        pass
-#    except:
-#        set_error()
+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:
index 33c291bef1359de147eee4b47df23e75f5fd4454..cd3f53ea3351b8d50644c9378b17ee4551eb401f 100644 (file)
 
         def __cmp__(self, other):
             """
-               Compares the two dname rdf's according to the algorithm for
+               Compares two dname rdf according to the algorithm for
                ordering in RFC4034 Section 6.
                
                :param other: The second dname rdf to compare.
                 raise Exception("Operands must be ldns_dname.")
             return _ldns.ldns_dname_compare(self, other)
 
+        def __lt__(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 '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.__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
+
+        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,
index adf87ee400232e0fc2314dbda2f2e9a079a98fb6..edff4d6249920dc7a92b541c96f8d4bfaf41ce8b 100644 (file)
@@ -299,18 +299,86 @@ specified in the (16-bit) type field with a value from ldns_rdf_type."
 
         def __cmp__(self, other):
             """
-               Compares two rdf's on their wire formats.
+               Compares two rdfs on their wire formats.
                
                (To order dnames according to rfc4034, use ldns_dname_compare.)
                
                :param other: The second one RDF.
                :type other: :class:`ldns_rdf`
-               :throws TypeError: When other of non-:class:`ldns_rdf` type.
+               :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 __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
@@ -527,15 +595,15 @@ specified in the (16-bit) type field with a value from ldns_rdf_type."
 
         def dname_compare(self, other):
             """
-               Compares the two dname rdf's according to the algorithm
+               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_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.
+               :return: (int) -1, 0 or 1 if `self` comes before `other`,
+                   `self` is equal or `self` comes after `other` respectively.
 
                .. warning::
 
index 059461a4f318a68c836e6e306030fb3e83d4ea47..726c6cd902afb4f0ae13948ec6e4e62eb7a34a64 100644 (file)
@@ -796,7 +796,6 @@ to create :class:`ldns_rr` instances.
         # _LDNS_RR_CONSTRUCTORS
         #
 
-
         def __str__(self):
             """
                Converts the data in the resource record to presentation format.
@@ -819,6 +818,86 @@ to create :class:`ldns_rr` instances.
             """
             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.
+               :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) == -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):
             """
@@ -1923,6 +2002,80 @@ This class contains a list of RR's (see :class:`ldns.ldns_rr`).
             """
             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.