mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
This is a far more reasonable implementation of __len__.
This commit is contained in:
parent
b9d109222a
commit
ee145e7959
@ -166,17 +166,7 @@ class IrcMsg(object):
|
|||||||
return self._str
|
return self._str
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
if self._len is not None:
|
return len(str(self))
|
||||||
return self._len
|
|
||||||
self._len = 0
|
|
||||||
if self.prefix:
|
|
||||||
self._len += len(self.prefix)
|
|
||||||
self._len += len(self.command)
|
|
||||||
if self.args:
|
|
||||||
for arg in self.args:
|
|
||||||
self._len += len(arg) + 1 # Remember space prior to the arg.
|
|
||||||
self._len += 2 # For colon before the prefix and before the last arg.
|
|
||||||
return self._len
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return isinstance(other, self.__class__) and \
|
return isinstance(other, self.__class__) and \
|
||||||
@ -184,9 +174,11 @@ class IrcMsg(object):
|
|||||||
self.command == other.command and \
|
self.command == other.command and \
|
||||||
self.prefix == other.prefix and \
|
self.prefix == other.prefix and \
|
||||||
self.args == other.args
|
self.args == other.args
|
||||||
|
__req__ = __eq__ # I don't know exactly what this does, but it can't hurt.
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not (self == other)
|
return not (self == other)
|
||||||
|
__rne__ = __ne__ # Likewise as above.
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
if self._hash is not None:
|
if self._hash is not None:
|
||||||
@ -216,12 +208,6 @@ class IrcMsg(object):
|
|||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
return self.tagged(attr)
|
return self.tagged(attr)
|
||||||
|
|
||||||
## try:
|
|
||||||
## import _ircmsg
|
|
||||||
## IrcMsg = _ircmsg.IrcMsg
|
|
||||||
## except:
|
|
||||||
## pass
|
|
||||||
|
|
||||||
|
|
||||||
def isCtcp(msg):
|
def isCtcp(msg):
|
||||||
"""Returns whether or not msg is a CTCP message."""
|
"""Returns whether or not msg is a CTCP message."""
|
||||||
|
Loading…
Reference in New Issue
Block a user