mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Filter: Use the 'codecs' module instead of .encode and .decode.
This commit is contained in:
parent
9dcfce01c7
commit
a89ff32297
@ -29,6 +29,7 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import codecs
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
@ -102,6 +103,7 @@ class Filter(callbacks.Plugin):
|
|||||||
[('checkChannelCapability', 'op'),
|
[('checkChannelCapability', 'op'),
|
||||||
additional('commandName')])
|
additional('commandName')])
|
||||||
|
|
||||||
|
_hebrew_remover = utils.str.MultipleRemover('aeiou')
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def hebrew(self, irc, msg, args, text):
|
def hebrew(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
@ -110,8 +112,7 @@ class Filter(callbacks.Plugin):
|
|||||||
named 'hebrew' it's because I (jemfinch) thought of it in Hebrew class,
|
named 'hebrew' it's because I (jemfinch) thought of it in Hebrew class,
|
||||||
and printed Hebrew often elides the vowels.)
|
and printed Hebrew often elides the vowels.)
|
||||||
"""
|
"""
|
||||||
text = filter(lambda c: c not in 'aeiou', text)
|
irc.reply(self._hebrew_remover(text))
|
||||||
irc.reply(text)
|
|
||||||
hebrew = wrap(hebrew, ['text'])
|
hebrew = wrap(hebrew, ['text'])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
@ -174,6 +175,7 @@ class Filter(callbacks.Plugin):
|
|||||||
irc.reply(''.join(L))
|
irc.reply(''.join(L))
|
||||||
unbinary = wrap(unbinary, ['text'])
|
unbinary = wrap(unbinary, ['text'])
|
||||||
|
|
||||||
|
_hex_encoder = staticmethod(codecs.getencoder('hex_codec'))
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def hexlify(self, irc, msg, args, text):
|
def hexlify(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
@ -181,9 +183,10 @@ class Filter(callbacks.Plugin):
|
|||||||
Returns a hexstring from the given string; a hexstring is a string
|
Returns a hexstring from the given string; a hexstring is a string
|
||||||
composed of the hexadecimal value of each character in the string
|
composed of the hexadecimal value of each character in the string
|
||||||
"""
|
"""
|
||||||
irc.reply(text.encode('hex_codec'))
|
irc.reply(self._hex_encoder(text.encode('utf8'))[0].decode('utf8'))
|
||||||
hexlify = wrap(hexlify, ['text'])
|
hexlify = wrap(hexlify, ['text'])
|
||||||
|
|
||||||
|
_hex_decoder = staticmethod(codecs.getdecoder('hex_codec'))
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def unhexlify(self, irc, msg, args, text):
|
def unhexlify(self, irc, msg, args, text):
|
||||||
"""<hexstring>
|
"""<hexstring>
|
||||||
@ -192,11 +195,12 @@ class Filter(callbacks.Plugin):
|
|||||||
<hexstring> must be a string of hexadecimal digits.
|
<hexstring> must be a string of hexadecimal digits.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
irc.reply(text.decode('hex_codec'))
|
irc.reply(self._hex_decoder(text.encode('utf8'))[0].decode('utf8'))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
irc.error(_('Invalid input.'))
|
irc.error(_('Invalid input.'))
|
||||||
unhexlify = wrap(unhexlify, ['text'])
|
unhexlify = wrap(unhexlify, ['text'])
|
||||||
|
|
||||||
|
_rot13_encoder = codecs.getencoder('rot-13')
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def rot13(self, irc, msg, args, text):
|
def rot13(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
@ -205,7 +209,7 @@ class Filter(callbacks.Plugin):
|
|||||||
commonly used for text that simply needs to be hidden from inadvertent
|
commonly used for text that simply needs to be hidden from inadvertent
|
||||||
reading by roaming eyes, since it's easily reversible.
|
reading by roaming eyes, since it's easily reversible.
|
||||||
"""
|
"""
|
||||||
irc.reply(text.encode('rot13'))
|
irc.reply(self._rot13_encoder(text)[0])
|
||||||
rot13 = wrap(rot13, ['text'])
|
rot13 = wrap(rot13, ['text'])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import codecs
|
||||||
|
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
@ -134,8 +135,9 @@ class FilterTest(ChannelPluginTestCase):
|
|||||||
self.assertResponse('spellit asasdfasdf12345@#$!%^',
|
self.assertResponse('spellit asasdfasdf12345@#$!%^',
|
||||||
'asasdfasdf12345@#$!%^')
|
'asasdfasdf12345@#$!%^')
|
||||||
|
|
||||||
|
_rot13_encoder = codecs.getencoder('rot-13')
|
||||||
def testOutfilter(self):
|
def testOutfilter(self):
|
||||||
s = self.nick.encode('rot13')
|
s = self._rot13_encoder(self.nick)[0]
|
||||||
self.assertNotError('outfilter rot13')
|
self.assertNotError('outfilter rot13')
|
||||||
self.assertResponse('rot13 foobar', '%s: foobar' % s)
|
self.assertResponse('rot13 foobar', '%s: foobar' % s)
|
||||||
self.assertNotError('outfilter rot13')
|
self.assertNotError('outfilter rot13')
|
||||||
@ -148,7 +150,7 @@ class FilterTest(ChannelPluginTestCase):
|
|||||||
self.assertResponse('rot13 foobar', 'sbbone')
|
self.assertResponse('rot13 foobar', 'sbbone')
|
||||||
|
|
||||||
def testOutfilterAction(self):
|
def testOutfilterAction(self):
|
||||||
s = self.nick.encode('rot13')
|
s = self._rot13_encoder(self.nick)[0]
|
||||||
self.assertNotError('outfilter rot13')
|
self.assertNotError('outfilter rot13')
|
||||||
self.assertResponse('rot13 foobar', '%s: foobar' % s)
|
self.assertResponse('rot13 foobar', '%s: foobar' % s)
|
||||||
m = self.getMsg('action foobar')
|
m = self.getMsg('action foobar')
|
||||||
|
Loading…
Reference in New Issue
Block a user