mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Filter: strip spaces in "unbinary" (Closes #1166)
This makes _squish() a shared function to prevent code duplication. Also, remove duplicate testUnbinary function, and add tests for this.
This commit is contained in:
parent
879ce460e9
commit
ed493e6504
@ -118,14 +118,16 @@ class Filter(callbacks.Plugin):
|
|||||||
irc.reply(self._hebrew_remover(text))
|
irc.reply(self._hebrew_remover(text))
|
||||||
hebrew = wrap(hebrew, ['text'])
|
hebrew = wrap(hebrew, ['text'])
|
||||||
|
|
||||||
|
def _squish(self, text):
|
||||||
|
return ''.join(text.split())
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def squish(self, irc, msg, args, text):
|
def squish(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Removes all the spaces from <text>.
|
Removes all the spaces from <text>.
|
||||||
"""
|
"""
|
||||||
text = ''.join(text.split())
|
irc.reply(self._squish(text))
|
||||||
irc.reply(text)
|
|
||||||
squish = wrap(squish, ['text'])
|
squish = wrap(squish, ['text'])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
@ -182,6 +184,7 @@ class Filter(callbacks.Plugin):
|
|||||||
Returns the character representation of binary <text>.
|
Returns the character representation of binary <text>.
|
||||||
Assumes ASCII, 8 digits per character.
|
Assumes ASCII, 8 digits per character.
|
||||||
"""
|
"""
|
||||||
|
text = self._squish(text) # Strip spaces.
|
||||||
try:
|
try:
|
||||||
L = [chr(int(text[i:(i+8)], 2)) for i in range(0, len(text), 8)]
|
L = [chr(int(text[i:(i+8)], 2)) for i in range(0, len(text), 8)]
|
||||||
irc.reply(''.join(L))
|
irc.reply(''.join(L))
|
||||||
|
@ -87,12 +87,10 @@ class FilterTest(ChannelPluginTestCase):
|
|||||||
def testBinary(self):
|
def testBinary(self):
|
||||||
self.assertResponse('binary A', '01000001')
|
self.assertResponse('binary A', '01000001')
|
||||||
|
|
||||||
def testUnbinary(self):
|
|
||||||
self.assertResponse('unbinary 011011010110111101101111', 'moo')
|
|
||||||
|
|
||||||
def testUnbinary(self):
|
def testUnbinary(self):
|
||||||
self.assertResponse('unbinary 011011010110111101101111', 'moo')
|
self.assertResponse('unbinary 011011010110111101101111', 'moo')
|
||||||
self.assertError('unbinary moo')
|
self.assertError('unbinary moo')
|
||||||
|
self.assertResponse('unbinary 01101101 01101111 01101111', 'moo')
|
||||||
|
|
||||||
def testRot13(self):
|
def testRot13(self):
|
||||||
for s in map(str, range(1000, 1010)):
|
for s in map(str, range(1000, 1010)):
|
||||||
|
Loading…
Reference in New Issue
Block a user