微框架
项目描述
Rouver
基于werkzeug的Python 3微框架。
路由
>>> from rouver.router import Router
>>> from rouver.response import respond_with_html, respond_with_json
>>> def get_index(environ, start_response):
... return respond_with_html(start_response, "<div>Foo</div>")
>>> def get_count(environ, start_response):
... return respond_with_json(start_response, {"count": 42})
>>> router = Router()
>>> router.add_routes([
... ("", "GET", get_index),
... ("count", "GET", get_count),
... ])
带占位符的路由
>>> def get_addition(environ, start_response):
... num1, num2 = path
... return response_with_json(start_response, {"result": num1 + num2})
>>> def numeric_arg(request, path, value):
... return int(value)
>>> router.add_template_handler("numeric", numeric_arg)
>>> router.add_routes([
... ("add/{numeric}/{numeric}", "GET", get_addition),
... ])
带通配符的路由
>>> def get_wildcard(environ, start_response):
... # environ["rouver.wildcard_path"] contains the remaining path
... return respond(start_response)
>>> router.add_routes([
... ("wild/*", "GET", get_wildcard),
... ])
子路由器
>>> def get_sub(environ, start_response):
... return respond(start_response)
>>> sub_router = Router()
>>> sub_router.add_routes([
... ("sub", "GET", get_sub),
... ])
>>> router.add_sub_router("parent", sub_router)
参数处理
>>> from rouver.args import Multiplicity, parse_args
>>> from rouver.response import respond_with_json
>>> def get_count_with_args(request, path, start_response):
... args = parse_args(request.environ, [
... ("count", int, Multiplicity.REQUIRED),
... ])
... return respond_with_json({"count": args["count"]})
WSGI测试
>>> from rouver.test import create_request, test_wsgi_app
>>> request = create_request("GET", "/my/path")
>>> response = test_wsgi_app(app, request)
>>> response.assert_status(HTTPStatus.OK)
关闭
rouver-2.6.3.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b5c59f8fb096d0d51c094063c9ee88f70fe5f8c135f93a25a24f64242a0b602f |
|
MD5 | a4465bbc46fb344c41e2219e0eb4e8b8 |
|
BLAKE2b-256 | a4f50c6276b5deda473420ecc4563c38d25be3486032eda6051a02f69b85f5a7 |
关闭
rouver-2.6.3-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f5db1dcb4f0344a2c41484c7cd8363065e19f6792277d37aa2e14919d077333a |
|
MD5 | 3387c1869124ee4e4a7cffc470157535 |
|
BLAKE2b-256 | 5293043603378952b677fca0baf1c83256439b833f7817de4a5c6e3f53642a0c |