add 'directory' option to the http.server module #72893
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = None closed_at = <Date 2017-05-24.07:32:22.284> created_at = <Date 2016-11-15.22:31:49.043> labels = ['3.7'] title = "add 'directory' option to the http.server module" updated_at = <Date 2017-05-24.07:32:22.283> user = 'https://github.com/matrixise'
activity = <Date 2017-05-24.07:32:22.283> actor = 'vstinner' assignee = 'none' closed = True closed_date = <Date 2017-05-24.07:32:22.284> closer = 'vstinner' components =  creation = <Date 2016-11-15.22:31:49.043> creator = 'matrixise' dependencies =  files = ['45493', '45494', '45753', '45764'] hgrepos =  issue_num = 28707 keywords = ['patch'] message_count = 11.0 messages = ['280898', '280899', '280903', '280906', '280916', '282346', '294292', '294293', '294311', '294332', '294334'] nosy_count = 4.0 nosy_names = ['vstinner', 'matrixise', 'xiang.zhang', 'mdk'] pr_nums = ['1776'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue28707' versions = ['Python 3.6', 'Python 3.7']
The text was updated successfully, but these errors were encountered:
When we execute the http.server module, the tool will use the current directory (os.getcwd()) but sometimes we would like to specify a directory on the command line.
With the next patch, I try to fix this missing feature ;-)
Just with python -m http.server -d /tmp
by default the system will use the current directory.
Your patch is simple and elegant, but I'm asking myself a question about the idea to pass a class instead of an instance to the TCPServer ctor (I know that's not your choice).
If we were able to pass an instance of SimpleHTTPRequestHandler instead of its class, we'd be able to give the
I think that relying on
I tried to provide a patch fixing all those condiderations, here it is. still, I can't write a patch as KISS as yours, so I'm probably in the wrong way, at least I tried.
Julien Palard added the comment:
You may be able to use functools.partial() to pass an additional
We use something like that in asyncio for protocols.
I have added the documentation, but for the unit test, there is already a test with the SimpleHTTPRequestHandler class where they specify the cwd attribute, because the code of mdk does not change the behavior, I think it's not needed to write a test.
now, if you think we need a test for this specific case (in fact we only override the constructor of the class and specify the directory parameter), I can write a test, but check the code before.