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')