"""
Base64_Decode.py - A Jython macro for jEdit that decodes
a buffer, or selections in a buffer, enocded in base64..

Copyright 2003 (C) Ollie Rutherfurd <oliver@rutherfurd.net>

$Id: Base64_Decode.py 28 2003-03-25 22:40:28Z oliver $
"""

import base64

def base64decode(textArea):
	textArea.getBuffer().beginCompoundEdit()
	try:
		selections = textArea.getSelection()
		if len(selections) == 0:
			textArea.setText(base64.decodestring(textArea.getText()))
		else:
			for i in range(len(selections), 0, -1):
				selection = selections[i-1]
				start,end = selection.getStart(), selection.getEnd()
				text = textArea.getText(start, end-start)
				textArea.getBuffer().remove(start, end-start)
				textArea.getBuffer().insert(start, base64.decodestring(text))
	finally:
		textArea.getBuffer().endCompoundEdit()

if __name__ in ('__main__','main'):
	base64decode(init.textArea)

# :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:

