<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>pnotepad.org forums Topic: PyPn script: Base64 encode/decode</title>
		<link>http://pnotepad.org/forums/topic/572</link>
		<description>Programmer&#039;s Notepad Forums</description>
		<language>en-US</language>
		<pubDate>Sat, 13 Mar 2010 17:14:41 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://pnotepad.org/forums/search.php</link>
		</textInput>
		<atom:link href="http://pnotepad.org/forums/rss/topic/572" rel="self" type="application/rss+xml" />

		<item>
			<title>simon on "PyPn script: Base64 encode/decode"</title>
			<link>http://pnotepad.org/forums/topic/572#post-1994</link>
			<pubDate>Tue, 28 Apr 2009 09:18:20 +0000</pubDate>
			<dc:creator>simon</dc:creator>
			<guid isPermaLink="false">1994@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;Nice :) Particularly like using a script to fix the bad forums encoding - good work!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>NickDMax on "PyPn script: Base64 encode/decode"</title>
			<link>http://pnotepad.org/forums/topic/572#post-1990</link>
			<pubDate>Tue, 28 Apr 2009 08:10:13 +0000</pubDate>
			<dc:creator>NickDMax</dc:creator>
			<guid isPermaLink="false">1990@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;note, you can use my other snippet to fix those &#60;code&#62;&#38;quote;&#60;/code&#62; lines. Just use the XML UnEscape method.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>NickDMax on "PyPn script: Base64 encode/decode"</title>
			<link>http://pnotepad.org/forums/topic/572#post-1989</link>
			<pubDate>Tue, 28 Apr 2009 08:08:31 +0000</pubDate>
			<dc:creator>NickDMax</dc:creator>
			<guid isPermaLink="false">1989@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;It comes up that you have some base64 encoded info and you want to know what it is... or perhaps you need to send a semi-private email, or just want to base64 encode something to be cool. Who knows why we do the things we do?&#60;/p&#62;
&#60;p&#62;These little methods will grab the current selection and clipboard it into a new document after base64 encoding or decoding it. Note that the decoding is dumb and will not check that the decoded text is ok to paste into a PN document (i.e. it may very well crash PN -- has not done it to me yet, but I have not been testing with binary files).&#60;/p&#62;
&#60;p&#62;base64utils.py:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;###############################################################################
## base64Utils.py -- PyPn utility script to encode and decode base64.
## tested on Python 2.6.1. This utility will take the current selection
## (or document if there is no selection) and create a base 64 encoded document
## It will also take a base 64 encoded document and return the unencoded text.
## -- Note: No verification is done to ensure that the unencoded data is
## ASCII or valid unicode textual data.
## By: NickDMax

import pn
import scintilla
from pypn.decorators import script
import base64

@script(&#38;amp;quot;Base64Encode&#38;amp;quot;, &#38;amp;quot;DocUtils&#38;amp;quot;)
def doBase64():
    &#38;amp;quot;&#38;amp;quot;&#38;amp;quot; This method will grab the curent selection/document and
        create a new document that is a base64 vesion of the text &#38;amp;quot;&#38;amp;quot;&#38;amp;quot;
    doc = pn.CurrentDoc()
    if doc is not None:     #Lets try not to crash pn too often...
        editor = scintilla.Scintilla(pn.CurrentDoc())
        start = editor.SelectionStart
        end = editor.SelectionEnd
        if (start == end):  #nothing is selected so we will just grab it all...
            start = 0
            end = editor.Length
        text = editor.GetTextRange(start, end)
        newDoc = pn.NewDocument(None)
        newEditor = scintilla.Scintilla(newDoc)
        newEditor.BeginUndoAction()
        encoded = base64.b64encode(text)
        l = len (encoded)
        m = 0
        while l &#38;gt; 80:
            str = encoded[m:m+80] + &#38;#39;\n&#38;#39;
            newEditor.AppendText(len(str), str)
            l, m = l - 80, m + 80
        str = encoded[m:m+l]
        newEditor.AppendText(len(str), str)
        newEditor.EndUndoAction()
    pass

@script(&#38;amp;quot;DecodeBase64&#38;amp;quot;, &#38;amp;quot;DocUtils&#38;amp;quot;)
def undoBase64():
    &#38;amp;quot;&#38;amp;quot;&#38;amp;quot; This method will grab the curent selection/document and
        create a new document that is the base64 decoded vesion
        of the text &#38;amp;quot;&#38;amp;quot;&#38;amp;quot;
    doc = pn.CurrentDoc()
    if doc is not None:     #Lets try not to crash pn too often...
        editor = scintilla.Scintilla(pn.CurrentDoc())
        start = editor.SelectionStart
        end = editor.SelectionEnd
        if (start == end):  #nothing is selected so we will just grab it all...
            start = 0
            end = editor.Length
        text = editor.GetTextRange(start, end)
        newDoc = pn.NewDocument(None)
        newEditor = scintilla.Scintilla(newDoc)
        newEditor.BeginUndoAction()
        decoded = base64.b64decode(text)
        newEditor.AppendText(len(decoded), decoded)
        newEditor.EndUndoAction()
    pass&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
