summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2009-03-30 23:32:22 +0000
committerBob Halley <halley@dnspython.org>2009-03-30 23:32:22 +0000
commit68480dc55511008abaa9d9c5c9e6df5b39643781 (patch)
treea833dc9f96992b03a6c5f273b624f701c9efc67f
parenta817216b0dc299a7e4edf29658020d4ae07aeb76 (diff)
downloaddnspython-68480dc55511008abaa9d9c5c9e6df5b39643781.tar.gz
make EDNS options comparable
-rw-r--r--dns/edns.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/dns/edns.py b/dns/edns.py
index 093e36a..1731ced 100644
--- a/dns/edns.py
+++ b/dns/edns.py
@@ -49,6 +49,51 @@ class Option(object):
from_wire = classmethod(from_wire)
+ def _cmp(self, other):
+ """Compare an ENDS option with another option of the same type.
+ Return < 0 if self < other, 0 if self == other, and > 0 if self > other.
+ """
+ raise NotImplementedError
+
+ def __eq__(self, other):
+ if not isinstance(other, Option):
+ return False
+ if self.otype != other.otype:
+ return False
+ return self._cmp(other) == 0
+
+ def __ne__(self, other):
+ if not isinstance(other, Option):
+ return False
+ if self.otype != other.otype:
+ return False
+ return self._cmp(other) != 0
+
+ def __lt__(self, other):
+ if not isinstance(other, Option) or \
+ self.otype != other.otype:
+ return NotImplemented
+ return self._cmp(other) < 0
+
+ def __le__(self, other):
+ if not isinstance(other, Option) or \
+ self.otype != other.otype:
+ return NotImplemented
+ return self._cmp(other) <= 0
+
+ def __ge__(self, other):
+ if not isinstance(other, Option) or \
+ self.otype != other.otype:
+ return NotImplemented
+ return self._cmp(other) >= 0
+
+ def __gt__(self, other):
+ if not isinstance(other, Option) or \
+ self.otype != other.otype:
+ return NotImplemented
+ return self._cmp(other) > 0
+
+
class GenericOption(Option):
"""Generate Rdata Class
@@ -68,6 +113,8 @@ class GenericOption(Option):
from_wire = classmethod(from_wire)
+ def _cmp(self, other):
+ return cmp(self.data, other.data)
_type_to_class = {
}