Latest recipes tagged "wsgi"http://code.activestate.com/recipes/tags/wsgi/new/2013-12-26T18:45:35-08:00ActiveState Code RecipesA basic WSGI PDF server (Python) 2013-12-26T18:45:35-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578798-a-basic-wsgi-pdf-server/ <p style="color: grey"> Python recipe 578798 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/wsgi/">wsgi</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create a rudimentary Python WSGI server that can serve PDF. I had seen a post on the Python Reddit about how to create 'a basic WSGI server (aka "enough to make a website without using a framework")'. Thought of modifying it to serve PDF content (hard-ccded, though, not dynamic content, just as a basic example). This is the result. It's meant for learning, as was the original from which it was adapted, not for production use. It requires my xtopdf toolkit and the Reportlab toolkit, v1.21</p> Distributed lock manager for Python (Python) 2012-07-04T21:03:32-07:00pavelhttp://code.activestate.com/recipes/users/4171837/http://code.activestate.com/recipes/578194-distributed-lock-manager-for-python/ <p style="color: grey"> Python recipe 578194 by <a href="/recipes/users/4171837/">pavel</a> (<a href="/recipes/tags/distributed/">distributed</a>, <a href="/recipes/tags/lock/">lock</a>, <a href="/recipes/tags/locking/">locking</a>, <a href="/recipes/tags/locks/">locks</a>, <a href="/recipes/tags/manager/">manager</a>, <a href="/recipes/tags/socket/">socket</a>, <a href="/recipes/tags/thread/">thread</a>, <a href="/recipes/tags/threading/">threading</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). Revision 2. </p> <p>Distributed lock manager provides mutex(es) over network. It is used to synchronize processes running on different machines, e.g. WSGI processes in case of web applications. Lock object is compatible with threading.Lock and can be used as a context manager ("with statement"). It can be easily modified to use UNIX sockets instead of TCP/IP. Communication protocol is text based.</p> <p>First start server process:</p> <pre class="prettyprint"><code>$ chmod +x dlm.py $ ./dlm.py </code></pre> <p>Usage:</p> <pre class="prettyprint"><code>from dlm import LockClient client = LockClient('localhost', 27272, 'client_name') lock = client.mkLock('lock_name') lock.acquire() # critical section here... lock.release() # using context manager with lock: # critical section here... </code></pre> Function Pipelines (Python) 2011-05-22T20:39:05-07:00Rob Lhttp://code.activestate.com/recipes/users/4178061/http://code.activestate.com/recipes/577714-function-pipelines/ <p style="color: grey"> Python recipe 577714 by <a href="/recipes/users/4178061/">Rob L</a> (<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). </p> <p>Alexandre Zani's recipe on function pipelines was useful. I wanted to change it to suit my needs.</p> <p>Mostly I just wanted to add arbitrary functions and make the pipe line more list like in behavior.</p> <p>(edit: typos)</p> Function Pipelines (Python) 2011-05-15T19:38:13-07:00Alexandre Zanihttp://code.activestate.com/recipes/users/4177180/http://code.activestate.com/recipes/577696-function-pipelines/ <p style="color: grey"> Python recipe 577696 by <a href="/recipes/users/4177180/">Alexandre Zani</a> (<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). </p> <p>Pipelines can be used to chain a series of functions to process a piece of data. For instance you can build a pipeline to process web requests easily including some middleware for instance.</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> 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> WSGI option parsing & type conversion (Python) 2009-05-28T16:32:11-07:00Brendan O'Connorhttp://code.activestate.com/recipes/users/4170520/http://code.activestate.com/recipes/576784-wsgi-option-parsing-type-conversion/ <p style="color: grey"> Python recipe 576784 by <a href="/recipes/users/4170520/">Brendan O'Connor</a> (<a href="/recipes/tags/option_parsing/">option_parsing</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). Revision 2. </p> <p>fetches named parameters from the WSGI querystring, plus defaults for missing values, and type conversions so you dont accidentally have strings when you want numbers.</p>