From: Willem Toorop Date: Tue, 4 Sep 2012 07:34:21 +0000 (+0000) Subject: Support for Python's rich comparison methods into ldns_dname, ldns_rdf, X-Git-Tag: release-1.6.14rc1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92543b13308b8d55f4927b239a2fa64c086cecf6;p=thirdparty%2Fldns.git Support for Python's rich comparison methods into ldns_dname, ldns_rdf, 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! --- diff --git a/contrib/python/Changelog b/contrib/python/Changelog index 0b87e23b..54bc431c 100644 --- a/contrib/python/Changelog +++ b/contrib/python/Changelog @@ -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 diff --git a/contrib/python/examples/test_dname.py b/contrib/python/examples/test_dname.py index 692f0356..d6917073 100755 --- a/contrib/python/examples/test_dname.py +++ b/contrib/python/examples/test_dname.py @@ -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()" diff --git a/contrib/python/examples/test_rdf.py b/contrib/python/examples/test_rdf.py index b45d1afc..4991288c 100755 --- a/contrib/python/examples/test_rdf.py +++ b/contrib/python/examples/test_rdf.py @@ -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()" diff --git a/contrib/python/examples/test_rr.py b/contrib/python/examples/test_rr.py index f8d78e8b..b7bc1e0d 100644 --- a/contrib/python/examples/test_rr.py +++ b/contrib/python/examples/test_rr.py @@ -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: diff --git a/contrib/python/ldns_dname.i b/contrib/python/ldns_dname.i index 33c291be..cd3f53ea 100644 --- a/contrib/python/ldns_dname.i +++ b/contrib/python/ldns_dname.i @@ -202,7 +202,7 @@ 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. @@ -234,6 +234,206 @@ 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, diff --git a/contrib/python/ldns_rdf.i b/contrib/python/ldns_rdf.i index adf87ee4..edff4d62 100644 --- a/contrib/python/ldns_rdf.i +++ b/contrib/python/ldns_rdf.i @@ -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:: diff --git a/contrib/python/ldns_rr.i b/contrib/python/ldns_rr.i index 059461a4..726c6cd9 100644 --- a/contrib/python/ldns_rr.i +++ b/contrib/python/ldns_rr.i @@ -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.