mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Caught the LookupError raised from a bad encoding.
This commit is contained in:
parent
d7e95f5e87
commit
2cbcddb582
@ -197,7 +197,10 @@ class Fun(callbacks.Privmsg):
|
||||
<http://www.python.org/doc/lib/node126.html>.
|
||||
"""
|
||||
encoding, text = privmsgs.getArgs(args, required=2)
|
||||
irc.reply(msg, text.encode(encoding))
|
||||
try:
|
||||
irc.reply(msg, text.encode(encoding))
|
||||
except LookupError:
|
||||
irc.error(msg, 'There is no such encoding %r' % encoding)
|
||||
|
||||
def decode(self, irc, msg, args):
|
||||
"""<encoding> <text>
|
||||
@ -207,7 +210,10 @@ class Fun(callbacks.Privmsg):
|
||||
<http://www.python.org/doc/lib/node126.html>.
|
||||
"""
|
||||
encoding, text = privmsgs.getArgs(args, required=2)
|
||||
irc.reply(msg, text.decode(encoding).encode('utf-8'))
|
||||
try:
|
||||
irc.reply(msg, text.decode(encoding).encode('utf-8'))
|
||||
except LookupError:
|
||||
irc.error(msg, 'There is no such encoding %r' % encoding)
|
||||
|
||||
def hexlify(self, irc, msg, args):
|
||||
"""<text>
|
||||
|
@ -108,6 +108,12 @@ class FunTest(ChannelPluginTestCase, PluginDocumentation):
|
||||
self.assertNotRegexp('colorize foobar', r'\s+')
|
||||
self.assertRegexp('colorize foobar', r'\x03')
|
||||
|
||||
def testEncodeDecode(self):
|
||||
s = 'the recalcitrant jamessan tests his scramble function'
|
||||
self.assertNotRegexp('encode aldkfja foobar', 'LookupError')
|
||||
self.assertNotRegexp('decode asdflkj foobar', 'LookupError')
|
||||
self.assertResponse('decode zlib [encode zlib %s]' % s, s)
|
||||
|
||||
def testoutfilter(self):
|
||||
s = self.nick.encode('rot13')
|
||||
self.assertNotError('outfilter rot13')
|
||||
|
Loading…
Reference in New Issue
Block a user