Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion serve/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def _get_meta(self, request):
if replacement:
yield replacement

def listing_fixup(self, base, names):
extras = set()
for name in names:
for item in self.path_replace:
dest, src = item[:2]
if name.endswith(src):
extras.add(name.replace(src, dest))

return names | extras

@abc.abstractproperty
def path_replace(self):
# A list containing a mix of 2 item tuples with (input suffix, output suffix)
Expand Down Expand Up @@ -243,10 +253,16 @@ def add_mount_point(self, url_base, path):
]

for (method, suffix, handler_cls) in routes:
handler = handler_cls(base_path=path, url_base=url_base)
if hasattr(handler, "listing_fixup"):
listing_fixup = handler.listing_fixup
else:
listing_fixup = None
self.mountpoint_routes[url_base].append(
(method,
b"%s%s" % (str(url_base) if url_base != "/" else "", str(suffix)),
handler_cls(base_path=path, url_base=url_base)))
handler,
listing_fixup))

def add_file_mount_point(self, file_url, base_path):
assert file_url.startswith("/")
Expand Down