String: Give a more useful message when decoding base64 fails

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
James Vega 2009-04-06 11:26:15 -04:00
parent dfbec681d1
commit ebfe8e66f3
2 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,6 @@
### ###
# Copyright (c) 2003-2005, Jeremiah Fincher # Copyright (c) 2003-2005, Jeremiah Fincher
# Copyright (c) 2008, James Vega # Copyright (c) 2008-2009, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -29,6 +29,7 @@
### ###
import types import types
import binascii
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
@ -81,6 +82,10 @@ class String(callbacks.Plugin):
irc.reply(text.decode(encoding).encode('utf-8')) irc.reply(text.decode(encoding).encode('utf-8'))
except LookupError: except LookupError:
irc.errorInvalid('encoding', encoding) irc.errorInvalid('encoding', encoding)
except binascii.Error:
irc.errorInvalid('base64 string',
s='Base64 strings must be a multiple of 4 in '
'length, padded with \'=\' if necessary.')
decode = wrap(decode, ['something', 'text']) decode = wrap(decode, ['something', 'text'])
def levenshtein(self, irc, msg, args, s1, s2): def levenshtein(self, irc, msg, args, s1, s2):

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2003-2005, Jeremiah Fincher # Copyright (c) 2003-2005, Jeremiah Fincher
# Copyright (c) 2009, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -104,6 +105,7 @@ class StringTestCase(PluginTestCase):
self.assertNotRegexp('encode aldkfja foobar', 'LookupError') self.assertNotRegexp('encode aldkfja foobar', 'LookupError')
self.assertNotRegexp('decode asdflkj foobar', 'LookupError') self.assertNotRegexp('decode asdflkj foobar', 'LookupError')
self.assertResponse('decode zlib [encode zlib %s]' % s, s) self.assertResponse('decode zlib [encode zlib %s]' % s, s)
self.assertRegexp('decode base64 $BCfBg7;9D;R(B', 'padded with')
def testRe(self): def testRe(self):
self.assertResponse('re "m/system time/" [status cpu]', 'system time') self.assertResponse('re "m/system time/" [status cpu]', 'system time')