Filter: add unbinary command, as counterpart to binary command.

This commit is contained in:
Daniel Folkinshteyn 2010-07-01 15:44:53 -04:00
parent 0781ff339e
commit 67a41f6626
2 changed files with 13 additions and 0 deletions

View File

@ -156,6 +156,16 @@ class Filter(callbacks.Plugin):
irc.reply(''.join(L))
binary = wrap(binary, ['text'])
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))
unbinary = wrap(unbinary, ['text'])
def hexlify(self, irc, msg, args, text):
"""<text>

View File

@ -86,6 +86,9 @@ class FilterTest(ChannelPluginTestCase):
def testBinary(self):
self.assertResponse('binary A', '01000001')
def testUnbinary(self):
self.assertResponse('unbinary 011011010110111101101111', 'moo')
def testRot13(self):
for s in map(str, range(1000, 1010)):