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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import os
import sys
import Zcgi
def main():
if Zcgi.dictionary is None or not Zcgi.dictionary.has_key('file'):
show_form()
else:
show_file()
def show_form(error=''):
if error:
error = '\t\t\t<b>' + error + '</b> cannot be displayed.<br>\n'
Zcgi.print_html('''<html>
\t<head>
\t\t<title>
\t\t\tPython Script Viewer
\t\t</title>
\t</head>
\t<body>
\t\t<form action="%s">
%s\t\t\tPython Script Filename:<br>
\t\t\t<input type="text" name="file" size="50"><br>
\t\t\t<input type="submit" value="Display">
\t\t</form>
\t</body>
</html>''' % (os.path.basename(sys.argv[0]), error))
def show_file():
try:
if Zcgi.dictionary['file'][-3:].lower() != '.py':
raise Exception
Zcgi.print_plain(file(Zcgi.dictionary['file']).read())
except Exception, error:
if error.__class__ is not SystemExit:
show_form(Zcgi.dictionary['file'])
if __name__ == '__main__':
Zcgi.execute(main, 'cgi')
|
The Zcgi
module can be found in recipe 475112.