mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Fixed a bug in the handling of the msg keyword argument in IrcMsg.
This commit is contained in:
parent
e02589c204
commit
288f6179d6
@ -77,25 +77,14 @@ class IrcMsg(object):
|
|||||||
__slots__ = ('args', 'command', 'host', 'nick', 'prefix', 'user',
|
__slots__ = ('args', 'command', 'host', 'nick', 'prefix', 'user',
|
||||||
'_hash', '_str', '_repr', '_len')
|
'_hash', '_str', '_repr', '_len')
|
||||||
def __init__(self, s='', command='', args=None, prefix='', msg=None):
|
def __init__(self, s='', command='', args=None, prefix='', msg=None):
|
||||||
|
assert not (msg and s), 'Ircmsg.__init__ cannot accept both s and msg'
|
||||||
if not s and not command and not msg:
|
if not s and not command and not msg:
|
||||||
raise ValueError, 'IRC messages require a command.'
|
raise ValueError, 'IRC messages require a command.'
|
||||||
self._str = None
|
self._str = None
|
||||||
self._repr = None
|
self._repr = None
|
||||||
self._hash = None
|
self._hash = None
|
||||||
self._len = None
|
self._len = None
|
||||||
if msg is not None:
|
if s:
|
||||||
self.prefix = msg.prefix
|
|
||||||
self.command = msg.command
|
|
||||||
self.args = tuple(msg.args)
|
|
||||||
if command: # Must be using command=, args=, prefix= form.
|
|
||||||
self.prefix = prefix
|
|
||||||
self.command = command
|
|
||||||
if args is not None:
|
|
||||||
assert all(ircutils.isValidArgument, args)
|
|
||||||
self.args = tuple(args)
|
|
||||||
else:
|
|
||||||
self.args = ()
|
|
||||||
elif s: # Must be using a string.
|
|
||||||
self._str = s
|
self._str = s
|
||||||
if s[0] == ':':
|
if s[0] == ':':
|
||||||
self.prefix, s = s[1:].split(None, 1)
|
self.prefix, s = s[1:].split(None, 1)
|
||||||
@ -108,11 +97,30 @@ class IrcMsg(object):
|
|||||||
else:
|
else:
|
||||||
self.args = s.split()
|
self.args = s.split()
|
||||||
self.command = self.args.pop(0)
|
self.command = self.args.pop(0)
|
||||||
|
else:
|
||||||
|
if msg is not None:
|
||||||
|
if prefix:
|
||||||
|
self.prefix = prefix
|
||||||
|
else:
|
||||||
|
self.prefix = msg.prefix
|
||||||
|
if command:
|
||||||
|
self.command = command
|
||||||
|
else:
|
||||||
|
self.command = msg.command
|
||||||
|
if args:
|
||||||
|
self.args = args
|
||||||
|
else:
|
||||||
|
self.args = msg.args
|
||||||
|
else:
|
||||||
|
self.prefix = prefix
|
||||||
|
self.command = command
|
||||||
|
assert all(ircutils.isValidArgument, args)
|
||||||
|
self.args = args
|
||||||
|
self.args = tuple(self.args)
|
||||||
if ircutils.isUserHostmask(self.prefix):
|
if ircutils.isUserHostmask(self.prefix):
|
||||||
(self.nick,self.user,self.host)=ircutils.splitHostmask(self.prefix)
|
(self.nick,self.user,self.host)=ircutils.splitHostmask(self.prefix)
|
||||||
else:
|
else:
|
||||||
(self.nick, self.user, self.host) = (self.prefix,)*3
|
(self.nick, self.user, self.host) = (self.prefix,)*3
|
||||||
self.args = tuple(self.args)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self._str is not None:
|
if self._str is not None:
|
||||||
|
@ -104,6 +104,13 @@ class IrcMsgTestCase(unittest.TestCase):
|
|||||||
zeroes += 1
|
zeroes += 1
|
||||||
self.failIf(zeroes > (len(msgs)/10), 'Too many zero hashes.')
|
self.failIf(zeroes > (len(msgs)/10), 'Too many zero hashes.')
|
||||||
|
|
||||||
|
def testMsgKeywordHandledProperly(self):
|
||||||
|
msg = ircmsgs.notice('foo', 'bar')
|
||||||
|
msg2 = ircmsgs.IrcMsg(msg=msg, command='PRIVMSG')
|
||||||
|
self.assertEqual(msg2.command, 'PRIVMSG')
|
||||||
|
self.assertEqual(msg2.args, msg.args)
|
||||||
|
|
||||||
|
|
||||||
class FunctionsTestCase(unittest.TestCase):
|
class FunctionsTestCase(unittest.TestCase):
|
||||||
def testIsAction(self):
|
def testIsAction(self):
|
||||||
L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG'
|
L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG'
|
||||||
|
Loading…
Reference in New Issue
Block a user