From ed493e6504268e4405f31d03f5c1dfa505b4cde8 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 9 Sep 2015 19:32:15 -0700 Subject: [PATCH 1/2] 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. --- plugins/Filter/plugin.py | 7 +++++-- plugins/Filter/test.py | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index b13cf672a..9c5e459b7 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -118,14 +118,16 @@ class Filter(callbacks.Plugin): irc.reply(self._hebrew_remover(text)) hebrew = wrap(hebrew, ['text']) + def _squish(self, text): + return ''.join(text.split()) + @internationalizeDocstring def squish(self, irc, msg, args, text): """ Removes all the spaces from . """ - text = ''.join(text.split()) - irc.reply(text) + irc.reply(self._squish(text)) squish = wrap(squish, ['text']) @internationalizeDocstring @@ -182,6 +184,7 @@ class Filter(callbacks.Plugin): Returns the character representation of binary . Assumes ASCII, 8 digits per character. """ + text = self._squish(text) # Strip spaces. try: L = [chr(int(text[i:(i+8)], 2)) for i in range(0, len(text), 8)] irc.reply(''.join(L)) diff --git a/plugins/Filter/test.py b/plugins/Filter/test.py index bdd7957e8..9bc715dd0 100644 --- a/plugins/Filter/test.py +++ b/plugins/Filter/test.py @@ -86,13 +86,11 @@ class FilterTest(ChannelPluginTestCase): def testBinary(self): self.assertResponse('binary A', '01000001') - - def testUnbinary(self): - self.assertResponse('unbinary 011011010110111101101111', 'moo') def testUnbinary(self): self.assertResponse('unbinary 011011010110111101101111', 'moo') self.assertError('unbinary moo') + self.assertResponse('unbinary 01101101 01101111 01101111', 'moo') def testRot13(self): for s in map(str, range(1000, 1010)): From f5146e8af44cc2eb67598abfda1d015eb3433f41 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 10 Sep 2015 06:57:40 -0700 Subject: [PATCH 2/2] Filter: more efficient _squish code --- plugins/Filter/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index 9c5e459b7..bad45fa6d 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -119,7 +119,7 @@ class Filter(callbacks.Plugin): hebrew = wrap(hebrew, ['text']) def _squish(self, text): - return ''.join(text.split()) + return text.replace(' ', '') @internationalizeDocstring def squish(self, irc, msg, args, text):