NoLatin1: enhance testNoWarningOnUnicode and fix detection.

master
Valentin Lorentz 2011-03-10 15:23:35 +01:00
parent 639a8866be
commit f3f577f025
2 changed files with 10 additions and 4 deletions

View File

@ -29,6 +29,7 @@
###
import time
import chardet
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
@ -51,9 +52,8 @@ class NoLatin1(callbacks.Plugin):
content = msg.args[1]
if not self.registryValue('enable', channel):
return
try:
unicode(content, errors='strict')
except UnicodeDecodeError:
encoding = chardet.detect(content)['encoding']
if encoding not in ('utf-8', 'ascii'):
self._warn(irc, channel, msg.prefix.split('!')[0])
def _warn(self, irc, channel, nick):

View File

@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
###
# Copyright (c) 2011, Valentin Lorentz
# All rights reserved.
@ -46,7 +47,12 @@ class NoLatin1TestCase(ChannelPluginTestCase):
def testNoWarningOnUnicode(self):
msg = ircmsgs.privmsg(self.channel, 'Hi !', prefix=self.prefix)
self.irc.feedMsg(msg)
assert self.irc.takeMsg() is None
msg = self.irc.takeMsg()
assert msg is None, msg
msg = ircmsgs.privmsg(self.channel, 'é', prefix=self.prefix)
self.irc.feedMsg(msg)
msg = self.irc.takeMsg()
assert msg is None, msg
def testCleanUp(self):
for foo in range(0, 4):