Popular recipes tagged "meta:requires=base64"http://code.activestate.com/recipes/tags/meta:requires=base64/2014-07-03T16:32:53-07:00ActiveState Code Recipescreate a unique session key (Python) 2014-07-03T16:32:53-07:00john stinsonhttp://code.activestate.com/recipes/users/4190325/http://code.activestate.com/recipes/578903-create-a-unique-session-key/ <p style="color: grey"> Python recipe 578903 by <a href="/recipes/users/4190325/">john stinson</a> (<a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/sessions/">sessions</a>). </p> <p>A simple function that will generate a secure and unique session key.</p> WebSocket interface (Python) 2012-11-25T16:52:21-08:00Nick Farohttp://code.activestate.com/recipes/users/4184363/http://code.activestate.com/recipes/578348-websocket-interface/ <p style="color: grey"> Python recipe 578348 by <a href="/recipes/users/4184363/">Nick Faro</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/socket/">socket</a>, <a href="/recipes/tags/websocket/">websocket</a>). Revision 2. </p> <p>This tries its best to be a replacement for the regular <code>socket</code> module.</p> <p>It supports only sending and receiving but should be useful enough.</p> <p>The only real difference should be that you can't specify the number of bytes is received, instead do</p> <pre class="prettyprint"><code>for message in socket.recv(): print(message) </code></pre> <p>Revision 2: Added proper message receiving. Previously it just requested a ton of data. Now it reads 2 bytes, determines the length, then requests that much.</p> Directory Pruner 4 (Python) 2012-06-06T22:00:00-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578154-directory-pruner-4/ <p style="color: grey"> Python recipe 578154 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). Revision 2. </p> <p>Module providing GUI capability to prune any directory.</p> <p>The code presented in this module is for the purposes of: (1) ascertaining the space taken up by a directory, its files, its sub-directories, and its sub-files; (2) allowing for the removal of the sub-files, sub-directories, files, and directory found in the first purpose; (3) giving the user a GUI to accomplish said purposes in a convenient way that is easily accessible.</p> Self-contained TWL06 Dictionary Module (515 KB) (Python) 2011-08-10T20:32:03-07:00Michael Foglemanhttp://code.activestate.com/recipes/users/4171845/http://code.activestate.com/recipes/577835-self-contained-twl06-dictionary-module-515-kb/ <p style="color: grey"> Python recipe 577835 by <a href="/recipes/users/4171845/">Michael Fogleman</a> (<a href="/recipes/tags/dawg/">dawg</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/scrabble/">scrabble</a>, <a href="/recipes/tags/trie/">trie</a>, <a href="/recipes/tags/twl06/">twl06</a>, <a href="/recipes/tags/word/">word</a>). Revision 4. </p> <p>A convenient, self-contained, 515 KB Scrabble dictionary module, ideal for use in word games.</p> <p>Functionality:</p> <ul> <li>Check if a word is in the dictionary.</li> <li>Enumerate all words in the dictionary.</li> <li>Determine what letters may appear after a given prefix.</li> <li>Determine what words can be formed by anagramming a set of letters.</li> </ul> <p>Sample usage:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; import twl &gt;&gt;&gt; twl.check('dog') True &gt;&gt;&gt; twl.check('dgo') False &gt;&gt;&gt; words = set(twl.iterator()) &gt;&gt;&gt; len(words) 178691 &gt;&gt;&gt; twl.children('dude') ['$', 'd', 'e', 's'] &gt;&gt;&gt; list(twl.anagram('top')) ['op', 'opt', 'pot', 'to', 'top'] </code></pre> Securely processing Twilio requests from Tornado (Python) 2011-10-05T15:29:44-07:00Jesse Davishttp://code.activestate.com/recipes/users/4175348/http://code.activestate.com/recipes/577893-securely-processing-twilio-requests-from-tornado/ <p style="color: grey"> Python recipe 577893 by <a href="/recipes/users/4175348/">Jesse Davis</a> (<a href="/recipes/tags/authentication/">authentication</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/https/">https</a>, <a href="/recipes/tags/nginx/">nginx</a>, <a href="/recipes/tags/telephony/">telephony</a>, <a href="/recipes/tags/tornado/">tornado</a>, <a href="/recipes/tags/twilio/">twilio</a>). </p> <p>Twilio is a telephony service that POSTs to a callback URL on your server and asks you what to do when it receives phone calls or SMSes to the numbers you rent from Twilio. But securing your communications with Twilio can be complex if you're using Tornado behind Nginx. This shows you how to protect your Twilio callback URL with HTTP Authentication, request-signing, and (optionally) SSL.</p> <p>I'm using HTTP Authentication code from Kevin Kelley, and I wrote the rest myself.</p> Directory Pruner 2 (Python) 2011-04-05T01:37:14-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577633-directory-pruner-2/ <p style="color: grey"> Python recipe 577633 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This program builds on work done in <a href="http://code.activestate.com/recipes/577632/">recipe 577632</a>, adds new options to the context menu, and experiments with threading the GUI. Directory Pruner 2 appear to work better on Windows 7 while Directory Pruner 1 (the non-threaded version) performs better on Windows XP. Those are the primary platforms on which the two programs have been tested. Please use these applications at your own risk.</p> <p>If you do not like something about this recipe and want to vote it down, please let everyone what you find fault with, how you would improve it, and an example of the code you would improve.</p> Directory Pruner 1 (Python) 2011-04-05T00:56:25-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577632-directory-pruner-1/ <p style="color: grey"> Python recipe 577632 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This program is an extension of <a href="http://code.activestate.com/recipes/577567/">recipe 577567</a> in that it not only allows one to find a directory's size but also remove files based on a context menu. The directory pruner has been used by my roommate to free up room on his hard drive and also by several friends that wished to remove games and other unnecessary program that were taking up their space. Right-click on found directories to review your options.</p> <p>If you wish to vote this recipe down, please post a comment at the bottom telling me how you would improve the utility.</p> Directory Pruner 3 (Python) 2011-04-05T23:15:58-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577635-directory-pruner-3/ <p style="color: grey"> Python recipe 577635 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>After considering the monolithic design of <a href="http://code.activestate.com/recipes/577633/">recipe 577633</a> and deciding that it should be divided into several smaller modules, Directory Pruner 3 was written to take advantage of better abstraction methodologies. There are a total of twelve files in the project, and all of them except the first are contained within a directory called "Directory Pruner 3" such that they make up a package in Python. Like the other Directory Pruners, please use and configure this program at your own computer's risk.</p> <p>If you have any comments or wish to vote this recipe down, please provide an explanation as to what you find fault with in this program and also a solution that you would implement to fix the problem.</p> Self Extracting Archiver (Python) 2012-06-20T22:32:01-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577485-self-extracting-archiver/ <p style="color: grey"> Python recipe 577485 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/python/">python</a>). Revision 6. </p> <p>This is a command-line tool for making self-extracting file archives in Python.</p> GAE User Session with HTTP Basic Authentication (Python) 2010-05-20T23:49:49-07:00Berendhttp://code.activestate.com/recipes/users/4173891/http://code.activestate.com/recipes/577235-gae-user-session-with-http-basic-authentication/ <p style="color: grey"> Python recipe 577235 by <a href="/recipes/users/4173891/">Berend</a> (<a href="/recipes/tags/appengine/">appengine</a>, <a href="/recipes/tags/appspot/">appspot</a>, <a href="/recipes/tags/authentication/">authentication</a>, <a href="/recipes/tags/clients/">clients</a>, <a href="/recipes/tags/gae/">gae</a>, <a href="/recipes/tags/google/">google</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sessions/">sessions</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). Revision 6. </p> <p>HTTP Basic is an unsecure but easy to implement authentication protocol. I think its good enough for a simple client in front of an SSL capable server. Google App-Engine supports SSL, and here is a recipe to set up the user-session using HTTP Basic. </p> <p>gauth has the code from my not-really-a-recipe listing at: <a href="http://code.activestate.com/recipes/577217-routines-for-programmatically-authenticating-with-" rel="nofollow">http://code.activestate.com/recipes/577217-routines-for-programmatically-authenticating-with-</a></p> SimpleCryptSocketExt - SimpleCrypt Wrapper for Easy Socket, Client / Server Encryption (Python) 2010-05-07T15:33:06-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577212-simplecryptsocketext-simplecrypt-wrapper-for-easy-/ <p style="color: grey"> Python recipe 577212 by <a href="/recipes/users/4173476/">AJ. Mayorga</a> (<a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/cryptography/">cryptography</a>, <a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/server/">server</a>, <a href="/recipes/tags/socket/">socket</a>). Revision 5. </p> <p>Lightweight drop-in encryption wrapper for various Client/Server solutions supporting protocols such as UDP, TCP, HTTP, HTTPS, FTP, RAW Sockets etc.</p> wsgi SPNEGO middleware (Python) 2009-12-28T09:36:18-08:00Sven Ludwighttp://code.activestate.com/recipes/users/4172687/http://code.activestate.com/recipes/576992-wsgi-spnego-middleware/ <p style="color: grey"> Python recipe 576992 by <a href="/recipes/users/4172687/">Sven Ludwig</a> (<a href="/recipes/tags/kerberos/">kerberos</a>, <a href="/recipes/tags/spnego/">spnego</a>, <a href="/recipes/tags/wsgi/">wsgi</a>, <a href="/recipes/tags/wsgi_middleware/">wsgi_middleware</a>). </p> <p>Kerberos Single Sign On wsgi middleware</p> pseudo-random string (Python) 2009-04-21T18:56:01-07:00Patrick Ramseyhttp://code.activestate.com/recipes/users/4169944/http://code.activestate.com/recipes/576722-pseudo-random-string/ <p style="color: grey"> Python recipe 576722 by <a href="/recipes/users/4169944/">Patrick Ramsey</a> (<a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/string/">string</a>). Revision 3. </p> <p>Returns a random, password-suitable string with the specified number of characters. base64 stores 6 bits in each (8-bit) output character, hence the coefficient.</p> using xmlrpc with authenticated proxy server (Python) 2007-07-03T23:42:04-07:00Vaibhav Bhatiahttp://code.activestate.com/recipes/users/4007166/http://code.activestate.com/recipes/523016-using-xmlrpc-with-authenticated-proxy-server/ <p style="color: grey"> Python recipe 523016 by <a href="/recipes/users/4007166/">Vaibhav Bhatia</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>To access an XML-RPC server through a proxy which requires authentication, you need to define a custom transport. the custom transport mentioned in the python docs, allows only proxy server's which do not require authentication. (<a href="http://docs.python.org/lib/xmlrpc-client-example.html" rel="nofollow">http://docs.python.org/lib/xmlrpc-client-example.html</a>). Have tried to use urllib which has support for proxy server and added the headers required for authentication. Idea to use urllib was taken from this thread (<a href="http://mail.python.org/pipermail/python-list/2001-July/098183.html%29" rel="nofollow">http://mail.python.org/pipermail/python-list/2001-July/098183.html)</a></p> simple crawler using twisted (Python) 2007-08-01T05:12:59-07:00Vaibhav Bhatiahttp://code.activestate.com/recipes/users/4007166/http://code.activestate.com/recipes/525493-simple-crawler-using-twisted/ <p style="color: grey"> Python recipe 525493 by <a href="/recipes/users/4007166/">Vaibhav Bhatia</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>a simple recipe which can be used to download a webpage using twisted. Created this while going through the twisted documentation. supports the following : - basic authentication - check whether the page is updated - progress bar</p> xmlrpc server/client which does cookie handling and supports basic authentication (Python) 2007-01-23T10:51:39-08:00Vaibhav Bhatiahttp://code.activestate.com/recipes/users/4007166/http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/ <p style="color: grey"> Python recipe 501148 by <a href="/recipes/users/4007166/">Vaibhav Bhatia</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>xmlrpc server client which do the following: * client sends a request with basic authentication * server on successful authentication sends response back and also sends cookies with authentication id * these cookies are saved by client and then used for authentication on any subsequent requests</p> Obtain encoded string representations of images, for use in your apps (Python) 2006-04-03T18:15:55-07:00stewart midwinterhttp://code.activestate.com/recipes/users/970057/http://code.activestate.com/recipes/476223-obtain-encoded-string-representations-of-images-fo/ <p style="color: grey"> Python recipe 476223 by <a href="/recipes/users/970057/">stewart midwinter</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>Say you want to generate a default image with my app without having to include an image file with my app. You'll want to encode the binary image data as text, using base64. This image can later be displayed in my app, or a binary image file can be written by decoding the encoded text string using the base64 module. To make this task a little easier for you, I created a small GUI app using Wax. Simply run the app, select the image file you want converted, then copy the encoded text string and paste it into your app (which could be a Wax, wxPython, Qt or even Tkinter app). The last part of the recipe shows you how to decode that text string back to binary data.</p> Authenticate with twisted.web.xmlrpc (Python) 2006-09-05T18:09:47-07:00Duncan McGreggorhttp://code.activestate.com/recipes/users/1923213/http://code.activestate.com/recipes/473865-authenticate-with-twistedwebxmlrpc/ <p style="color: grey"> Python recipe 473865 by <a href="/recipes/users/1923213/">Duncan McGreggor</a> (<a href="/recipes/tags/network/">network</a>). Revision 2. </p> <p>These classes subclass several of the culprits in twisted.web.xmlrpc that are responsible for not being able to make autenticated XML-RPC calls.</p> <p>Note that this recipe also makes use of the URI classes that were posted in a previous recipe here: <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473864" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473864</a></p> <p>I will submit a patch to twisted along these lines, but there will be no references to the custom Uri module or code.</p> <p>Update: XML-RPC Authentication is now supported in Twisted (version 2.4 included a patch based on this recipe). If you are using a recent version of Twisted or can update to a recent version, this recipe is no longer needed.</p> EAN Bar code image generator (Python) 2005-06-18T04:07:13-07:00remi inconnuhttp://code.activestate.com/recipes/users/832244/http://code.activestate.com/recipes/426069-ean-bar-code-image-generator/ <p style="color: grey"> Python recipe 426069 by <a href="/recipes/users/832244/">remi inconnu</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>This class generate EAN bar code, it required PIL (python imaging library) installed.</p> <p>If the code has not checksum (12 digits), it added automatically.</p> <p>Create bar code sample : from EANBarCode import EanBarCode bar = EanBarCode() bar.getImage("9782212110708",50,"gif")</p> simplest useful HTTPS with basic proxy authentication (Python) 2005-12-28T17:27:47-08:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/301740-simplest-useful-https-with-basic-proxy-authenticat/ <p style="color: grey"> Python recipe 301740 by <a href="/recipes/users/135654/">John Nielsen</a> (<a href="/recipes/tags/network/">network</a>). Revision 4. </p> <p>This is just about the most simple snippet of how to do proxy authentication with SSL using python. The current httplib only supports ssl through a proxy _without_ authentication. This example does basic proxy auth that a lot of proxy servers can support. This will at least give someone an idea of how to do it and then improve it and incorporate it however they want.</p>