1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
from __future__ import unicode_literals
class Notify(object):
def __init__(self, pid, channel, payload=''):
self.pid = pid
self.channel = channel
self.payload = payload
def __eq__(self, other):
if isinstance(other, tuple):
return other == self._astuple(False)
if isinstance(other, Notify):
return self._astuple(True) == other._astuple(True)
return False
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash(self._astuple(bool(self.payload)))
def __getitem__(self, key):
return (self.pid, self.channel)[key]
def __len__(self):
return 2
def _astuple(self, with_payload):
if not with_payload:
return (self.pid, self.channel)
return (self.pid, self.channel, self.payload)
|