add base64 to text transformations

This commit is contained in:
Brian S. Stephan 2010-12-10 23:59:49 -06:00
parent da9e4b3142
commit 977675c593
1 changed files with 17 additions and 0 deletions

View File

@ -16,6 +16,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import base64
from extlib import irclib
from Module import Module
@ -35,6 +37,8 @@ class TextTransform(Module):
if self.rot13(what, reply):
return self.reply(connection, replypath, reply[0])
elif self.base64(what, reply):
return self.reply(connection, replypath, reply[0])
def rot13(self, what, reply):
"""
@ -46,5 +50,18 @@ class TextTransform(Module):
reply[0] = ' '.join(whats[1:]).encode('rot13', 'ignore')
return True
def base64(self, what, reply):
"""
Encode/decode base64 string.
"""
whats = what.split(' ')
if whats[0] == 'base64e' or whats[0] == 'base64':
reply[0] = base64.encodestring(' '.join(whats[1:]))
return True
if whats[0] == 'base64d':
reply[0] = base64.decodestring(' '.join(whats[1:]))
return True
# vi:tabstop=4:expandtab:autoindent
# kate: indent-mode python;indent-width 4;replace-tabs on;