Robust test CGI script, usable as main program. Write minimal HTTP headers and dump all information provided to the script in HTML form.
(environ=os.environ)
| 851 | # =============== |
| 852 | |
| 853 | def test(environ=os.environ): |
| 854 | """Robust test CGI script, usable as main program. |
| 855 | |
| 856 | Write minimal HTTP headers and dump all information provided to |
| 857 | the script in HTML form. |
| 858 | |
| 859 | """ |
| 860 | print("Content-type: text/html") |
| 861 | print() |
| 862 | sys.stderr = sys.stdout |
| 863 | try: |
| 864 | form = FieldStorage() # Replace with other classes to test those |
| 865 | print_directory() |
| 866 | print_arguments() |
| 867 | print_form(form) |
| 868 | print_environ(environ) |
| 869 | print_environ_usage() |
| 870 | def f(): |
| 871 | exec("testing print_exception() -- <I>italics?</I>") |
| 872 | def g(f=f): |
| 873 | f() |
| 874 | print("<H3>What follows is a test, not an actual exception:</H3>") |
| 875 | g() |
| 876 | except: |
| 877 | print_exception() |
| 878 | |
| 879 | print("<H1>Second try with a small maxlen...</H1>") |
| 880 | |
| 881 | global maxlen |
| 882 | maxlen = 50 |
| 883 | try: |
| 884 | form = FieldStorage() # Replace with other classes to test those |
| 885 | print_directory() |
| 886 | print_arguments() |
| 887 | print_form(form) |
| 888 | print_environ(environ) |
| 889 | except: |
| 890 | print_exception() |
| 891 | |
| 892 | def print_exception(type=None, value=None, tb=None, limit=None): |
| 893 | if type is None: |
no test coverage detected