Ticket #5780: 5780v3.patch

File 5780v3.patch, 2.6 KB (added by stephsolis, 14 months ago)

Addressed more review suggestions.

  • twisted/topfiles/5780.bugfix

     
     1twisted.words.service.IRCUser now allows NICK commands with non-UTF8 and non-ASCII symbols. 
  • twisted/words/test/test_irc_service.py

     
    4444 
    4545    def test_utf8Messages(self): 
    4646        """ 
    47         An C{Exception} is not raised when a UTF-8 nick is set and a UTF-8  
    48         message is sent. 
     47        When a UTF8 message is sent with sendMessage and the current IRCUser 
     48        has a UTF8 nick and is set to UTF8 encoding, the message will be  
     49        written to the transport. 
    4950        """ 
    50         expectedResult = (":example.com \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 " 
    51                           "\xd0\xbd\xd0\xb8\xd0\xba\r\n") 
     51        expectedResult = (u":example.com \u0442\u0435\u0441\u0442 " 
     52                          u"\u043d\u0438\u043a\r\n").encode('utf-8') 
    5253 
    53         self.ircUser.irc_NICK("", ["\xd0\xbd\xd0\xb8\xd0\xba"]) 
     54        self.ircUser.irc_NICK("", [u"\u043d\u0438\u043a".encode('utf-8')]) 
    5455        self.stringTransport.clear() 
    55         self.ircUser.sendMessage("\xd1\x82\xd0\xb5\xd1\x81\xd1\x82") 
     56        self.ircUser.sendMessage(u"\u0442\u0435\u0441\u0442".encode('utf-8')) 
    5657        self.assertEqual(self.stringTransport.value(), expectedResult) 
    5758 
    5859 
    59     def test_wrongUtf8Nick(self): 
     60    def test_invalidEncodingNick(self): 
    6061        """ 
    61         An C{Exception} is not raised when a NICK command is sent with a  
    62         non-UTF-8 nickname. 
     62        A NICK command sent with a nickname that cannot be decoded with the  
     63        current IRCUser's encoding results in a PRIVMSG from NickServ  
     64        indicating that the nickname could not be decoded. 
    6365        """ 
    64         expectedResult = (":NickServ!NickServ@services PRIVMSG " 
    65                           "\xd4\xc5\xd3\xd4 :Your nickname cannot be " 
    66                           "decoded. Please use ASCII or UTF-8.\r\n") 
     66        expectedResult = (b":NickServ!NickServ@services PRIVMSG " 
     67                          b"\xd4\xc5\xd3\xd4 :Your nickname cannot be " 
     68                          b"decoded. Please use ASCII or UTF-8.\r\n") 
    6769 
    68         self.ircUser.irc_NICK("", ["\xd4\xc5\xd3\xd4"]) 
     70        self.ircUser.irc_NICK("", [b"\xd4\xc5\xd3\xd4"]) 
    6971        self.assertEqual(self.stringTransport.value(), expectedResult) 
    7072 
    7173