This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maggyero
Recipients JelleZijlstra, eric.araujo, maggyero, matrixise, openalmeida
Date 2022-01-23.18:05:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642961100.61.0.200618402709.issue46285@roundup.psfhosted.org>
In-reply-to
Content
Thanks Hugo for opening this issue and Éric for inviting me.

As you guys pointed out, function test in module http.server expects a real handler class argument (SimpleHTTPRequestHandler or CGIHTTPRequestHandler), not a partial object partial(SimpleHTTPRequestHandler, directory=args.directory) or partial(CGIHTTPRequestHandler, directory=args.directory), so that the assignment of protocol_version class attribute in test is not ignored.

The partial object in the if __name__ == '__main__' branch of module http.server was introduced in the first place to pass the directory argument to the handler class’s __init__ method called in method BaseServer.finish_request:

    def finish_request(self, request, client_address):
        """Finish one request by instantiating RequestHandlerClass."""
        self.RequestHandlerClass(request, client_address, self)

But finish_request is a factory method of BaseServer (the abstract creator) so it is DESIGNED to be overridden in subclasses to customize the instantiation of the handler class BaseRequestHandler (the abstract product). So the proper way to instantiate SimpleHTTPRequestHandler and CGIHTTPRequestHandler with the directory argument is to override BaseServer.finish_request.

That is what I have just did by updating my PR here: https://github.com/python/cpython/pull/30701/commits/fc7f95f9d270a8a83cb2fd6d51eb0f904b85e0d9

It fixes both #46285 and #46436.
History
Date User Action Args
2022-01-23 18:05:00maggyerosetrecipients: + maggyero, eric.araujo, matrixise, JelleZijlstra, openalmeida
2022-01-23 18:05:00maggyerosetmessageid: <1642961100.61.0.200618402709.issue46285@roundup.psfhosted.org>
2022-01-23 18:05:00maggyerolinkissue46285 messages
2022-01-23 18:05:00maggyerocreate