def __init__(self, connection, user, channel, msg, method='privmsg', privileged_channels=[], **kwargs): self.my_nick = connection.nickname self.chanmodes = connection.chanmodes self.user = user if '!' in user: self.nick, self.mask = user.split('!', 1) else: # pragma: nocover self.nick, self.mask = user, None self.channel = force_unicode(channel) self.privileged_channels = [force_unicode(x, encodings=['utf-8']) for x in privileged_channels] self.message = force_unicode(msg) self.method = method.upper() self.context = kwargs self.addressee = '' if self.channel == self.my_nick: self.addressed = True self.reply_recipient = self.nick elif self.message.lower().startswith(self.my_nick.lower()): self.addressed = True self.reply_recipient = self.channel self.addressee = self.nick else: self.addressed = False self.reply_recipient = self.channel
def __init__(self, recipient, data, method='PRIVMSG', **kwargs): self.recipient = force_unicode(recipient) self.data = force_unicode(data) self.method = method self.context = kwargs if 'responses' in kwargs: self.responses = kwargs['responses']
def test_conversion(self): self.assertEqual( encoding.force_unicode("\xC6", encodings=self.std_enc), "\xc3\x86".decode('utf-8')) self.assertRaises(DjangoUnicodeDecodeError, encoding.force_unicode, "\x9D", encodings=self.std_enc)
def test_unicode_object(self): # Passing a unicode object should return it unchanged snowman = "\xe2\x98\x83".decode('utf-8') self.assertEqual( encoding.force_unicode(snowman, encodings=['ascii']), snowman)
def test_ruscii(self): # Now let's try some ruscii self.assertEqual( encoding.force_unicode("\xf2", encodings=['koi8_r']), "\xd0\xa0".decode('utf-8'))
def test_cp1252_latin9_equal(self): # CP1252 and ISO8859-1 on the other hand are identical here self.assertEqual( encoding.force_unicode("\xA4", encodings=self.std_enc), encoding.force_unicode("\xA4", encodings=['iso8859-1']))
def test_cp1252_latin9_differ(self): # CP1252 and ISO8859-15 differ slightly self.assertNotEqual( encoding.force_unicode("\xA4", encodings=self.std_enc), encoding.force_unicode("\xA4", encodings=['iso8859-15']))
def test_conversion(self): self.assertEqual(encoding.force_unicode( "\xC6", encodings=self.std_enc), "\xc3\x86".decode('utf-8')) self.assertRaises(DjangoUnicodeDecodeError, encoding.force_unicode, "\x9D", encodings=self.std_enc)
def test_ascii_unchanged(self): self.assertEqual(encoding.force_unicode( "abc", encodings=self.std_enc), u'abc')
def test_unicode_object(self): # Passing a unicode object should return it unchanged snowman = "\xe2\x98\x83".decode('utf-8') self.assertEqual(encoding.force_unicode(snowman, encodings=['ascii']), snowman)
def test_ruscii(self): # Now let's try some ruscii self.assertEqual(encoding.force_unicode("\xf2", encodings=['koi8_r']), "\xd0\xa0".decode('utf-8'))
def test_ascii_unchanged(self): self.assertEqual(encoding.force_unicode("abc", encodings=self.std_enc), u'abc')