Caught the LookupError raised from a bad encoding.

This commit is contained in:
Jeremy Fincher 2003-11-17 23:10:14 +00:00
parent d7e95f5e87
commit 2cbcddb582
2 changed files with 14 additions and 2 deletions

View File

@ -197,7 +197,10 @@ class Fun(callbacks.Privmsg):
<http://www.python.org/doc/lib/node126.html>. <http://www.python.org/doc/lib/node126.html>.
""" """
encoding, text = privmsgs.getArgs(args, required=2) 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): def decode(self, irc, msg, args):
"""<encoding> <text> """<encoding> <text>
@ -207,7 +210,10 @@ class Fun(callbacks.Privmsg):
<http://www.python.org/doc/lib/node126.html>. <http://www.python.org/doc/lib/node126.html>.
""" """
encoding, text = privmsgs.getArgs(args, required=2) 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): def hexlify(self, irc, msg, args):
"""<text> """<text>

View File

@ -108,6 +108,12 @@ class FunTest(ChannelPluginTestCase, PluginDocumentation):
self.assertNotRegexp('colorize foobar', r'\s+') self.assertNotRegexp('colorize foobar', r'\s+')
self.assertRegexp('colorize foobar', r'\x03') 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): def testoutfilter(self):
s = self.nick.encode('rot13') s = self.nick.encode('rot13')
self.assertNotError('outfilter rot13') self.assertNotError('outfilter rot13')