summaryrefslogtreecommitdiffstats
path: root/Lib/http/server.py
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2009-04-03 07:16:55 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2009-04-03 07:16:55 (GMT)
commitb5292a2e27dfb72a63f5ae51eb344405eb8a2f13 (patch)
treec5ebcacfd75bd5eabbc6fbc14e3f0763733f34f6 /Lib/http/server.py
parent3cde7c752ab38e357f9e74d6f5c50af0094e2220 (diff)
downloadcpython-b5292a2e27dfb72a63f5ae51eb344405eb8a2f13.zip
cpython-b5292a2e27dfb72a63f5ae51eb344405eb8a2f13.tar.gz
cpython-b5292a2e27dfb72a63f5ae51eb344405eb8a2f13.tar.bz2
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".
Diffstat (limited to 'Lib/http/server.py')
-rw-r--r--Lib/http/server.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 31153f4..5b5ef0a 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -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)