当前位置: 首页>>代码示例>>Python>>正文


Python Router.install_routes方法代码示例

本文整理汇总了Python中mamba.web.routing.Router.install_routes方法的典型用法代码示例。如果您正苦于以下问题:Python Router.install_routes方法的具体用法?Python Router.install_routes怎么用?Python Router.install_routes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mamba.web.routing.Router的用法示例。


在下文中一共展示了Router.install_routes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: StubController

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
class StubController(object):

    def __init__(self):
        self.path = ''
        self._router = Router()
        self._router.install_routes(self)
        self.children = {}

    def render(self, request):
        return self._router.dispatch(self, request)

    def get_register_path(self):
        return self.path

    @decoroute('/test/<int:user_id>')
    def test(self, request, user_id, **kwargs):
        return 'User ID : {}'.format(user_id)

    @decoroute('/defer')
    @defer.inlineCallbacks
    def deferred(self, request, **kwargs):
        val1 = yield 'Hello '
        val2 = yield 'Defer!'
        defer.returnValue(val1 + val2)

    @decoroute('/209')
    def unknown(self, request, **kwargs):
        pass
开发者ID:DamnWidget,项目名称:mamba,代码行数:30,代码来源:test_web.py

示例2: test_lookup_returns_not_implemented_on_valid_url_invalid_method

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
    def test_lookup_returns_not_implemented_on_valid_url_invalid_method(self):

        controller = StubController()
        request = request_generator(['/test/102'], method='POST')
        router = Router()
        router.install_routes(controller)
        route_dispatcher = RouteDispatcher(router, controller, request)

        self.assertEqual(route_dispatcher.lookup()[0], 'NotImplemented')
开发者ID:DamnWidget,项目名称:mamba,代码行数:11,代码来源:test_web.py

示例3: test_lookup_returns_route

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
    def test_lookup_returns_route(self):

        controller = StubController()
        request = request_generator(['/test/102'])
        router = Router()
        router.install_routes(controller)
        route_dispatcher = RouteDispatcher(router, controller, request)

        self.assertIsInstance(route_dispatcher.lookup()[0], Route)
开发者ID:DamnWidget,项目名称:mamba,代码行数:11,代码来源:test_web.py

示例4: test_dispatch_returns_unknown_209_on_no_return_from_method

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
    def test_dispatch_returns_unknown_209_on_no_return_from_method(self):

        controller = StubController()
        request = request_generator(['/209'], method='GET')
        router = Router()
        router.install_routes(controller)

        self.assertIsInstance(
            router.dispatch(controller, request).result, response.Unknown
        )
开发者ID:DamnWidget,项目名称:mamba,代码行数:12,代码来源:test_web.py

示例5: test_install_router_fails_when_give_wrong_arguments

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
    def test_install_router_fails_when_give_wrong_arguments(self):

        router = Router()

        @decoroute('/test')
        def test(self, request, user_id, **kwargs):
            return 'I will fail'

        StubController.test2 = test
        router.install_routes(StubController())

        # only one of the routes should be installed
        self.assertTrue(len(router.routes['GET']) == 3)
开发者ID:DamnWidget,项目名称:mamba,代码行数:15,代码来源:test_web.py

示例6: test_install_several_HTTP_methods_per_route_decorator

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
    def test_install_several_HTTP_methods_per_route_decorator(self):

        router = Router()

        class MyStubController(StubController):
            @decoroute('/multimethod_test', method=['GET', 'POST'])
            def multimethod_test(self, request, **kwargs):
                return None

        router.install_routes(MyStubController())

        self.assertTrue(len(router.routes['GET']) == 4)
        self.assertTrue(len(router.routes['POST']) == 1)
        self.assertEqual(
            router.routes['GET']['/multimethod_test'],
            router.routes['POST']['/multimethod_test']
        )
开发者ID:DamnWidget,项目名称:mamba,代码行数:19,代码来源:test_web.py

示例7: test_install_routes_register_route

# 需要导入模块: from mamba.web.routing import Router [as 别名]
# 或者: from mamba.web.routing.Router import install_routes [as 别名]
    def test_install_routes_register_route(self):

        router = Router()
        router.install_routes(StubController())

        self.assertTrue(len(router.routes['GET']) == 3)

        del router
        router = Router()

        class MyStubController(StubController):
            @decoroute('/another_test')
            def another_test(self, request, **kwargs):
                return None

        router.install_routes(MyStubController())

        self.assertTrue(len(router.routes['GET']) == 4)
开发者ID:DamnWidget,项目名称:mamba,代码行数:20,代码来源:test_web.py


注:本文中的mamba.web.routing.Router.install_routes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。