Don't use directory argument with SimpleHTTPRequestHandler constructor

The `directory` argument has been added only since Python 3.7, which
breaks the unit test on Python 3.6.

Reimplement the intended behavior by overriding the `translate_path()`
method, which takes the `directory` value into account on newer Python
versions.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-04-25 16:05:15 +02:00 committed by Tomáš Hozza
parent eb427e2513
commit 3100882019

View file

@ -73,7 +73,13 @@ def can_setup_netns() -> bool:
def runFileServer(barrier, directory):
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, request, client_address, server):
super().__init__(request, client_address, server, directory=directory)
super().__init__(request, client_address, server)
def translate_path(self, path: str) -> str:
translated_path = super().translate_path(path)
common = os.path.commonpath([translated_path, directory])
translated_path = os.path.join(directory, os.path.relpath(translated_path, common))
return translated_path
def guess_type(self, path):
try: