

@app.route('/', defaults={
    'path': '/',
})
@app.route('/<path:path>')
def page_handler(path):
    if (not path.endswith('/')):
        return redirect((path + '/'))
    elif (not path.startswith('/')):
        path = ('/' + path)
    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:
        filepath = path[1:(- 1)]
        paths = [os.path.join((filepath + 'index'))]
        if filepath:
            paths.append(filepath)
        filenames = []
        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)
    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/original