summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-06-03 08:15:54 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-06-03 08:15:54 (GMT)
commit1251fafcc57091d952bb1cc9b1e1a77f39c59b7b (patch)
tree9c769f7853d95b57d296f4220006d6aeb807cca5 /Lib
parentc68e1368b52eb3b6b192593b988e882579827694 (diff)
downloadcpython-1251fafcc57091d952bb1cc9b1e1a77f39c59b7b.zip
cpython-1251fafcc57091d952bb1cc9b1e1a77f39c59b7b.tar.gz
cpython-1251fafcc57091d952bb1cc9b1e1a77f39c59b7b.tar.bz2
Issue 14989: http.server --cgi option can enable the CGI http server.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/http/server.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index cb66f2b..c4ac703 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -100,6 +100,8 @@ import sys
import time
import urllib.parse
import copy
+import argparse
+
# Default error message template
DEFAULT_ERROR_MESSAGE = """\
@@ -1173,18 +1175,13 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
def test(HandlerClass = BaseHTTPRequestHandler,
- ServerClass = HTTPServer, protocol="HTTP/1.0"):
+ ServerClass = HTTPServer, protocol="HTTP/1.0", port=8000):
"""Test the HTTP request handler class.
This runs an HTTP server on port 8000 (or the first command line
argument).
"""
-
- if sys.argv[1:]:
- port = int(sys.argv[1])
- else:
- port = 8000
server_address = ('', port)
HandlerClass.protocol_version = protocol
@@ -1200,4 +1197,15 @@ def test(HandlerClass = BaseHTTPRequestHandler,
sys.exit(0)
if __name__ == '__main__':
- test(HandlerClass=SimpleHTTPRequestHandler)
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--cgi', action='store_true',
+ help='Run as CGI Server')
+ parser.add_argument('port', action='store',
+ default=8000, type=int,
+ nargs='?',
+ help='Specify alternate port [default: 8000]')
+ args = parser.parse_args()
+ if args.cgi:
+ test(HandlerClass=CGIHTTPRequestHandler, port=args.port)
+ else:
+ test(HandlerClass=SimpleHTTPRequestHandler, port=args.port)