當前位置: 首頁>>代碼示例>>Python>>正文


Python routing.Router類代碼示例

本文整理匯總了Python中mamba.web.routing.Router的典型用法代碼示例。如果您正苦於以下問題:Python Router類的具體用法?Python Router怎麽用?Python Router使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Router類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: StubController

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,代碼行數:28,代碼來源:test_web.py

示例2: test_process_error

    def test_process_error(self):

        router = Router()
        request = request_generator('/test')

        resp = router._process_error('fake_result', request=request)
        self.assertIsInstance(resp, response.InternalServerError)
        self.assertEqual(resp.code, 500)
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:8,代碼來源:test_web.py

示例3: test_lookup_returns_not_implemented_on_valid_url_invalid_method

    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,代碼行數:9,代碼來源:test_web.py

示例4: test_lookup_returns_route

    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,代碼行數:9,代碼來源:test_web.py

示例5: test_register_route

    def test_register_route(self):

        router = Router()
        ctl = StubController()
        self.assertTrue(len(router.routes['GET']) == 0)
        route = Route('GET', '/defer', ctl.deferred)
        router.register_route(ctl, route, ctl.deferred)
        self.assertTrue(len(router.routes['GET']) == 1)
        self.assertTrue('/defer' in router.routes['GET'])
        self.assertTrue('StubController' in router.routes['GET']['/defer'])
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:10,代碼來源:test_web.py

示例6: test_dispatch_returns_unknown_209_on_no_return_from_method

    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,代碼行數:10,代碼來源:test_web.py

示例7: test_route_decorator

    def test_route_decorator(self):

        router = Router()
        decorator = router.route('/decorator_test')

        def test(self, request, **kwargs):
            return None

        decorated_func = decorator(test)
        self.assertIsInstance(decorated_func.route, Route)
        self.assertEqual(decorated_func.route.url, '/decorator_test')
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:11,代碼來源:test_web.py

示例8: test_process_return_objects_json_converted

    def test_process_return_objects_json_converted(self):

        router = Router()
        request = request_generator('/test')

        class FakeResult(object):
            name = 'Test'
            type = 'JSON'

        resp = router._process(FakeResult(), request)
        self.assertIsInstance(resp, response.Ok)
        self.assertEqual(resp.subject, {'name': 'Test', 'type': 'JSON'})
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:12,代碼來源:test_web.py

示例9: test_install_router_fails_when_give_wrong_arguments

    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,代碼行數:13,代碼來源:test_web.py

示例10: test_install_several_HTTP_methods_per_route_decorator

    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,代碼行數:17,代碼來源:test_web.py

示例11: test_process_serialize_object_inside_objects

    def test_process_serialize_object_inside_objects(self):

        import decimal

        router = Router()
        request = request_generator('/test')

        class FakeData(object):
            data = 'hdsihas8h9277t27gsj'
            pepe = decimal.Decimal('10.0')

        class FakeResult(object):
            name = 'Test'
            data = FakeData()

        resp = router._process(FakeResult(), request)
        self.assertIsInstance(resp, response.Ok)
        self.assertEqual(resp.subject, {
            'data': {'pepe': '10.0', 'data': 'hdsihas8h9277t27gsj'},
            'name': 'Test'
        })
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:21,代碼來源:test_web.py

示例12: test_install_routes_register_route

    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,代碼行數:18,代碼來源:test_web.py

示例13: __init__

 def __init__(self):
     self.path = ''
     self._router = Router()
     self._router.install_routes(self)
     self.children = {}
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:5,代碼來源:test_web.py

示例14: test_process_return_unknown_on_none_result

    def test_process_return_unknown_on_none_result(self):

        router = Router()
        self.assertIsInstance(router._process(None, None), response.Unknown)
開發者ID:DamnWidget,項目名稱:mamba,代碼行數:4,代碼來源:test_web.py


注:本文中的mamba.web.routing.Router類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。