Ticket #5780: 5780v2.patch

File 5780v2.patch, 2.2 KB (added by stephsolis, 15 months ago)

Addressed review suggestions

  • twisted/words/test/test_irc_service.py

     
    4242                          self.stringTransport.value()) 
    4343 
    4444 
     45    def test_utf8Messages(self): 
     46        """ 
     47        An C{Exception} is not raised when a UTF-8 nick is set and a UTF-8  
     48        message is sent. 
     49        """ 
     50        expectedResult = (":example.com \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 " 
     51                          "\xd0\xbd\xd0\xb8\xd0\xba\r\n") 
     52 
     53        self.ircUser.irc_NICK("", ["\xd0\xbd\xd0\xb8\xd0\xba"]) 
     54        self.stringTransport.clear() 
     55        self.ircUser.sendMessage("\xd1\x82\xd0\xb5\xd1\x81\xd1\x82") 
     56        self.assertEqual(self.stringTransport.value(), expectedResult) 
     57 
     58 
     59    def test_wrongUtf8Nick(self): 
     60        """ 
     61        An C{Exception} is not raised when a NICK command is sent with a  
     62        non-UTF-8 nickname. 
     63        """ 
     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") 
     67 
     68        self.ircUser.irc_NICK("", ["\xd4\xc5\xd3\xd4"]) 
     69        self.assertEqual(self.stringTransport.value(), expectedResult) 
     70 
     71 
    4572    def response(self): 
    4673        """ 
    4774        Grabs our responses and then clears the transport 
  • twisted/words/service.py

     
    289289 
    290290        [REQUIRED] 
    291291        """ 
     292        nickname = params[0] 
    292293        try: 
    293             nickname = params[0].decode(self.encoding) 
     294            nickname = nickname.decode(self.encoding) 
    294295        except UnicodeDecodeError: 
    295296            self.privmsg( 
    296297                NICKSERV, 
    297298                nickname, 
    298                 'Your nickname is cannot be decoded. Please use ASCII or UTF-8.') 
     299                'Your nickname cannot be decoded. Please use ASCII or UTF-8.') 
    299300            self.transport.loseConnection() 
    300301            return 
    301302