コード例 #1
0
ファイル: __init__.py プロジェクト: bbinet/blatter
    def template_viewer(environ, start_response):
        prefix, path_info = config.url_prefix, environ['PATH_INFO']
        if not os.path.dirname(path_info).startswith(prefix.rstrip('/')):
            raise NotFound()
        path_info = path_info[len(prefix):]

        if path_info.endswith('/'):
            path_info += config.index_document

        fspath = os.path.join(config.dynamic_path, path_info.lstrip('/'))

        if not os.path.exists(fspath):
            raise NotFound()
        elif os.path.isdir(fspath):
            return append_slash_redirect(environ)

        template = loader.get_template(path_info)

        mimetype, _ = mimetypes.guess_type(path_info)
        mimetype = mimetype or 'text/plain'

        render_environ = dict(environ, PATH_INFO=path_info)
        render_environ['SCRIPT_NAME'] += prefix

        response = BaseResponse(mimetype=mimetype or 'text/plain')
        response.data = template.render(config=config, environ=environ)
        response.headers['Pragma'] = 'no-cache'
        response.headers['Cache-Control'] = 'no-cache, must-revalidate'
        response.headers['Expires'] = 'Sun, 13 Aug 1995 13:00:00 GMT'
        return response
コード例 #2
0
ファイル: web.py プロジェクト: michaeljones/wake
def dispatch_request(environ, start_response):

    adapter = url_map.bind_to_environ(environ)
    endpoint, values = adapter.match()

    if endpoint == "index":
        try:
            endpoint, values = adapter.match()
            request = BaseRequest(environ)
            response = BaseResponse(mimetype='text/html')

            response.data = "Pipeline home page"

            return response

        except HTTPException, e:
            return e