Ticket #5329: issue5329.diff

File issue5329.diff, 18.5 KB (added by Ezio Melotti, 9 years ago)
  • twisted/words/protocols/irc.py

     
    272272            raise ValueError, "Somebody screwed up, 'cuz this doesn't" \
    273273                  " look like a command to me: %s" % command
    274274
    275         line = string.join([command] + list(parameter_list))
     275        line = ' '.join([command] + list(parameter_list))
    276276        if 'prefix' in prefix:
    277277            line = ":%s %s" % (prefix['prefix'], line)
    278278        self.sendLine(line)
     
    17641764        if not (size is None):
    17651765            args.append(size)
    17661766
    1767         args = string.join(args, ' ')
     1767        args = ' '.join(args)
    17681768
    17691769        self.ctcpMakeQuery(user, [('DCC', args)])
    17701770
     
    18481848        """
    18491849        Called when a user joins a channel.
    18501850        """
    1851         nick = string.split(prefix,'!')[0]
     1851        nick = prefix.split('!')[0]
    18521852        channel = params[-1]
    18531853        if nick == self.nickname:
    18541854            self.joined(channel)
     
    18591859        """
    18601860        Called when a user leaves a channel.
    18611861        """
    1862         nick = string.split(prefix,'!')[0]
     1862        nick = prefix.split('!')[0]
    18631863        channel = params[0]
    18641864        if nick == self.nickname:
    18651865            self.left(channel)
     
    18701870        """
    18711871        Called when a user has quit.
    18721872        """
    1873         nick = string.split(prefix,'!')[0]
     1873        nick = prefix.split('!')[0]
    18741874        self.userQuit(nick, params[0])
    18751875
    18761876
     
    19311931            if not m['normal']:
    19321932                return
    19331933
    1934             message = string.join(m['normal'], ' ')
     1934            message = ' '.join(m['normal'])
    19351935
    19361936        self.privmsg(user, channel, message)
    19371937
     
    19511951            if not m['normal']:
    19521952                return
    19531953
    1954             message = string.join(m['normal'], ' ')
     1954            message = ' '.join(m['normal'])
    19551955
    19561956        self.noticed(user, channel, message)
    19571957
     
    19591959        """
    19601960        Called when a user changes their nickname.
    19611961        """
    1962         nick = string.split(prefix,'!', 1)[0]
     1962        nick = prefix.split('!', 1)[0]
    19631963        if nick == self.nickname:
    19641964            self.nickChanged(params[0])
    19651965        else:
     
    19691969        """
    19701970        Called when a user is kicked from a channel.
    19711971        """
    1972         kicker = string.split(prefix,'!')[0]
     1972        kicker = prefix.split('!')[0]
    19731973        channel = params[0]
    19741974        kicked = params[1]
    19751975        message = params[-1]
    1976         if string.lower(kicked) == string.lower(self.nickname):
     1976        if kicked.lower() == self.nickname.lower():
    19771977            # Yikes!
    19781978            self.kickedFrom(channel, kicker, message)
    19791979        else:
     
    19831983        """
    19841984        Someone in the channel set the topic.
    19851985        """
    1986         user = string.split(prefix, '!')[0]
     1986        user = prefix.split('!')[0]
    19871987        channel = params[0]
    19881988        newtopic = params[1]
    19891989        self.topicUpdated(user, channel, newtopic)
     
    19931993        Called when the topic for a channel is initially reported or when it
    19941994        subsequently changes.
    19951995        """
    1996         user = string.split(prefix, '!')[0]
     1996        user = prefix.split('!')[0]
    19971997        channel = params[1]
    19981998        newtopic = params[2]
    19991999        self.topicUpdated(user, channel, newtopic)
    20002000
    20012001    def irc_RPL_NOTOPIC(self, prefix, params):
    2002         user = string.split(prefix, '!')[0]
     2002        user = prefix.split('!')[0]
    20032003        channel = params[1]
    20042004        newtopic = ""
    20052005        self.topicUpdated(user, channel, newtopic)
     
    21082108        self.action(user, channel, data)
    21092109
    21102110    def ctcpQuery_PING(self, user, channel, data):
    2111         nick = string.split(user,"!")[0]
     2111        nick = user.split('!')[0]
    21122112        self.ctcpMakeReply(nick, [("PING", data)])
    21132113
    21142114    def ctcpQuery_FINGER(self, user, channel, data):
     
    21232123        else:
    21242124            reply = str(self.fingerReply)
    21252125
    2126         nick = string.split(user,"!")[0]
     2126        nick = user.split('!')[0]
    21272127        self.ctcpMakeReply(nick, [('FINGER', reply)])
    21282128
    21292129    def ctcpQuery_VERSION(self, user, channel, data):
     
    21322132                               % (user, data))
    21332133
    21342134        if self.versionName:
    2135             nick = string.split(user,"!")[0]
     2135            nick = user.split('!')[0]
    21362136            self.ctcpMakeReply(nick, [('VERSION', '%s:%s:%s' %
    21372137                                       (self.versionName,
    21382138                                        self.versionNum or '',
     
    21432143            self.quirkyMessage("Why did %s send '%s' with a SOURCE query?"
    21442144                               % (user, data))
    21452145        if self.sourceURL:
    2146             nick = string.split(user,"!")[0]
     2146            nick = user.split('!')[0]
    21472147            # The CTCP document (Zeuge, Rollo, Mesander 1994) says that SOURCE
    21482148            # replies should be responded to with the location of an anonymous
    21492149            # FTP server in host:directory:file format.  I'm taking the liberty
     
    21562156            self.quirkyMessage("Why did %s send '%s' with a USERINFO query?"
    21572157                               % (user, data))
    21582158        if self.userinfo:
    2159             nick = string.split(user,"!")[0]
     2159            nick = user.split('!')[0]
    21602160            self.ctcpMakeReply(nick, [('USERINFO', self.userinfo)])
    21612161
    21622162    def ctcpQuery_CLIENTINFO(self, user, channel, data):
     
    21682168        the usage of that tag.
    21692169        """
    21702170
    2171         nick = string.split(user,"!")[0]
     2171        nick = user.split('!')[0]
    21722172        if not data:
    21732173            # XXX: prefixedMethodNames gets methods from my *class*,
    21742174            # but it's entirely possible that this *instance* has more
     
    21762176            names = reflect.prefixedMethodNames(self.__class__,
    21772177                                                'ctcpQuery_')
    21782178
    2179             self.ctcpMakeReply(nick, [('CLIENTINFO',
    2180                                        string.join(names, ' '))])
     2179            self.ctcpMakeReply(nick, [('CLIENTINFO', ' '.join(names))])
    21812180        else:
    2182             args = string.split(data)
     2181            args = data.split()
    21832182            method = getattr(self, 'ctcpQuery_%s' % (args[0],), None)
    21842183            if not method:
    21852184                self.ctcpMakeReply(nick, [('ERRMSG',
     
    21942193    def ctcpQuery_ERRMSG(self, user, channel, data):
    21952194        # Yeah, this seems strange, but that's what the spec says to do
    21962195        # when faced with an ERRMSG query (not a reply).
    2197         nick = string.split(user,"!")[0]
     2196        nick = user.split('!')[0]
    21982197        self.ctcpMakeReply(nick, [('ERRMSG',
    21992198                                   "%s :No error has occoured." % data)])
    22002199
     
    22022201        if data is not None:
    22032202            self.quirkyMessage("Why did %s send '%s' with a TIME query?"
    22042203                               % (user, data))
    2205         nick = string.split(user,"!")[0]
     2204        nick = user.split('!')[0]
    22062205        self.ctcpMakeReply(nick,
    22072206                           [('TIME', ':%s' %
    22082207                             time.asctime(time.localtime(time.time())))])
     
    22202219            data = data[len(dcctype)+1:]
    22212220            handler(user, channel, data)
    22222221        else:
    2223             nick = string.split(user,"!")[0]
     2222            nick = user.split('!')[0]
    22242223            self.ctcpMakeReply(nick, [('ERRMSG',
    22252224                                       "DCC %s :Unknown DCC type '%s'"
    22262225                                       % (data, dcctype))])
     
    23902389        """When I get a message that's so broken I can't use it.
    23912390        """
    23922391        log.msg(line)
    2393         log.msg(string.join(traceback.format_exception(excType,
    2394                                                         excValue,
    2395                                                         tb),''))
     2392        log.msg(''.join(traceback.format_exception(excType, excValue, tb)))
    23962393
    23972394    def quirkyMessage(self, s):
    23982395        """This is called when I receive a message which is peculiar,
     
    26572654
    26582655    def dataReceived(self, data):
    26592656        self.buffer = self.buffer + data
    2660         lines = string.split(self.buffer, LF)
     2657        lines = self.buffer.split(LF)
    26612658        # Put the (possibly empty) element after the last LF back in the
    26622659        # buffer
    26632660        self.buffer = lines.pop()
     
    26992696    """
    27002697
    27012698    orig_data = data
    2702     data = string.split(data)
     2699    data = data.split()
    27032700    if len(data) < 4:
    27042701        return orig_data
    27052702
     
    27212718                )
    27222719            # The mapping to 'int' is to get rid of those accursed
    27232720            # "L"s which python 1.5.2 puts on the end of longs.
    2724             address = string.join(map(str,map(int,address)), ".")
     2721            address = '.'.join(map(str,map(int,address)))
    27252722
    27262723    if dcctype == 'SEND':
    27272724        filename = arg
     
    28922889    retval = {'extended': extended_messages,
    28932890              'normal': normal_messages }
    28942891
    2895     messages = string.split(message, X_DELIM)
     2892    messages = message.split(X_DELIM)
    28962893    odd = 0
    28972894
    28982895    # X1 extended data X2 nomal data X3 extended data X4 normal...
     
    29082905
    29092906    extended_messages[:] = map(ctcpDequote, extended_messages)
    29102907    for i in xrange(len(extended_messages)):
    2911         m = string.split(extended_messages[i], SPC, 1)
     2908        m = extended_messages[i].split(SPC, 1)
    29122909        tag = m[0]
    29132910        if len(m) > 1:
    29142911            data = m[1]
     
    29392936
    29402937def lowQuote(s):
    29412938    for c in (M_QUOTE, NUL, NL, CR):
    2942         s = string.replace(s, c, mQuoteTable[c])
     2939        s = s.replace(c, mQuoteTable[c])
    29432940    return s
    29442941
    29452942def lowDequote(s):
     
    29692966
    29702967def ctcpQuote(s):
    29712968    for c in (X_QUOTE, X_DELIM):
    2972         s = string.replace(s, c, xQuoteTable[c])
     2969        s = s.replace(c, xQuoteTable[c])
    29732970    return s
    29742971
    29752972def ctcpDequote(s):
     
    30083005        m = "%s%s%s" % (X_DELIM, m, X_DELIM)
    30093006        coded_messages.append(m)
    30103007
    3011     line = string.join(coded_messages, '')
     3008    line = ''.join(coded_messages)
    30123009    return line
    30133010
    30143011
  • twisted/words/test/test_irc.py

     
    18821882
    18831883
    18841884
     1885class CollectorClient(irc.IRCClient):
     1886    """A client that saves in a list the name of the methods that got called."""
     1887    def __init__(self, methods_list):
     1888        # methods_list is a list of methods' names that should be replaced
     1889        self.methods = []
     1890        self.nickname = 'Wolf'  # set 'Wolf' as the current nickname
     1891
     1892        for method in methods_list:
     1893            def fake_method(method=method):
     1894                def inner(*args):
     1895                    self.methods.append((method, args))
     1896                return inner
     1897            setattr(self, method, fake_method())
     1898
     1899
     1900
     1901class TestServerToClient(TestCase):
     1902    """Tests for the irc_* methods sent from the server to the client."""
     1903    def setUp(self):
     1904        methods_list = ['joined', 'userJoined', 'left', 'userLeft', 'userQuit',
     1905                        'noticed', 'kickedFrom', 'userKicked', 'topicUpdated']
     1906        self.client = CollectorClient(methods_list)
     1907
     1908    def test_irc_JOIN(self):
     1909        """
     1910        L{IRCClient.joined} is called when I join a channel;
     1911        l{IRCClient.userJoined} is called when someone else joins.
     1912        """
     1913        self.client.irc_JOIN('Wolf!~wolf@yok.utu.fi', ['#twisted'])
     1914        self.client.irc_JOIN('Svadilfari!~svadi@yok.utu.fi', ['#python'])
     1915        self.assertEqual(self.client.methods,
     1916                         [('joined', ('#twisted',)),
     1917                          ('userJoined', ('Svadilfari', '#python'))])
     1918
     1919    def test_irc_PART(self):
     1920        """
     1921        L{IRCClient.left} is called when I part the channel;
     1922        l{IRCClient.userLeft} is called when someone else parts.
     1923        """
     1924        self.client.irc_PART('Wolf!~wolf@yok.utu.fi', ['#twisted'])
     1925        self.client.irc_PART('Svadilfari!~svadi@yok.utu.fi', ['#python'])
     1926        self.assertEqual(self.client.methods,
     1927                         [('left', ('#twisted',)),
     1928                          ('userLeft', ('Svadilfari', '#python'))])
     1929
     1930    def test_irc_QUIT(self):
     1931        """
     1932        L{IRCClient.userQuit} is called whenever someone quits
     1933        the channel (myself included).
     1934        """
     1935        self.client.irc_QUIT('Svadilfari!~svadi@yok.utu.fi', ['Adios.'])
     1936        self.client.irc_QUIT('Wolf!~wolf@yok.utu.fi', ['Farewell.'])
     1937        self.assertEqual(self.client.methods,
     1938                         [('userQuit', ('Svadilfari', 'Adios.')),
     1939                          ('userQuit', ('Wolf', 'Farewell.'))])
     1940
     1941    def test_irc_NOTICE(self):
     1942        """
     1943        L{IRCClient.noticed} is called when a notice is received.
     1944        """
     1945        user = 'Wolf!~wolf@yok.utu.fi'
     1946        msg = ('%(X)cextended%(X)cdata1%(X)cextended%(X)cdata2%(X)c%(EOL)s' %
     1947               {'X': irc.X_DELIM, 'EOL': irc.CR + irc.LF})
     1948        self.client.irc_NOTICE(user, ['#twisted', msg])
     1949        self.assertEqual(self.client.methods,
     1950                         [('noticed', (user, '#twisted', 'data1 data2'))])
     1951
     1952    def test_irc_KICK(self):
     1953        """
     1954        L{IRCClient.kickedFrom} is called when I get kicked from the channel;
     1955        l{IRCClient.userKicked} is called when someone else gets kicked.
     1956        """
     1957        # fight!
     1958        self.client.irc_KICK('Svadilfari!~svadi@yok.utu.fi',
     1959                             ['#python', 'WOLF', 'shoryuken!'])
     1960        self.client.irc_KICK('Wolf!~wolf@yok.utu.fi',
     1961                             ['#twisted', 'Svadilfari', 'hadouken!'])
     1962        self.assertEqual(self.client.methods,
     1963                         [('kickedFrom',
     1964                           ('#python', 'Svadilfari', 'shoryuken!')),
     1965                          ('userKicked',
     1966                           ('Svadilfari', '#twisted', 'Wolf', 'hadouken!'))])
     1967
     1968    def test_irc_TOPIC(self):
     1969        """
     1970        L{IRCClient.topicUpdated} is called when someone sets the topic.
     1971        """
     1972        self.client.irc_TOPIC('Wolf!~wolf@yok.utu.fi',
     1973                              ['#twisted', 'new topic is new'])
     1974        self.assertEqual(self.client.methods,
     1975                         [('topicUpdated',
     1976                           ('Wolf', '#twisted', 'new topic is new'))])
     1977
     1978    def test_irc_RPL_TOPIC(self):
     1979        """
     1980        L{IRCClient.topicUpdated} is called when the topic is initially
     1981        reported.
     1982        """
     1983        self.client.irc_RPL_TOPIC('Wolf!~wolf@yok.utu.fi',
     1984                              ['?', '#twisted', 'new topic is new'])
     1985        self.assertEqual(self.client.methods,
     1986                         [('topicUpdated',
     1987                           ('Wolf', '#twisted', 'new topic is new'))])
     1988
     1989    def test_irc_RPL_NOTOPIC(self):
     1990        """
     1991        L{IRCClient.topicUpdated} is called when the topic is removed.
     1992        """
     1993        self.client.irc_RPL_NOTOPIC('Wolf!~wolf@yok.utu.fi', ['?', '#twisted'])
     1994        self.assertEqual(self.client.methods,
     1995                         [('topicUpdated', ('Wolf', '#twisted', ''))])
     1996
     1997
     1998
     1999class TestCTCPQuery(TestCase):
     2000    """Tests for the ctcpQuery_* methods."""
     2001    def setUp(self):
     2002        self.client = CollectorClient(['ctcpMakeReply'])
     2003
     2004    def test_ctcpQuery_PING(self):
     2005        """
     2006        Test that L{IRCClient.ctcpQuery_PING} calls L{IRCClient.ctcpMakeReply}
     2007        with the correct args.
     2008        """
     2009        self.client.ctcpQuery_PING('Wolf!~wolf@yok.utu.fi', '#twisted', 'data')
     2010        self.assertEqual(self.client.methods,
     2011                         [('ctcpMakeReply', ('Wolf', [('PING', 'data')]))])
     2012
     2013    def test_ctcpQuery_FINGER(self):
     2014        """
     2015        Test that L{IRCClient.ctcpQuery_FINGER} calls L{IRCClient.ctcpMakeReply}
     2016        with the correct args.
     2017        """
     2018        self.patch(self.client, 'fingerReply', 'reply')
     2019        self.client.ctcpQuery_FINGER('Wolf!~wolf@yok.utu.fi',
     2020                                     '#twisted', 'data')
     2021        self.assertEqual(self.client.methods,
     2022                         [('ctcpMakeReply', ('Wolf', [('FINGER', 'reply')]))])
     2023
     2024    def test_ctcpQuery_SOURCE(self):
     2025        """
     2026        Test that L{IRCClient.ctcpQuery_SOURCE} calls L{IRCClient.ctcpMakeReply}
     2027        with the correct args.
     2028        """
     2029        self.patch(self.client, 'sourceURL', 'url')
     2030        self.client.ctcpQuery_SOURCE('Wolf!~wolf@yok.utu.fi',
     2031                                     '#twisted', 'data')
     2032        self.assertEqual(self.client.methods,
     2033                         [('ctcpMakeReply', ('Wolf', [('SOURCE', 'url'),
     2034                                                      ('SOURCE', None)]))])
     2035
     2036    def test_ctcpQuery_USERINFO(self):
     2037        """
     2038        Test that L{IRCClient.ctcpQuery_USERINFO} calls L{IRCClient.ctcpMakeReply}
     2039        with the correct args.
     2040        """
     2041        self.patch(self.client, 'userinfo', 'info')
     2042        self.client.ctcpQuery_USERINFO('Wolf!~wolf@yok.utu.fi',
     2043                                       '#twisted', 'data')
     2044        self.assertEqual(self.client.methods,
     2045                         [('ctcpMakeReply', ('Wolf', [('USERINFO', 'info')]))])
     2046
     2047    def test_ctcpQuery_CLIENTINFO(self):
     2048        """
     2049        Test that L{IRCClient.ctcpQuery_CLIENTINFO} calls
     2050        L{IRCClient.ctcpMakeReply} with the correct args.
     2051        """
     2052        self.client.ctcpQuery_CLIENTINFO('Wolf!~wolf@yok.utu.fi',
     2053                                         '#twisted', '')
     2054        self.client.ctcpQuery_CLIENTINFO('Wolf!~wolf@yok.utu.fi',
     2055                                         '#twisted', 'PING PONG')
     2056        info = ('CLIENTINFO PING DCC SOURCE VERSION '
     2057                'USERINFO TIME ACTION ERRMSG FINGER')
     2058        self.assertEqual(self.client.methods,
     2059                         [('ctcpMakeReply', ('Wolf', [('CLIENTINFO', info)])),
     2060                          ('ctcpMakeReply', ('Wolf', [('CLIENTINFO', None)]))])
     2061
     2062    def test_ctcpQuery_TIME(self):
     2063        """
     2064        Test that L{IRCClient.ctcpQuery_TIME} calls L{IRCClient.ctcpMakeReply}
     2065        with the correct args.
     2066        """
     2067        self.client.ctcpQuery_TIME('Wolf!~wolf@yok.utu.fi', '#twisted', 'data')
     2068        self.assertEqual(self.client.methods[0][1][0], 'Wolf')
     2069
     2070    def test_ctcpQuery_DCC(self):
     2071        """
     2072        Test that L{IRCClient.ctcpQuery_DCC} calls L{IRCClient.ctcpMakeReply}
     2073        with the correct args.
     2074        """
     2075        self.client.ctcpQuery_DCC('Wolf!~wolf@yok.utu.fi', '#twisted', 'data')
     2076        self.assertEqual(self.client.methods,
     2077                         [('ctcpMakeReply',
     2078                           ('Wolf', [('ERRMSG',
     2079                                      "DCC data :Unknown DCC type 'DATA'")]))])
     2080
     2081
     2082
    18852083class DccChatFactoryTests(unittest.TestCase):
    18862084    """
    18872085    Tests for L{DccChatFactory}