From 2cbcddb58269d659f689faf36652b2e37c1960c8 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 17 Nov 2003 23:10:14 +0000 Subject: [PATCH] Caught the LookupError raised from a bad encoding. --- plugins/Fun.py | 10 ++++++++-- test/test_Fun.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/Fun.py b/plugins/Fun.py index d566290ca..e60c9e399 100644 --- a/plugins/Fun.py +++ b/plugins/Fun.py @@ -197,7 +197,10 @@ class Fun(callbacks.Privmsg): . """ 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): """ @@ -207,7 +210,10 @@ class Fun(callbacks.Privmsg): . """ 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): """ diff --git a/test/test_Fun.py b/test/test_Fun.py index fd55cc2a3..cf3cf85c6 100644 --- a/test/test_Fun.py +++ b/test/test_Fun.py @@ -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')