| Index: cms/bin/test_server.py |
| =================================================================== |
| --- a/cms/bin/test_server.py |
| +++ b/cms/bin/test_server.py |
| @@ -50,6 +50,15 @@ |
| # behavior by parsing local config files. |
| mime_types = mimetypes.MimeTypes() |
| +class ConflictingPage(Exception): |
| + pass |
| + |
| +def get_pages_and_localizable_files(source): |
| + for page, format in source.list_pages(): |
| + yield page |
| + for filename in source.list_localizable_files(): |
| + yield filename |
| + |
| def get_data(path): |
| if source.has_static(path): |
| return source.read_static(path) |
| @@ -58,20 +67,43 @@ |
| if path == "": |
| path = source.read_config().get("general", "defaultlocale") |
| if "/" in path: |
| - locale, page = path.split("/", 1) |
| + locale, requested_page = path.split("/", 1) |
| else: |
| - locale, page = path, "" |
| + locale, requested_page = path, "" |
| default_page = source.read_config().get("general", "defaultpage") |
| - alternative_page = "/".join([page, default_page]).lstrip("/") |
| + alternative_page = "/".join([requested_page, default_page]).lstrip("/") |
| + |
| + found_page = None |
| + func = None |
| + args = None |
| + |
| for format in converters.iterkeys(): |
| - for p in (page, alternative_page): |
| - if source.has_page(p, format): |
| - return process_page(source, locale, p, format, "http://127.0.0.1:5000") |
| - if source.has_localizable_file(locale, page): |
| - return source.read_localizable_file(locale, page) |
| + for page in (requested_page, alternative_page): |
| + if source.has_page(page, format): |
| + if found_page: |
| + raise ConflictingPage("The requested page correpsonds to multiple files") |
| - return None |
| + found_page = page |
| + func = process_page |
| + args = (source, locale, page, format, "http://127.0.0.1:5000") |
| + |
| + if source.has_localizable_file(locale, requested_page): |
| + if found_page: |
| + raise ConflictingPage("The requested page conflicts with a localizable file") |
| + |
| + found_page = requested_page |
| + func = source.read_localizable_file |
| + args = (locale, requested_page) |
| + |
| + if not found_page: |
| + return None |
| + |
| + for page in get_pages_and_localizable_files(source): |
| + if page.startswith(found_page + "/") or found_page.startswith(page + "/"): |
| + raise ConflictingPage("The requested path conflicts with the path of another page") |
| + |
| + return func(*args) |
| def show_error(start_response, status, **kwargs): |
| env = jinja2.Environment(autoescape=True) |
| @@ -85,7 +117,7 @@ |
| path = environ.get("PATH_INFO") |
| data = get_data(path) |
| - if data == None: |
| + if data is None: |
| return show_error(start_response, "404 Not Found", uri=path) |
| mime = mime_types.guess_type(path)[0] or "text/html" |