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' + error + ' cannot be displayed.
\n'
Zcgi.print_html('''
\t
\t\t
\t\t\tPython Script Viewer
\t\t
\t
\t
\t\t
\t
''' % (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')