summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/wptserve/wptserve/handlers.py
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/tools/wptserve/wptserve/handlers.py')
-rw-r--r--testing/web-platform/tests/tools/wptserve/wptserve/handlers.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/wptserve/wptserve/handlers.py b/testing/web-platform/tests/tools/wptserve/wptserve/handlers.py
index 6d79230a32..62faf47d64 100644
--- a/testing/web-platform/tests/tools/wptserve/wptserve/handlers.py
+++ b/testing/web-platform/tests/tools/wptserve/wptserve/handlers.py
@@ -2,6 +2,7 @@
import json
import os
+import pathlib
from collections import defaultdict
from urllib.parse import quote, unquote, urljoin
@@ -289,6 +290,10 @@ class PythonScriptHandler:
"""
This loads the requested python file as an environ variable.
+ If the requested file is a directory, this instead loads the first
+ lexicographically sorted file found in that directory that matches
+ "default*.py".
+
Once the environ is loaded, the passed `func` is run with this loaded environ.
:param request: The request object
@@ -298,6 +303,14 @@ class PythonScriptHandler:
"""
path = filesystem_path(self.base_path, request, self.url_base)
+ # Find a default Python file if the specified path is a directory
+ if os.path.isdir(path):
+ default_py_files = sorted(list(filter(
+ pathlib.Path.is_file,
+ pathlib.Path(path).glob("default*.py"))))
+ if default_py_files:
+ path = str(default_py_files[0])
+
try:
environ = {"__file__": path}
with open(path, 'rb') as f:
@@ -416,6 +429,9 @@ class AsIsHandler:
def __call__(self, request, response):
path = filesystem_path(self.base_path, request, self.url_base)
+ if os.path.isdir(path):
+ raise HTTPException(
+ 500, "AsIsHandler cannot process directory, %s" % path)
try:
with open(path, 'rb') as f: