All pastes #9075 Raw Edit

Something

public python v1 · immutable
#9075 ·published 2005-04-08 04:48 UTC
rendered paste body
#!/usr/bin/pythonimport cgi,sys,rearray1=[]array2=[]response=[]form = cgi.FieldStorage()print "Content-type: text/html\n"def formgen():  print """  <html><head><title>madlib form</title></head><body>  <form name="input" action="madlib.cgi" method="POST">  <input type="hidden" name="hasformgen" value="true">  """      filename=form['madlib'].value + '.txt'    print '<input type="hidden" name="filename" value="' + filename + '">'    file=open(filename).read()  file=str(file)    array1 = re.findall('\{.*?\}', file)    for i in array1:    array2.append(i[1:-1])    for i in range(len(array2)):    response.append(array2[i] + ': <input type="text" name="' + array2[i] + '"><br>')    for i in range(len(response)):    print response[i]  print """  <input type="submit" value="Submit">  </form>  </body>  </html>  """def display(madlib_file):  print """  <html><head><title>madlib results</title></head><body>  """    file=open(madlib_file).read()  file=str(file)  array1 = re.findall('\{.*?\}', file)  for i in array1:    array2.append(i[1:-1])      for i in range(len(array2)):    x=array2[i]    file = re.sub(array1[i], form[x].value, file)#     #   for i in range(len(array2)):#    file = re.sub(array1[i], form[array2[i]].value, madlib_file)  print '\n' + file + '\n' + "</body></html>"  def main():  gen=form['hasformgen'].value  if gen=='true':    madfile=form['filename'].value    display(madfile)  else:    formgen()main()