def test_append(self): self.root.append(u("index/"), u("test"))(lambda: True) assert self.root.subnode.pop().subnode.pop().handles["GET"].pop() self.root.append(u("index/"), u("test"), methods=("GET",))(lambda: 1) assert not self.root.subnode[-1].subnode[-1].handles["OPTION"] assert self.root.subnode.pop().subnode.pop().handles["GET"].pop()
def test_append(self): self.root.append(u('index/'), u('test'))(lambda: True) assert self.root.subnode.pop().subnode.pop().handles['GET'].pop() self.root.append(u('index/'), u('test'), methods=('GET', ))(lambda: 1) assert not self.root.subnode[-1].subnode[-1].handles['OPTION'] assert self.root.subnode.pop().subnode.pop().handles['GET'].pop()
def test_handler(self): req, res = Request(env), Response(start_res) assert req.next.pop(0) == '/' result = u('/').all()( lambda this, req, res: res.push("Test.").ok())._Microwave__handler( req, res) assert isinstance(result, Result) assert result.ok() env['PATH_INFO'] = '/posts/1' req, res = Request(env), Response(start_res) assert req.next.pop(0) == '/' result = u('/').append(u('posts/'), u(':id'))(lambda this, req, res: res.push( req.rest('id')).ok())._Microwave__handler( req, res) assert result.ok() == [b'1'] env['PATH_INFO'] = '/file/img/test.png' req, res = Request(env), Response(start_res) assert req.next.pop(0) == '/' result = u('/').append(u('file/'), u('img/'), u(':!png'))(lambda this, req, res: res.push( req.rest('png')).ok())._Microwave__handler( req, res) assert result.ok() == [b'test.png'] env['PATH_INFO'] = '/error' req, res = Request(env), Response(start_res) assert req.next.pop(0) == '/' result = u('/').err(500)(lambda this, req, res, err: res.push(err).ok( )).all()(lambda this, req, res: res.status(500).err("Test") )._Microwave__handler(req, res) assert result.ok() == [b'Test']
def test_route(self): index = u('index') self.root.route(index)(lambda: True) assert not self.root.subnode[-1].handles['OPTION'] assert self.root.subnode[-1].handles['HEAD'] assert self.root.subnode.pop().handles['GET'].pop()() self.root.route(index, methods=('OPTION', ))(lambda: True) assert self.root.subnode.pop().handles['OPTION'].pop()()
def test_route(self): index = u("index") self.root.route(index)(lambda: True) assert not self.root.subnode[-1].handles["OPTION"] assert self.root.subnode[-1].handles["HEAD"] assert self.root.subnode.pop().handles["GET"].pop()() self.root.route(index, methods=("OPTION",))(lambda: True) assert self.root.subnode.pop().handles["OPTION"].pop()()
def test_handler(self): req, res = Request(env), Response(start_res) assert req.next.pop(0) == "/" result = u("/").all()(lambda this, req, res: res.push("Test.").ok())._Microwave__handler(req, res) assert isinstance(result, Result) assert result.ok() env["PATH_INFO"] = "/posts/1" req, res = Request(env), Response(start_res) assert req.next.pop(0) == "/" result = ( u("/") .append(u("posts/"), u(":id"))(lambda this, req, res: res.push(req.rest("id")).ok()) ._Microwave__handler(req, res) ) assert result.ok() == [b"1"] env["PATH_INFO"] = "/file/img/test.png" req, res = Request(env), Response(start_res) assert req.next.pop(0) == "/" result = ( u("/") .append(u("file/"), u("img/"), u(":!png"))(lambda this, req, res: res.push(req.rest("png")).ok()) ._Microwave__handler(req, res) ) assert result.ok() == [b"test.png"] env["PATH_INFO"] = "/error" req, res = Request(env), Response(start_res) assert req.next.pop(0) == "/" result = ( u("/") .err(500)(lambda this, req, res, err: res.push(err).ok()) .all()(lambda this, req, res: res.status(500).err("Test")) ._Microwave__handler(req, res) ) assert result.ok() == [b"Test"]
#!/usr/bin/env python # encoding: utf-8 from isperdal import Microwave as u from database import db from os import path app = u('/') posts_node = app.then(u('posts/')) @app.append(u('assets/'), u(':!path')) def assets(this, req, res): return res.file(path.join('/path/to/your', res.rest['path'])) @posts_node.get(u(':pid')) def get_posts(this, req, res): body = (yield from db.query(req.rest['pid']).body) return res.push(body).ok() @posts_node.append(u(':pid/'), u('comment'), methods=('POST', )) def add_comment(this, req, res): status = (yield from db.query(req.rest['pid']).update(req.body)) return res.push(status).ok() @posts_node.append(*map(u, [':pid/', 'comment/', ':cid']), methods=('GET', )) def get_comment(this, req, res): comment = (yield from
def test_get(self): self.root.get(u("index/"))(lambda: True) assert not self.root.subnode[-1].handles["OPTION"] assert not self.root.subnode[-1].handles["HEAD"] assert self.root.subnode.pop().handles["GET"].pop()()
def test_then(self): self.root.then(u("index/")).then(u("test")).all()(lambda: True) assert self.root.subnode.pop().subnode.pop().handles["GET"].pop()
#!/usr/bin/env python # encoding: utf-8 from isperdal import Microwave as u app = u('/') @app.all() def logger(this, req, res): print("logger {} {}".format(req.method, req.uri)) @app.get(u(""), u('index')) def index(this, req, res): return res.push("/INDEX").ok() @app.get( u('app/').all()(lambda this, req, res: ('id' in req.session or ( _ for _ in ()).throw(res.redirect('/index'))))) def appindex(this, req, res): return res.push("/APP/").ok() app.run()
def setUp(self): self.root = u("/")
def test_get(self): self.root.get(u('index/'))(lambda: True) assert not self.root.subnode[-1].handles['OPTION'] assert not self.root.subnode[-1].handles['HEAD'] assert self.root.subnode.pop().handles['GET'].pop()()
def test_then(self): self.root.then(u('index/')).then(u('test')).all()(lambda: True) assert self.root.subnode.pop().subnode.pop().handles['GET'].pop()
def test_add(self): index = u('index/').all()(lambda: True) self.root.add(index) assert self.root.subnode.pop().handles['GET'].pop()()
#!/usr/bin/env python # encoding: utf-8 from isperdal import Microwave as u app = u('/') @app.all() def logger(this, req, res): print("logger {} {}".format(req.method, req.uri)) @app.get(u(""), u('index')) def index(this, req, res): return res.push("/INDEX").ok() @app.get(u('app/').all()( lambda this, req, res: ('id' in req.session or (_ for _ in ()).throw(res.redirect('/index'))) )) def appindex(this, req, res): return res.push("/APP/").ok() app.run()
#!/usr/bin/env python # encoding: utf-8 from isperdal import Microwave as u u('/').all()(lambda this, req, res: print("logger {} {}".format(req.method, req.uri)))\ .get(u(""), u('index'))(lambda this, req, res: res.push("INDEX").ok())\ .get(u('app/').all()( lambda this, req, res: ('id' in req.session or (_ for _ in ()).throw(res.redirect('/index'))) ))(lambda this, req, res: res.push("/APP/").ok())\ .run()
def test_add(self): index = u("index/").all()(lambda: True) self.root.add(index) assert self.root.subnode.pop().handles["GET"].pop()()
#!/usr/bin/env python # encoding: utf-8 from isperdal import Microwave as u from database import db from os import path app = u('/') posts_node = app.then(u('posts/')) @app.append(u('assets/'), u(':!path')) def assets(this, req, res): return res.file(path.join('/path/to/your', res.rest['path'])) @posts_node.get(u(':pid')) def get_posts(this, req, res): body = (yield from db.query(req.rest['pid']).body) return res.push(body).ok() @posts_node.append(u(':pid/'), u('comment'), methods=('POST',)) def add_comment(this, req, res): status = (yield from db.query(req.rest['pid']).update(req.body)) return res.push(status).ok() @posts_node.append(*map(u, [':pid/', 'comment/', ':cid']), methods=('GET',)) def get_comment(this, req, res): comment = (yield from db.query(req.rest['pid']).query(req.rest['cid'].comment)) return res.push(comment).ok() app.run()
def setUp(self): self.root = u('/')