예제 #1
0
    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()
예제 #2
0
    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()
예제 #3
0
    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']
예제 #4
0
    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()()
예제 #5
0
    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()()
예제 #6
0
    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"]
예제 #7
0
#!/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
예제 #8
0
 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()()
예제 #9
0
 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()
예제 #10
0
#!/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()
예제 #11
0
 def setUp(self):
     self.root = u("/")
예제 #12
0
 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()()
예제 #13
0
 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()
예제 #14
0
 def test_add(self):
     index = u('index/').all()(lambda: True)
     self.root.add(index)
     assert self.root.subnode.pop().handles['GET'].pop()()
예제 #15
0
#!/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()
예제 #16
0
#!/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()
예제 #17
0
 def test_add(self):
     index = u("index/").all()(lambda: True)
     self.root.add(index)
     assert self.root.subnode.pop().handles["GET"].pop()()
예제 #18
0
#!/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()
예제 #19
0
 def setUp(self):
     self.root = u('/')