Popular recipes tagged "cgi"http://code.activestate.com/recipes/tags/cgi/popular/2016-11-01T02:27:13-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>
Calendar Maker (Python)
2012-07-03T05:23:57-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578187-calendar-maker/
<p style="color: grey">
Python
recipe 578187
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/calendar/">calendar</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/old/">old</a>).
</p>
<p>This is an old program experimenting with CGI techniques in Python using <code>CGIHTTPServer</code> and designed for creating calendars. This is committed for archival to be run under Python 2.5 or later versions.</p>
Zcgi Test (Python)
2012-07-02T22:44:58-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578185-zcgi-test/
<p style="color: grey">
Python
recipe 578185
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/test/">test</a>).
</p>
<p>While trying to implement a bare-bones CGI module with little support for the then-new-to-me concept, the <code>Zcgi</code> module was written, and this experiment was designed to test what it could do. This is committed for archival to be run under Python 2.5 or later versions.</p>
CGI Directory Contents (Python)
2012-07-02T22:38:31-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578183-cgi-directory-contents/
<p style="color: grey">
Python
recipe 578183
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/old/">old</a>).
</p>
<p>CGI Directory Contents was a simple experiment meant to work similarly to the <code>os.listdir</code> function in Python. This is committed for archival to be run under Python 2.5 or later versions.</p>
CGI Image Viewer (Python)
2012-07-02T22:52:32-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578186-cgi-image-viewer/
<p style="color: grey">
Python
recipe 578186
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/old/">old</a>).
</p>
<p>If you have ever started a program and never finished it, then you may recognize the code below for what it is: an experiment begun but not completed, meant to allow viewing pictures on a server. It is included here as an exercise for the reader to complete and is committed for archival to be run under Python 2.5 or later versions.</p>
Python Viewer (Python)
2012-07-02T22:29:27-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578181-python-viewer/
<p style="color: grey">
Python
recipe 578181
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/viewer/">viewer</a>).
</p>
<p>This was a CGI experiment from many years ago for viewing Python files on a server. This is committed for archival to be run under Python 2.5 or later versions.</p>
IP Address (Python)
2012-07-02T22:34:13-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578182-ip-address/
<p style="color: grey">
Python
recipe 578182
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/old/">old</a>).
</p>
<p>The following was a CGI experiment for finding out the IP address of a connecting client. This is committed for archival to be run under Python 2.5 or later versions.</p>
Page Counter (Python)
2012-07-02T22:41:43-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578184-page-counter/
<p style="color: grey">
Python
recipe 578184
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/achive/">achive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/counter/">counter</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/page/">page</a>).
</p>
<p>This page counter was a CGI experiment in what it would take to implement such a simple concept. This is committed for archival to be run under Python 2.5 or later versions.</p>
Get user's IP address even when they're behind a proxy (Python)
2011-07-15T21:19:17-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/577795-get-users-ip-address-even-when-theyre-behind-a-pro/
<p style="color: grey">
Python
recipe 577795
by <a href="/recipes/users/4170919/">Ben Hoyt</a>
(<a href="/recipes/tags/address/">address</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/webpy/">webpy</a>).
</p>
<p>Function to get the user's IP address in a web app or CGI script, even when they're behind a web proxy.</p>
<p>We use web.py as our web framework, but change web.ctx.env and web.ctx.get('ip') to whatever the equivalents are for the CGI environment variables and REMOTE_ADDR are in your framework.</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>
Userfriendly Webpage Template (Python)
2010-05-04T07:38:03-07:00david.gaarenstroomhttp://code.activestate.com/recipes/users/4168848/http://code.activestate.com/recipes/577203-userfriendly-webpage-template/
<p style="color: grey">
Python
recipe 577203
by <a href="/recipes/users/4168848/">david.gaarenstroom</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/httpserver/">httpserver</a>, <a href="/recipes/tags/mvc/">mvc</a>, <a href="/recipes/tags/template/">template</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/webdesign/">webdesign</a>, <a href="/recipes/tags/webpagetemplate/">webpagetemplate</a>).
Revision 5.
</p>
<p>User friendly template class targeted towards Web-page usage and optimized for speed and efficiency.</p>
<p>Tags can be inserted in a template HTML file in a non-intrusive way, by using specially formatted comment strings. Therefore, the template-file can be viewed in a browser, even with prototype data embedded in it, which will later be replaced by dynamic content.
Also, webdesigners can continue to work on the template and upload it without further
modification.</p>
JasperServer.cgi. It works (Python)
2009-11-28T10:34:40-08:00Martchenkohttp://code.activestate.com/recipes/users/4172446/http://code.activestate.com/recipes/576970-jasperservercgi-it-works/
<p style="color: grey">
Python
recipe 576970
by <a href="/recipes/users/4172446/">Martchenko</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/jasperreports/">jasperreports</a>, <a href="/recipes/tags/snippet/">snippet</a>).
Revision 2.
</p>
<p>running jasperreports over pythons CGI</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>
Easy testing of CGI scripts (Python)
2016-11-01T02:27:13-07:00Bryan Olsonhttp://code.activestate.com/recipes/users/1998252/http://code.activestate.com/recipes/550822-easy-testing-of-cgi-scripts/
<p style="color: grey">
Python
recipe 550822
by <a href="/recipes/users/1998252/">Bryan Olson</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
Revision 3.
</p>
<p>Invoking 'runcgi.py target.cgi' starts a built-in web server listening on the localhost adapter, configures the server to run target.cgi as a CGI program, then launches the system's default web browser to get the URL of the target script. The CGI script need not be in Python. The terminal that launched runcgi.py will show the server's log, which reports requests, responses, and errors.</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>
An asynchronous HTTP server with CGI support (Python)
2007-04-05T05:46:26-07:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/511454-an-asynchronous-http-server-with-cgi-support/
<p style="color: grey">
Python
recipe 511454
by <a href="/recipes/users/1552957/">Pierre Quentel</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>This recipes implements the HTTP protocol with persistent connection and CGI support on top of the generic asynchronous server provided in <a href="http://code.activestate.com/recipes/511453/">recipe 511453</a></p>
z_cgi.py (Python)
2012-07-02T23:06:06-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/496854-z_cgipy/
<p style="color: grey">
Python
recipe 496854
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>z_cgi.py provides a simple interface for CGI applications.
It does not currently support reading information from standard in.
Future versions will probably be delivered in a packaged format.</p>
z_html.py (Python)
2006-07-05T09:40:44-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/496862-z_htmlpy/
<p style="color: grey">
Python
recipe 496862
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
</p>
<p>This recipe requires the z_matrix module.
Two classes are provided, HTML_Table and HTML_Month.
HTML_Table can manage the generation of a table in HTML format.
HTML_Month builds on top of HTML_Table and expands on its capabilities.
It allows for dynamically created tables that have the look of the selected month.</p>
Schedule Maker (Python)
2012-07-03T05:09:03-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/475112-schedule-maker/
<p style="color: grey">
Python
recipe 475112
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
Revision 5.
</p>
<p>This CGI program is designed to create schedules once given valid information on a form.
It is not designed to look pretty but tests the ability to combine custom modules in different sized projects.
It has minimal functionality but gets its job done in a timely manner and in a format that can be understood.</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>