hy/site/shim.py

47 lines
1010 B
Python
Raw Normal View History

2013-03-10 04:45:08 +01:00
#
2013-03-10 04:47:25 +01:00
import hy # NOQA
2013-03-10 04:45:08 +01:00
from hy.models.expression import HyExpression
from hy.models.symbol import HySymbol
2013-03-10 15:30:03 +01:00
from hy.models.string import HyString
from hy.models.list import HyList
from hy.models.dict import HyDict
2013-03-10 04:45:08 +01:00
from hy.macros import macro
2013-03-10 15:30:03 +01:00
def router(tree, rkwargs=None):
2013-03-10 04:45:08 +01:00
tree.pop(0)
path = tree.pop(0)
tree.insert(0, HySymbol("fn"))
2013-03-10 15:30:03 +01:00
route = HyExpression([HySymbol(".route"),
HySymbol("app"),
path])
if rkwargs:
route = HyExpression([HySymbol("kwapply"),
route,
HyDict({HyString("methods"): rkwargs})])
2013-03-10 04:45:08 +01:00
return HyExpression([HySymbol("decorate_with"),
2013-03-10 15:30:03 +01:00
route,
tree])
@macro("route")
def route_macro(tree):
return router(tree)
@macro("post_route")
def route_macro(tree):
return router(tree, rkwargs=HyList([HyString("POST")]))
2013-03-10 04:45:08 +01:00
from app import app
if __name__ == '__main__':
app.run(debug=True)