예제 #1
0
def test_simple_ctx_proc():
    add_name_lang = SimpleContextProcessor(name='Kurt', language='en')
    app = Application([('/', hello_world_ctx, render_json)],
                      middlewares=[add_name_lang])
    c = app.get_local_client()
    resp = c.get('/')
    resp_data = json.loads(resp.get_data(True))
    assert resp_data['name'] == 'world'  # does not overwrite
    assert resp_data['language'] == 'en'
예제 #2
0
def test_simple_ctx_proc():
    add_name_lang = SimpleContextProcessor(name='Kurt', language='en')
    app = Application([('/', hello_world_ctx, render_json)],
                      middlewares=[add_name_lang])
    c = Client(app, BaseResponse)
    resp = c.get('/')
    resp_data = json.loads(resp.data)
    yield eq_, resp_data['name'], 'world'  # does not overwrite
    yield eq_, resp_data['language'], 'en'
예제 #3
0
파일: basic.py 프로젝트: waytai/clastic
def create_decked_out_app():
    resources = {'start_time': time.time(),
                 'module_list': sys.modules.keys()}
    middlewares = [GetParamMiddleware(['name', 'date', 'session_id']),
                   SignedCookieMiddleware(),
                   SimpleContextProcessor('name')]
    routes = [('/', cookie_hello_world, render_basic),
              ('/debug', debug, render_basic),
              ('/modules/', see_modules, render_basic)]
    return Application(routes, resources, middlewares=middlewares)
예제 #4
0
def create_decked_out_app():
    resources = {'start_time': time.time(), 'module_list': sys.modules.keys()}
    get_param_names = ['name', 'date', 'session_id', 'limit', 'expire_cookie']
    middlewares = [
        GetParamMiddleware(get_param_names),
        SignedCookieMiddleware(),
        SimpleContextProcessor('name')
    ]
    routes = [('/', cookie_hello_world, render_basic),
              ('/debug', debug, render_basic),
              ('/fizzbuzz', FizzBuzzer().fizzbuzz, render_basic),
              ('/modules', see_modules, render_basic),
              ('/fraiser', fraiser, render_basic),
              ('/obj/', create_obj_browser_app()),
              ('/webtop/', create_webtop_app())]
    return Application(routes,
                       resources,
                       middlewares=middlewares,
                       error_handler=REPLErrorHandler())
예제 #5
0
def create_app(link_list_path=None,
               local_root=None,
               host_url=None,
               secret_key=None):
    link_list_path = link_list_path or _DEFAULT_LINKS_FILE_PATH
    link_map = LinkMap(link_list_path)
    local_static_app = None
    if local_root:
        local_static_app = StaticApplication(local_root)
    host_url = (host_url or 'localhost:5000').rstrip('/') + '/'
    full_host_url = 'http://' + host_url
    resources = {
        'link_map': link_map,
        'local_root': local_root,
        'local_static_app': local_static_app,
        'host_url': host_url,
        'full_host_url': full_host_url
    }

    pdm = PostDataMiddleware({
        'target_url': unicode,
        'target_file': unicode,
        'alias': unicode,
        'max_count': int,
        'expiry_time': unicode
    })
    submit_route = POST('/submit',
                        add_entry,
                        add_entry_render,
                        middlewares=[pdm])

    routes = [('/', home, 'home.html'), submit_route, ('/<alias>', use_entry)]
    scm = SignedCookieMiddleware(secret_key=secret_key)
    scp = SimpleContextProcessor('local_root', 'full_host_url')
    middlewares = [scm, scp]

    arf = AshesRenderFactory(_CUR_PATH, keep_whitespace=False)
    app = Application(routes, resources, middlewares, arf)
    return app