def test_get_param_mw(): get_name_mw = GetParamMiddleware(['name', 'date']) app = Application([('/', hello_world)], middlewares=[get_name_mw]) c = Client(app, BaseResponse) resp = c.get('/') yield eq_, resp.data, 'Hello, world!' resp = c.get('/?name=Kurt') yield eq_, resp.data, 'Hello, Kurt!'
def test_get_param_mw(): get_name_mw = GetParamMiddleware(['name', 'date']) app = Application([('/', hello_world)], middlewares=[get_name_mw]) c = app.get_local_client() resp = c.get('/') assert resp.data == b'Hello, world!' resp = c.get('/?name=Kurt') assert resp.data == b'Hello, Kurt!'
def main(): rsc = {'data': _DATA} gpm = GetParamMiddleware('url') atr = AutoTableRenderer(max_depth=5) render_basic = BasicRender() app = Application([('/', ident_ep, render_basic), ('/json', ident_ep, render_basic), ('/fetch', fetch_json, render_basic)], rsc, [gpm]) app.serve()
def create_v1_app(filename=FILENAME): data_store = DataStore(filename) rdm = RequestDataMiddleware() gpm = GetParamMiddleware({'group_by': str, 'limit': int}) return Application([('/on_import', on_import_endpoint, render_basic), ('/count', get_count_data, render_basic), ('/download/import', get_import_data, render_basic)], resources={'data_store': data_store}, middlewares=[gpm, rdm])
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)
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())
def create_app(): routes = [('/', fetch_json, render_basic)] mws = [GetParamMiddleware('url')] app = Application(routes, middlewares=mws) return app
d[col[0]] = row[idx] return d def _add_test_data(the_list, count=6): for i in range(count): is_done = (i % 2) == 1 the_list.add_task('task_%s' % i, done=is_done) return the_list = TodoList('todo.db') the_list.create_db(reset=True) _add_test_data(the_list) app = Cline(resources={'todo_list': the_list}) ashes_rf = AshesRenderFactory(_CUR_DIR) done_mw = GetParamMiddleware({'done': int}) @app.route('/', render=ashes_rf('todo.html'), middlewares=[done_mw]) @app.route('/api/todo', middlewares=[done_mw]) def get_tasks(todo_list, done=None): tasks = todo_list.get_tasks(done=done) print tasks return {'tasks': tasks} if __name__ == '__main__': app.run()