def do_debug(self): self.prologue("FAQ Wizard Debugging") form = cgi.FieldStorage() cgi.print_form(form) cgi.print_environ(os.environ) cgi.print_directory() cgi.print_arguments()
def do_POST(self): print "in do_POST(self)" # this shows successfully to the command line ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) if ctype == 'multipart/form-data': postvars = cgi.parse_multipart(self.rfile, pdict) elif ctype == 'application/x-www-form-urlencoded': length = int(self.headers.getheader('content-length')) postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1) else: postvars = {} print postvars form = cgi.FieldStorage() print cgi.print_form(form) # this always prints an empty form print str(form.getvalue('name')) # this always prints an empty string if "name" not in form or "addr" not in form: # the if never runs print "Please fill in the name and addr fields." else: print "<p>name:", form["name"].value print "<p>addr:", form["addr"].value self.wfile.write("test response 123 \n") # this shows successfully in Postman self.send_response(200) # the 200 is successfully received by Postman
def dumpstatepage(exhaustive=0): """ for debugging: call me at top of a CGI to generate a new page with CGI state details """ if exhaustive: cgi.test() # show page with form, environ, etc. else: pageheader(kind='state dump') form = cgi.FieldStorage() # show just form fields names/values cgi.print_form(form) pagefooter() sys.exit()
def Dispatch(): """ Finds the user and command and passes control on """ user = os.environ.get('REMOTE_USER') form = cgi.FieldStorage() if "cmd" not in form: print(TEMPLATE_A) cgi.print_form(form) query = os.environ.get('QUERY_STRING') or "Empty Query String" print(NO_CMD_ERROR.format(query)) return cmd = set(form.getlist("cmd")) if len(cmd) != 1: print(MULTIPLE_CMDS_ERROR.format(cmd)) return cmd = cmd.pop() if not user and cmd not in VIEW_VALID: print(INVALID_CMD_ERROR.format(cmd, user, VIEW_VALID)) return elif cmd not in EDIT_VALID: print(INVALID_CMD_ERROR.format(cmd, user, EDIT_VALID)) return if cmd == 'report': from foodlog.report import Report Report(form, user) elif cmd == 'enter': from foodlog.form import EntryForm EntryForm(form, user).process() elif cmd == 'edit': from foodlog.edit import Edit Edit(form, user) elif cmd == 'detail': from foodlog.detail import ViewCourse ViewCourse(form, user) elif cmd == 'search': from foodlog.full_search import FullTextSearch FullTextSearch(form, user) elif cmd == 'template': from foodlog.copy_template import CopyTemplate CopyTemplate(form, user) else: print(NOT_IMPLEMENTED.format(cmd))
def init_vals(): ryw_view.print_header_logo() form = cgi.FieldStorage() tmpdir = form.getfirst('tmpdir', '') jobfile = form.getfirst('jobfile', '') autorunMerge = form.getfirst('autorun','') overwrite = form.getfirst('overwrite', '') if not tmpdir or not jobfile: ryw.give_bad_news( 'ProcessDiscs.init_vals: bad input: tmpdir, jobfile: ' + tmpdir + ' ' + jobfile, logging.error) cgi.print_form(form) return (False, None, None, None, None) overWrite = False if overwrite == 'true' or overwrite == 'True': overWrite = True return (True, tmpdir, jobfile,autorunMerge, overWrite)
#!/usr/bin/env python print "Content-type: text/html" print import cgi form=cgi.FieldStorage() x,y = form.getvalue("val").split(',') x,y = int(x),int(y) print "<table>" for i in range(y): print "<tr>" for j in range(x): print "<td>%dx%d</td>" % (j,i) print "</tr>" print "</table>" cgi.print_directory() cgi.print_form(form)
#!/usr/bin/env python # -*- coding: UTF-8 -*-# enable debugging import cgi formData = cgi.FieldStorage() #cgi.test() print "Content-type:text/html\r\n\r\n" print '<html><body>' print 'action=', formData.getvalue("action") print '<br>' print 'slider=', formData.getvalue("slider") cgi.print_form(formData) print '</body></html>'
#!/usr/bin/python import cgi, os, sys import posixpath, ntpath, macpath debugmode = False loadtextauto = False uploaddir = './uploads' sys.stderr = sys.stdout form = cgi.FieldStorage() print('Content-type: text/html\n') if debugmode: cgi.print_form(form) html = """ <html><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></html>""" goodhtml = html % """ <p>Your file, '%s', has been saved on the server as '%s'.</p> <p>An echo of the file's contents received and saved appears below. </p><hr> <p><pre>%s</pre> </p><hr> """
import cgi, os, sys import posixpath, ntpath, macpath debugme = False loadtextauto = False uploaddir = './uploads' sys.stderr = sys.stdout form = cgi.FieldStorage() print('Content-type: text/html\n') if debugme: cgi.print_form(form) html = """ <html><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></html>""" goodhtml = html % """ <p> Your file, '%s', has been saved on the server as '%s'.</p> <p>An acho of the file's contents recieved and saved appears below.</p><hr> <p><pre>%s</pre. </p><hr>""" def splitpath(origpath): for pathmodule in [posixpath, ntpath, macpath]: basename = pathmodule.split(origpath)[1]
#!/usr/bin/py3 import cgi, os, sys import posixpath, ntpath, macpath # for client paths debugme = False # True=print form info loadtextauto = False # True=read file at once uploaddir = './uploads' # dir to store files sys.stderr = sys.stdout # show error msgs form = cgi.FieldStorage() # parse form data print("Content-type: text/html\n") # with blank line if debugme: cgi.print_form(form) # print form fields # html templates html = """ <html><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></html>""" goodhtml = html % """ <p>Your file, '%s', has been saved on the server as '%s'. <p>An echo of the file's contents received and saved appears below. </p><hr> <p><pre>%s</pre> </p><hr> """ # process form data
# set this to True when running from command line debugMode = True # set to true to read the file at once loadtextauto = False # the directory should be writable uploaddir = './uploads' sys.stderr = sys.stdout form = cgi.FieldStorage() print("Content-type: text/html\n") if debugMode: print(cgi.print_form(form)) response = """ <html><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></html>""" validResponse = response % """ <p>Your file, '%s', has been saved on the server as '%s'. <p>An echo of the file's contents received and saved appears below. </p><hr> <p><pre>%s</pre> </p><hr> """
"""Generic FAQ Wizard.
caveat: could open output file in text mode to write receiving platform's line ends since file content always str from the cgi module, but this is a temporary solution anyhow--the cgi module doesn't handle binary file uploads; ##################################################################################### """ import cgi, os, sys import posixpath, ntpath, macpath debugmode = False loadtextauto = False uploaddir = './uploads' sys.stderr = sys.stdout form = cgi.FieldStorage() print("Content-type: text/html\n") if debugmode: cgi.print_form(form) html = """ <html><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></html> """ goodhtml = html % """ <p>Your file, '%s', has been saved on the server as '%s'.</p> <p>An echo of the file's contents received and saved appears below.</p> <hr> <p><pre>%s</pre> </p><hr>
ends since file content always str from the cgi module, but this is a temporary solution anyhow--the cgi module doesn't handle binary file uploads in 3.1 at all; ################################################################################ """ import cgi, os, sys import posixpath, ntpath, macpath # for client paths debugmode = False # True=print form info loadtextauto = False # True=read file at once uploaddir = './uploads' # dir to store files sys.stderr = sys.stdout # show error msgs form = cgi.FieldStorage() # parse form data print("Content-type: text/html\n") # with blank line if debugmode: cgi.print_form(form) # print form fields # html templates html = """ <html><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></html>""" goodhtml = html % """ <p>Your file, '%s', has been saved on the server as '%s'. <p>An echo of the file's contents received and saved appears below. </p><pre>%s</pre> </p><hr>
#path.append("../") import cgi import cgitb from time import time startTime = time() searchText = "" resultCount = 0 from searchengine import searcher if not debug : cgitb.enable() form = cgi.FieldStorage() if (debug): cgi.print_form(form) def htmlHeader(text = ''): decl = "Content-Type: text/html\n" # decl += """<!DOCTYPE html PUBLIC # "-//W3C//DTD XHTML 1.0 Transitional//EN" # "DTD/xhtml1-transitional.dtd">""" if text == "": Title = "Search" else: Title = "Result of %s" % text head = """ <html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
def update_event(self, inp=-1): self.set_output_val(0, cgi.print_form(self.input(0)))
def debug_block(): cgi.print_form(form) cgi.print_directory() cgi.print_environ()
################################################################################## """ import cgi, os, sys import html import posixpath, ntpath, macpath # for client paths debugmode = False # True=print form info loadtextauto = False # True=read file at once uploaddir = '.\\uploads' # dir to store files sys.stderr = sys.stdout # show error msgs form = cgi.FieldStorage() # parse form data print("Content-type: text/html\n") # with blank line if debugmode: cgi.print_form(form) # print form fields # HTML templates HTML = """ <HTML><title>Putfile response page</title> <body> <h1>Putfile response page</h1> %s </body></HTML>""" goodhtml = HTML % """ <p>Your file, '%s', has been saved on the server as '%s'. <p>An echo of the file's contents received and saved appears below. </p><hr> <p><pre>%s</pre> </p><hr>
def printForm(self): """Print contents of form as html.""" cgi.print_form(self.form)