import cgi def main(): if cgi.dictionary is None or not cgi.dictionary.has_key('file'): show_form() else: show_file() def show_form(error = ''): if error != '': error = '\t\t\t' + error + ' cannot be displayed.
\n' cgi.html(''' \t \t\t \t\t\tPython Script Viewer \t\t \t \t \t\t
\n''' + error + '''\t\t\tPython Script Filename:
\t\t\t
\t\t\t \t\t
\t ''') def show_file(): try: if cgi.dictionary['file'][-3:].lower() != '.py': raise Exception cgi.plain(file(cgi.dictionary['file']).read()) except: show_form(cgi.dictionary['file']) if __name__ == '__main__': cgi.execute(main, 'python')