与itty类似,但使用webob请求、响应和异常对象
wee的Python项目详细描述
你可以叫它webob-augmenteditty。它借用了它的形式但是 允许使用传入的请求或响应对象。由 默认情况下,它使用来自webob以及webob的请求和响应。
为什么?
我们和它一起工作,头撞了几下。我们真的 喜欢它的工作方式 收藏的请求和响应对象。106行之后,wee出生了 作为wsgi应用程序的调度程序。
基本用法
这里有一个超级简单的小马应用程序来展示WEE的基本知识。漂亮的 与itty基本相同,只是我们使用了完整的regex字符串:
import wee from wsgiref.simple_server import make_server @wee.get(r'^/$') def ponytime(request): return "It's Pony time!" @wee.post(r'^/$'): def make_pony(request): ... make a pony ... @wee.put('^/(?P<pony_name>\w+)$'): def add_unicorn_horn(request, pony_name=None): ... change a pony ... @wee.delete('^/(?P<pony_name>\w+)$'): def kill_a_pony(request, pony_name): ... delete a pony ... srv = make_server(host, port, wee.make_app()) srv.serve_forever()
使用前缀
有时候你想在现有的应用程序树上挂上一个小应用程序。import wee @wee.get('^/$') def logical_root(request): return "I'm an index" registry = wee.PrefixRegistry(prefix='/my/crazy/existing/dispatch/tree') wee.make_app(registry=prefix)
实验性静止容器支持
对于创建简单的crud容器有一些粗略的支持,比如 所以:
import wee @wee.rest("^/candymountain") class UnicornStable(wee.Resource): subtype = 'unicorn_id' def get(self): ... your list of unicorns ... def post(self): name = self.request.POST['unicorn-name'] ... make a unicorn ... def getitem(self, unicorn_id): ... serve a unicorn ... def put(self, unicorn_id): ... change a unicorn ... def delete(self, unicorn_id): ... kill a unicorn ...
rest动词生成一系列正则表达式,以便在 适当的动词要特别注意分开“get”(/)和 “getitem”(/some\u id)。
与ITty的其他差异
唯一的另一个主要区别是调度的范围是 定义处理程序的模块。这意味着多个WEE应用程序可以运行 在相同的过程中没有互相残杀。
我们也不给你运行命令,也不给流行的任何适配器 框架。也许以后吧。
覆盖范围
coverage.py目前说是100%,但我们可以有更多的单元测试 与堆栈测试。
等等,我很困惑……
“我什么时候用它,什么时候用wee?“
你可能也不该用。这是个实验,所以看起来 就这样吧。
不过,如果你很勇敢,当你想做某事或 像西纳特拉,但正在使用webob。当你想要的时候就用它 完全包含在自身中,不需要太多依赖项 要尽快运行的配置。