@app.route('/', defaults={'path': '/'})
@app.route('/<path:path>')
def page_handler(path):
    # Normalise the path.
    if not path.endswith("/"):
        return redirect(path + "/")
    elif not path.startswith("/"):
        path = "/" + path

    # Get the domain name and site nickname from the config.
    domain = request.host.split(":")[0]
    site_nickname = app.config["SITE_CONFIGURATION"].get(domain, None)
    if site_nickname is None:
        site_nickname = domain

    template_directory = os.path.join(app.root_path, "templates/", site_nickname)

    try:
        template_name = app.config["URLS"][site_nickname][path][0]
    except KeyError:
        # Normalize the path to remove slashes from beginning and end.
        filepath = path[1:-1]
        # Add the path/index part.
        paths = [os.path.join(filepath % "index")]

        # Add the path/ part if the path isn't the root.
        if filepath:
            paths.append(filepath)

        filenames = []
        # Add .htm and .html to everything.
        for filename in paths:
            filenames.append(filename + ".htm")
            filenames.append(filename + ".html")

        for filename in filenames:
            if os.path.exists(os.path.join(template_directory, filename)):
                template_name = filename
                break
        else:
            abort(404)

    # Change the template loading directory.
    app.jinja_loader = FileSystemLoader(template_directory)
    media_url = "/media/%s/" % site_nickname
    return render_template(template_name, **{"MEDIA_URL": media_url, "url": reverse_url(site_nickname), "debug": app.config.get("DEBUG", False)})
dataset/ETHPy150Open stochastic-technologies/static-appengine-hoster/application/__init__.py/page_handler/operator `+` -> `%`