diff options
author | Bob Halley <halley@dnspython.org> | 2020-06-19 09:23:52 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2020-06-19 09:23:52 -0700 |
commit | d41946f9ceea1afaece68700d072a4ad9211a62a (patch) | |
tree | 6f1fff137923781f61b18720b0f3b060ce3a6dd7 | |
parent | 85f390a78fd59938947da2a7c7a25f7c8957d338 (diff) | |
download | dnspython-d41946f9ceea1afaece68700d072a4ad9211a62a.tar.gz |
Make _cmp generic for all EDNS Options. It now compares the wire formats
of two objects of the same class.
Previously we did type-specific stuff for ECSOption, but we only
checked the padded address info, not the srclen or scopelen, so
different options could compare the same. Also, it's not clear that
there's any better semantic ordering of options than the wire format,
so we will just go for simplicity and use the generic implementation.
-rw-r--r-- | dns/edns.py | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/dns/edns.py b/dns/edns.py index 7d78137..82e7abc 100644 --- a/dns/edns.py +++ b/dns/edns.py @@ -69,7 +69,7 @@ class Option: Returns a ``bytes`` or ``None``. """ - raise NotImplementedError + raise NotImplementedError # pragma: no cover @classmethod def from_wire(cls, otype, wire, current, olen): @@ -87,14 +87,20 @@ class Option: Returns a ``dns.edns.Option``. """ - raise NotImplementedError + raise NotImplementedError # pragma: no cover def _cmp(self, other): """Compare an EDNS option with another option of the same type. Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*. """ - raise NotImplementedError + wire = self.to_wire() + owire = other.to_wire() + if wire == owire: + return 0 + if wire > owire: + return 1 + return -1 def __eq__(self, other): if not isinstance(other, Option): @@ -105,9 +111,9 @@ class Option: def __ne__(self, other): if not isinstance(other, Option): - return False + return True if self.otype != other.otype: - return False + return True return self._cmp(other) != 0 def __lt__(self, other): @@ -160,13 +166,6 @@ class GenericOption(Option): def from_wire(cls, otype, wire, current, olen): return cls(otype, wire[current: current + olen]) - def _cmp(self, other): - if self.data == other.data: - return 0 - if self.data > other.data: - return 1 - return -1 - def __str__(self): return self.to_text() @@ -299,13 +298,6 @@ class ECSOption(Option): return cls(addr, src, scope) - def _cmp(self, other): - if self.addrdata == other.addrdata: - return 0 - if self.addrdata > other.addrdata: - return 1 - return -1 - def __str__(self): return self.to_text() |