cgi-test.py 850 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python3
  2. # cgi-test.py by Bill Weinman [http://bw.org/]
  3. # Python versoin of CGI testing script
  4. # Copyright 1995-2010 The BearHeart Group, LLC
  5. import sys, os, cgi
  6. version = "5.3.1py cgi/{}".format(cgi.__version__)
  7. for s in (
  8. "Content-type: text/plain", '',
  9. "BW Test version: {}".format(version),
  10. "Copyright 1995-2010 The BearHeart Group, LLC",
  11. "\nVersions:\n=================",
  12. "Python: {}".format(sys.version.split(' ')[0])
  13. ) :
  14. print(s)
  15. form = cgi.FieldStorage()
  16. if form :
  17. print("\nQuery Variables:\n=================")
  18. for k in sorted(form):
  19. v = ']['.join(form.getlist(k)) # multiple items as [a][b][c]...
  20. print("{} [{}]".format(k, v))
  21. print("\nEnvironment Variables:\n=================")
  22. for k in sorted(os.environ.keys()):
  23. v = os.environ[k]
  24. print("{} [{}]".format(k, v))