Filter: catch invalid input for unbinary command.

Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
Daniel Folkinshteyn 2010-07-21 12:57:18 -04:00 committed by James McCoy
parent 7feb50685a
commit 84b878b10e
2 changed files with 7 additions and 3 deletions

View File

@ -158,12 +158,15 @@ class Filter(callbacks.Plugin):
def unbinary(self, irc, msg, args, text):
"""<text>
Returns the character representation of binary <text>.
Assumes ASCII, 8 digits per character.
"""
L = [chr(int(text[i:(i+8)], 2)) for i in xrange(0, len(text), 8)]
irc.reply(''.join(L))
try:
L = [chr(int(text[i:(i+8)], 2)) for i in xrange(0, len(text), 8)]
irc.reply(''.join(L))
except ValueError:
irc.errorInvalid('binary string', text)
unbinary = wrap(unbinary, ['text'])
def hexlify(self, irc, msg, args, text):

View File

@ -89,6 +89,7 @@ class FilterTest(ChannelPluginTestCase):
def testUnbinary(self):
self.assertResponse('unbinary 011011010110111101101111', 'moo')
self.assertError('unbinary moo')
def testRot13(self):
for s in map(str, range(1000, 1010)):