Kaydet (Commit) b5292a2e authored tarafından Alexandre Vassalotti's avatar Alexandre Vassalotti

Make http.server main program nicer for interactive use.

Remove unreachable calls to test().

This restores the behavior of SimpleHTTPServer, where a user could
type "python -m SimpleHTTPServer" and get a simple server for sharing
files. Now, you can do the same thing with "python3 -m http.server".
üst 3cde7c75
...@@ -1082,10 +1082,12 @@ def test(HandlerClass = BaseHTTPRequestHandler, ...@@ -1082,10 +1082,12 @@ def test(HandlerClass = BaseHTTPRequestHandler,
sa = httpd.socket.getsockname() sa = httpd.socket.getsockname()
print("Serving HTTP on", sa[0], "port", sa[1], "...") print("Serving HTTP on", sa[0], "port", sa[1], "...")
httpd.serve_forever() try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
httpd.server_close()
sys.exit(0)
if __name__ == '__main__': if __name__ == '__main__':
test(HandlerClass=BaseHTTPRequestHandler)
test(HandlerClass=SimpleHTTPRequestHandler) test(HandlerClass=SimpleHTTPRequestHandler)
test(HandlerClass=CGIHTTPRequestHandler)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment