]> granicus.if.org Git - python/commitdiff
Make http.server main program nicer for interactive use.
authorAlexandre Vassalotti <alexandre@peadrop.com>
Fri, 3 Apr 2009 07:16:55 +0000 (07:16 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Fri, 3 Apr 2009 07:16:55 +0000 (07:16 +0000)
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".

Lib/http/server.py

index 31153f4a3995922397ec6d605a06e058ee379b62..5b5ef0a48dcefb221117727fc91bfaa79c5f0c8e 100644 (file)
@@ -1082,10 +1082,12 @@ def test(HandlerClass = BaseHTTPRequestHandler,
 
     sa = httpd.socket.getsockname()
     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__':
-    test(HandlerClass=BaseHTTPRequestHandler)
     test(HandlerClass=SimpleHTTPRequestHandler)
-    test(HandlerClass=CGIHTTPRequestHandler)