"""
Launch this code in the directory where
the CGI script is that you want to run.
Point the browser to localhost:8000
(or whatever the value of PORTNUMBER is),
followed by / and the name of the script.
"""
PORTNUMBER = 8000
import http.server
import cgitb; cgitb.enable()  # CGI error report
 
server = http.server.HTTPServer
handler = http.server.CGIHTTPRequestHandler
server_address = ("", PORTNUMBER)
handler.cgi_directories = ["/"]
 
httpd = server(server_address, handler)
try:
    print('welcome to our cgi server')
    print('press ctrl c to shut down the server')
    httpd.serve_forever()
except:
    print('ctrl c pressed, shutting down server')
    httpd.socket.close()
