-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add 'directory' option to the http.server module #72893
Comments
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. |
The new feature should be documented in Doc/library/http.server.rst, and maybe also Doc/whatsnew/3.7.rst. Is it possible to write an unit test? |
Hi Stéphane, 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. |
+1 for this idea. I use this command everyday in work and every time must cd to the directory is an annoyance. |
@victor you're right, I forgot that partial can also apply keyword arguments. Here is a new patch. |
Victor, 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. Thank you. |
and of course, sorry for this big delay. |
Stéphane Wirtel added the comment: and of course, sorry for this big delay. I am not sure why you are saying that. Nobody was actively awaiting on this |
Patch merged. Thanks Stéphane and Julien! Especially because writing the unit test was much more painful than I expected, but it's really worth it! |
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
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: