Added isSplit, a function for checking whether a given QUIT message is a split quit.

This commit is contained in:
Jeremy Fincher 2005-02-25 09:59:39 +00:00
parent 50d390ece4
commit 13e1f7ccb9
2 changed files with 27 additions and 0 deletions

View File

@ -221,6 +221,19 @@ def isAction(msg):
else:
return False
def isSplit(msg):
if msg.command == 'QUIT':
# It's a quit.
quitmsg = msg.args[0]
if not quitmsg.startswith('"') and not quitmsg.endswith('"'):
# It's not a user-generated quitmsg.
servers = quitmsg.split()
if len(servers) == 2:
# We could check if domains match, or if the hostnames actually
# resolve, but we're going to put that off for now.
return True
return False
_unactionre = re.compile(r'^\x01ACTION\s+(.*)\x01$')
def unAction(msg):
"""Returns the payload (i.e., non-ACTION text) of an ACTION msg."""

View File

@ -239,5 +239,19 @@ class FunctionsTestCase(SupyTestCase):
s = str(m)
self.assertEqual(s, 'MODE #foo -b :foo!bar@baz\r\n')
def testIsSplit(self):
m = ircmsgs.IrcMsg(prefix="caker!~caker@ns.theshore.net",
command="QUIT",
args=('jupiter.oftc.net quasar.oftc.net',))
self.failUnless(ircmsgs.isSplit(m))
m = ircmsgs.IrcMsg(prefix="bzbot!Brad2901@ACC87473.ipt.aol.com",
command="QUIT",
args=('Read error: 110 (Connection timed out)',))
self.failIf(ircmsgs.isSplit(m))
m = ircmsgs.IrcMsg(prefix="JibberJim!~none@8212cl.b0nwbeoe.co.uk",
command="QUIT",
args=('"Bye!"',))
self.failIf(ircmsgs.isSplit(m))
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: