Implement hashing functions for Command and ServerSession.
This commit is contained in:
parent
ee58e59e7e
commit
f9526e78a8
2 changed files with 22 additions and 0 deletions
|
|
@ -201,6 +201,19 @@ class Command(with_metaclass(CommandMeta, object)):
|
||||||
# probably got a string
|
# probably got a string
|
||||||
return cmd in self._matchset
|
return cmd in self._matchset
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
"""
|
||||||
|
Python 3 requires that any class which implements __eq__ must also
|
||||||
|
implement __hash__ and that the corresponding hashes for equivalent
|
||||||
|
instances are themselves equivalent.
|
||||||
|
|
||||||
|
Technically, the following implementation is only valid for comparison
|
||||||
|
against other Commands, as our __eq__ supports comparison against
|
||||||
|
str, too.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return hash('\n'.join(self._matchset))
|
||||||
|
|
||||||
def __ne__(self, cmd):
|
def __ne__(self, cmd):
|
||||||
"""
|
"""
|
||||||
The logical negation of __eq__. Since this is one of the most
|
The logical negation of __eq__. Since this is one of the most
|
||||||
|
|
|
||||||
|
|
@ -433,6 +433,15 @@ class ServerSession(Session):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
"""
|
||||||
|
Python 3 requires that any class which implements __eq__ must also
|
||||||
|
implement __hash__ and that the corresponding hashes for equivalent
|
||||||
|
instances are themselves equivalent.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return hash(self.address)
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
try:
|
try:
|
||||||
return self.address != other.address
|
return self.address != other.address
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue