Popular recipes tagged "meta:requires=cgi"http://code.activestate.com/recipes/tags/meta:requires=cgi/2015-06-18T20:46:32-07:00ActiveState Code Recipesstupid trick: mimicking the python cgi library's FieldStorage() object for command line debuging (Python)
2015-06-18T20:46:32-07:00Jon Crumphttp://code.activestate.com/recipes/users/4174917/http://code.activestate.com/recipes/579069-stupid-trick-mimicking-the-python-cgi-librarys-fie/
<p style="color: grey">
Python
recipe 579069
by <a href="/recipes/users/4174917/">Jon Crump</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/urls/">urls</a>).
Revision 6.
</p>
<p>create dictionary-like object that mimics the cgi.FieldStorage() object having both a <code>.value</code> property, and a <code>.getvalue()</code> method</p>
Python Sessions (Python)
2011-01-08T03:23:05-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577524-python-sessions/
<p style="color: grey">
Python
recipe 577524
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/cookie/">cookie</a>, <a href="/recipes/tags/management/">management</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/sessions/">sessions</a>).
Revision 2.
</p>
<p>I think this script should now be functional enough to post here at ActiveState. When you reply or vote down, please post some information on your problem with the code, and if you can, maybe something about the solution. This interface works, and is designed especially for Python. If you like it, don't be afraid to post that either, constructive criticism is all good, but compliments are even better! ;)</p>
<p>Get the latest version of this code here:
<a href="http://wiki.sunjay.ca/Python:Contents/Python_Session" rel="nofollow">http://wiki.sunjay.ca/Python:Contents/Python_Session</a></p>
<p><strong>Latest Changes:</strong></p>
<ul>
<li>Added a new function for making the session cookie last longer. See code for <code>set_expires</code>. Note: This new function is just in case you need to include a session for longer than one brower session (for example, one day instead). </li>
</ul>
LoggingWebMonitor - a central logging server and monitor. (Python)
2010-02-02T01:56:42-08:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577025-loggingwebmonitor-a-central-logging-server-and-mon/
<p style="color: grey">
Python
recipe 577025
by <a href="/recipes/users/924636/">Gabriel Genellina</a>
(<a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/distributed/">distributed</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/web/">web</a>).
Revision 3.
</p>
<p>LoggingWebMonitor listens for log records sent from other processes running in the same box or network. Collects and saves them concurrently in a log file. Shows a summary web page with the latest N records received.</p>
Convert a transcript with Ansi escape sequences to HTML (Python)
2010-10-09T22:29:42-07:00Muhammad Alkarourihttp://code.activestate.com/recipes/users/4049383/http://code.activestate.com/recipes/577349-convert-a-transcript-with-ansi-escape-sequences-to/
<p style="color: grey">
Python
recipe 577349
by <a href="/recipes/users/4049383/">Muhammad Alkarouri</a>
(<a href="/recipes/tags/ansi/">ansi</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/text/">text</a>).
Revision 2.
</p>
<p>This is a stab at converting a transcript generated by the Unix <code>script</code> command that uses ANSI escape sequences, used to colour the terminal, to HTML.</p>
ExecSql.cgi returning JSON for SQL (Python)
2009-11-28T02:00:30-08:00Martchenkohttp://code.activestate.com/recipes/users/4172446/http://code.activestate.com/recipes/576971-execsqlcgi-returning-json-for-sql/
<p style="color: grey">
Python
recipe 576971
by <a href="/recipes/users/4172446/">Martchenko</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/sql/">sql</a>).
</p>
<p>CGI script getting JSON for SQL request</p>
CGI doc string reader (Python)
2010-04-13T14:06:06-07:00Timothy Makobuhttp://code.activestate.com/recipes/users/4165901/http://code.activestate.com/recipes/576850-cgi-doc-string-reader/
<p style="color: grey">
Python
recipe 576850
by <a href="/recipes/users/4165901/">Timothy Makobu</a>
(<a href="/recipes/tags/dosctring/">dosctring</a>, <a href="/recipes/tags/python_developer_tools/">python_developer_tools</a>).
Revision 10.
</p>
<p>Displays docstrings of attributes of the given Python module on a web browser.
Drop it into the cgi-bin of your web-server, and access it like this,
for example:</p>
<p><a href="http://localhost/cgi-bin/cgidir.py?m=socket" rel="nofollow">http://localhost/cgi-bin/cgidir.py?m=socket</a></p>
SingleUpload.py (Python)
2010-02-24T13:50:27-08:00Wilhelm Shenhttp://code.activestate.com/recipes/users/4061228/http://code.activestate.com/recipes/521897-singleuploadpy/
<p style="color: grey">
Python
recipe 521897
by <a href="/recipes/users/4061228/">Wilhelm Shen</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>Usage:</p>
<pre class="prettyprint"><code>#!/usr/bin/env python2.5
#
# html file:
# <form action="test.cgi" method="POST" enctype="multipart/form-data">
# <input name="file1" type="file"><input type="submit"></form>
# test.cgi: ...
import SingleUpload
def upload():
fr = SingleUpload.open()
fw = open('/tmp/%s' %fr.filename, 'wb')
while True:
l = fr.read(65536)
if not l:
break
fw.write(l)
fw.flush()
fw.close()
print 'Content-Type: text/plain\r\n\r\n'
try:
upload()
print 'OK'
except IOError:
__import__('traceback').print_exc(
file=__import__('sys').stdout )
</code></pre>
Cross-site scripting (XSS) defense (Python)
2006-08-05T10:45:10-07:00Josh Goldfoothttp://code.activestate.com/recipes/users/2960005/http://code.activestate.com/recipes/496942-cross-site-scripting-xss-defense/
<p style="color: grey">
Python
recipe 496942
by <a href="/recipes/users/2960005/">Josh Goldfoot</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>This cleanses user input of potentially dangerous HTML or scripting code that can be used to launch "cross-site scripting" ("XSS") attacks, or run other harmful or annoying code. You want to run this on any user-entered text that will be saved and retransmitted to other users of your web site. This uses only standard Python libraries.</p>
twvalidator: a Markup Validator Gateway for Twisted Web (Python)
2007-01-17T04:00:20-08:00Manlio Perillohttp://code.activestate.com/recipes/users/2425438/http://code.activestate.com/recipes/500263-twvalidator-a-markup-validator-gateway-for-twisted/
<p style="color: grey">
Python
recipe 500263
by <a href="/recipes/users/2425438/">Manlio Perillo</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>twvalidator is a simple markup validator gateway you can embed in your
Twisted Web application for validating all your pages.</p>
Create .m3u playlists on the fly for mp3 dowloads (Python)
2006-02-27T10:32:05-08:00Davide Andreahttp://code.activestate.com/recipes/users/2793872/http://code.activestate.com/recipes/474090-create-m3u-playlists-on-the-fly-for-mp3-dowloads/
<p style="color: grey">
Python
recipe 474090
by <a href="/recipes/users/2793872/">Davide Andrea</a>
.
</p>
<p>When offering an MP3 file for downloading, usually two files are stored in the server: the .mp3 file itself, and a small playlist file (.m3u) which tell the mp3 player to stream the .mp3 file.
This script avoids the need of storing an .m3u file for each .mp3 file. It serves an .m3u playlist "file" to the client, created on the fly.
You can test this script in the site of community radio KGNU; go to <a href="http://kgnu.org/ht/listings.html" rel="nofollow">http://kgnu.org/ht/listings.html</a> and click on any "Listen" icon.</p>
Paypal IPN (Python)
2006-09-19T19:02:54-07:00Anthony Barkerhttp://code.activestate.com/recipes/users/122940/http://code.activestate.com/recipes/456361-paypal-ipn/
<p style="color: grey">
Python
recipe 456361
by <a href="/recipes/users/122940/">Anthony Barker</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
Revision 2.
</p>
<p>This is a cgi script that allows you to log an ipn request from paypal. Basically if you configure your paypal account with an ipn url it will send a post to a script url. You need to respond with a post and then will receive a VERIFIED response.</p>
<p>I've included a subroutine to log the data to a database, but you could simply use a text file if that is all you need.</p>
Asynchronous HTTP server (Python)
2006-02-06T19:16:33-08:00Josiah Carlsonhttp://code.activestate.com/recipes/users/1241800/http://code.activestate.com/recipes/440665-asynchronous-http-server/
<p style="color: grey">
Python
recipe 440665
by <a href="/recipes/users/1241800/">Josiah Carlson</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 5.
</p>
<p>A recipe version of the SimpleAsyncHTTPServer with a few additional options not previously available for basic Python-only web servers.</p>
Python source to XHTML colorizer (Python)
2005-10-26T00:36:06-07:00Peter Krantzhttp://code.activestate.com/recipes/users/2641582/http://code.activestate.com/recipes/442482-python-source-to-xhtml-colorizer/
<p style="color: grey">
Python
recipe 442482
by <a href="/recipes/users/2641582/">Peter Krantz</a>
.
</p>
<p>Converts Python source to a portable XHTML 1.0 strict document that includes a basic set of Dublin Core metadata. Based on the MoinMoin source colorizer.</p>
Python Script Viewer (Python)
2005-10-03T18:17:11-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440642-python-script-viewer/
<p style="color: grey">
Python
recipe 440642
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>First of all, this code was written to take advantage of the custom CGI module that I wrote. The purpose for this script is to allow someone to view a CGI script through a server. I have the problem that when I click on a python (*.py) file while viewed through my browser, the script is run so that it cannot be viewed. Unless the script is using "cgi.execute(function, exception)", then there is no way of getting around the problem. Therefore, this CGI application was written so that python files (and only *.py files) can be viewed if the user knows either the filename of a file in the same directory as this script or the full path of a file somewhere on the host computer. WARNING: do not use this script if you do not want someone to view any and all python scripts on your computer!</p>
My first application server (Python)
2009-02-23T11:53:57-08:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/392879-my-first-application-server/
<p style="color: grey">
Python
recipe 392879
by <a href="/recipes/users/1552957/">Pierre Quentel</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 8.
</p>
<p>For those who want to start dynamic web programming, but don't know what to choose among the many Python web frameworks, this program might be a good starting point</p>
<p>ScriptServer is a minimalist application server, handling both GET and POST requests, including multipart/form-data for file uploads, HTTP redirections, and with an in-memory session management. It can run Python scripts and template files using the standard string substitution format</p>
<p>The scripts are run in the same process as the server, avoiding the CGI overhead. The environment variables are provided in the namespace where the script runs</p>
<p>To start the server, run </p>
<pre class="prettyprint"><code>python ScriptServer.py
</code></pre>
<p>In your web browser, enter <a href="http://localhost" rel="nofollow">http://localhost</a>, this will show you a listing of the directory. Add the scripts in the same directory as ScriptServer</p>
A very simple session handling example (Python)
2004-10-28T10:38:30-07:00Jonas Galvezhttp://code.activestate.com/recipes/users/2122857/http://code.activestate.com/recipes/325484-a-very-simple-session-handling-example/
<p style="color: grey">
Python
recipe 325484
by <a href="/recipes/users/2122857/">Jonas Galvez</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
Revision 4.
</p>
<p>This is a very simple session handling example that uses plain Python CGI (tested only under Python 2.2+). Its goal is to show how cookies are set via HTTP and how easily they can be used for session management.</p>
webcounter (Python)
2004-10-15T05:33:47-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/310320-webcounter/
<p style="color: grey">
Python
recipe 310320
by <a href="/recipes/users/1565518/">Michael Foord</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>This CGI will generate a simple text 'hit counter' for several sites.
Useful to ocunt visitors to the 'front door' of your website.</p>
Minimal http upload cgi (Python)
2004-03-20T01:47:04-08:00Noah Spurrierhttp://code.activestate.com/recipes/users/103276/http://code.activestate.com/recipes/273844-minimal-http-upload-cgi/
<p style="color: grey">
Python
recipe 273844
by <a href="/recipes/users/103276/">Noah Spurrier</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 3.
</p>
<p>This is a bare-bones cgi file upload. It will display an upload form and save the uploaded files to disk.</p>
http - Exploring Headers and Cookies from Servers (Python)
2004-08-18T10:23:52-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/298336-http-exploring-headers-and-cookies-from-servers/
<p style="color: grey">
Python
recipe 298336
by <a href="/recipes/users/1565518/">Michael Foord</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
Revision 5.
</p>
<p>This CGI script allows you to specify a URL. It fetches the URL and displays all the headers sent by the server.
It is based on approx.py the CGI-proxy I'm building. It includes authentication circuitry and I'm using it to understand http authentication.</p>
<p>This script demostrates using urllib2 to fetch a URL - using a request object with User-Agent header. It also demostrates basic authentication and shows the possible http errors - using a dictionary 'borrowed' from BaseHTTPServer.</p>
<p>It will also save cookies using the ClientCookie module, if it's available.</p>
cgi-shell (Python)
2004-07-09T07:31:52-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/286217-cgi-shell/
<p style="color: grey">
Python
recipe 286217
by <a href="/recipes/users/1565518/">Michael Foord</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>Run an arbitrary string on the server as a shell command. Mimics a very basic shell environment on a server using CGI.</p>