diff -r cd822205d37b -r c565bc1279a3 Lib/http/server.py --- a/Lib/http/server.py Sun Dec 04 15:43:57 2016 +0200 +++ b/Lib/http/server.py Sun Dec 04 16:07:46 2016 +0100 @@ -103,6 +103,7 @@ import urllib.parse import copy import argparse +from functools import partial from http import HTTPStatus @@ -634,6 +635,10 @@ server_version = "SimpleHTTP/" + __version__ + def __init__(self, *args, **kwargs): + self.directory = kwargs.pop('directory', os.getcwd()) + super().__init__(*args, **kwargs) + def do_GET(self): """Serve a GET request.""" f = self.send_head() @@ -776,7 +781,7 @@ path = posixpath.normpath(path) words = path.split('/') words = filter(None, words) - path = os.getcwd() + path = self.directory for word in words: if os.path.dirname(word) or word in (os.curdir, os.pardir): # Ignore components that are not a simple file/directory name @@ -1206,9 +1211,13 @@ default=8000, type=int, nargs='?', help='Specify alternate port [default: 8000]') + parser.add_argument('--directory', '-d', default=os.getcwd(), + help='Specify alternate directory ' + '[default: current directory]') args = parser.parse_args() if args.cgi: handler_class = CGIHTTPRequestHandler else: - handler_class = SimpleHTTPRequestHandler + handler_class = partial(SimpleHTTPRequestHandler, + directory=args.directory) test(HandlerClass=handler_class, port=args.port, bind=args.bind)