• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python webapp2.Router类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webapp2.Router的典型用法代码示例。如果您正苦于以下问题:Python Router类的具体用法?Python Router怎么用?Python Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_set_matcher

    def test_set_matcher(self):
        req = Request.blank('/')
        def custom_matcher(router, request):
            self.assertEqual(request, req)

        router = Router(None)
        router.set_matcher(custom_matcher)
        router.match(req)
开发者ID:karlwmacmillan,项目名称:webapp2,代码行数:8,代码来源:routing_test.py


示例2: test_router_build_error

    def test_router_build_error(self):
        router = Router()
        router.add(Route('/<year:\d{4}>', None, name='year-page'))

        url = router.build('year-page', Request.blank('/'), (), dict(year='2010'))
        self.assertEqual(url, '/2010')

        self.assertRaises(KeyError, router.build, 'i-dont-exist', Request.blank('/'), (), dict(year='2010'))
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:8,代码来源:test_router.py


示例3: test_router_build_error

    def test_router_build_error(self):
        router = Router(None)
        router.add(Route("/<year:\d{4}>", None, name="year-page"))

        url = router.build("year-page", Request.blank("/"), (), dict(year="2010"))
        self.assertEqual(url, "/2010")

        self.assertRaises(KeyError, router.build, "i-dont-exist", Request.blank("/"), (), dict(year="2010"))
开发者ID:strogo,项目名称:webapp-improved,代码行数:8,代码来源:test_routing.py


示例4: test_set_builder

    def test_set_builder(self):
        req = Request.blank('/')
        def custom_builder(router, request, name, args, kwargs):
            self.assertEqual(request, req)
            return 'http://www.google.com'

        router = Router(None)
        router.set_builder(custom_builder)
        res = router.build(req, '', (), {})
        self.assertEqual(res, 'http://www.google.com')
开发者ID:karlwmacmillan,项目名称:webapp2,代码行数:10,代码来源:routing_test.py


示例5: test_methods

 def test_methods(self):
     route = Route(r'/', methods=['GET', 'POST'])
     router = Router([route])
     req = Request.blank('/')
     req.method = 'GET'
     self.assertTrue(router.match(req) is not None)
     req.method = 'POST'
     self.assertTrue(router.match(req) is not None)
     req.method = 'PUT'
     self.assertRaises(webapp2.exc.HTTPMethodNotAllowed, router.match, req)
开发者ID:karlwmacmillan,项目名称:webapp2,代码行数:10,代码来源:routing_test.py


示例6: test_build_full_without_request

 def test_build_full_without_request(self):
     router = Router(None)
     router.add(Route(r'/hello', None, name='hello'))
     self.assertRaises(
         AttributeError,
         router.build, None, 'hello', (), dict(_full=True)
     )
     self.assertRaises(
         AttributeError,
         router.build, None, 'hello', (), dict(_scheme='https')
     )
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:11,代码来源:routing_test.py


示例7: test_with_variables_name_and_handler

    def test_with_variables_name_and_handler(self):
        router = Router(None, [
            PathPrefixRoute('/user/<username:\w+>', [
                HandlerPrefixRoute('apps.users.', [
                    NamePrefixRoute('user-', [
                        Route('/', 'UserOverviewHandler', 'overview'),
                        Route('/profile', 'UserProfileHandler', 'profile'),
                        Route('/projects', 'UserProjectsHandler', 'projects'),
                    ]),
                ]),
            ])
        ])

        path = '/user/calvin/'
        match = ('apps.users.UserOverviewHandler', (), {'username': 'calvin'})
        self.assertEqual(router.match(Request.blank(path)), match)
        self.assertEqual(router.build('user-overview', Request.blank('/'), match[1], match[2]), path)

        path = '/user/calvin/profile'
        match = ('apps.users.UserProfileHandler', (), {'username': 'calvin'})
        self.assertEqual(router.match(Request.blank(path)), match)
        self.assertEqual(router.build('user-profile', Request.blank('/'), match[1], match[2]), path)

        path = '/user/calvin/projects'
        match = ('apps.users.UserProjectsHandler', (), {'username': 'calvin'})
        self.assertEqual(router.match(Request.blank(path)), match)
        self.assertEqual(router.build('user-projects', Request.blank('/'), match[1], match[2]), path)
开发者ID:martinc,项目名称:webapp-improved,代码行数:27,代码来源:test_routing_extra.py


示例8: include

def include(prefix, routes):
    if isinstance(routes, StringTypes):
        routes = import_class('%s.routes' % routes)
    elif hasattr(routes, 'routes'):
        routes = routes.routes

    routes = [ Router.route_class(*route) if isinstance(route, tuple) else route for route in routes ]

    return PathPrefixRoute(prefix, routes)
开发者ID:assekalala,项目名称:gap,代码行数:9,代码来源:routes.py


示例9: test_simple

    def test_simple(self):
        SUBDOMAIN_RE = '^([^.]+)\.app-id\.appspot\.com$'

        router = Router(None, [
            DomainRoute(SUBDOMAIN_RE, [
                Route('/foo', 'FooHandler', 'subdomain-thingie'),
            ])
        ])

        match = router.match(Request.blank('/foo'))
        self.assertEqual(match, None)

        match = router.match(Request.blank('http://my-subdomain.app-id.appspot.com/foo'))
        self.assertEqual(match, ('FooHandler', (), {'_host_match': ('my-subdomain',)}))

        match = router.match(Request.blank('http://another-subdomain.app-id.appspot.com/foo'))
        self.assertEqual(match, ('FooHandler', (), {'_host_match': ('another-subdomain',)}))

        url = router.build('subdomain-thingie', None, (), {'_netloc': 'another-subdomain.app-id.appspot.com'})
        self.assertEqual(url, 'http://another-subdomain.app-id.appspot.com/foo')
开发者ID:martinc,项目名称:webapp-improved,代码行数:20,代码来源:test_routing_extra.py


示例10: test_router_repr

    def test_router_repr(self):
        router = Router(None)
        router.add(Route(r"/hello", None, name="hello", build_only=True))
        router.add(Route(r"/world", None))

        self.assertEqual(
            router.__repr__(),
            "<Router([<Route('/world', None, name=None, defaults={}, build_only=False)>, <Route('/hello', None, name='hello', defaults={}, build_only=True)>])>",
        )
开发者ID:strogo,项目名称:webapp-improved,代码行数:9,代码来源:test_routing.py


示例11: test_router_repr

    def test_router_repr(self):
        router = Router()
        router.add(Route(r'/hello', None, name='hello', build_only=True))
        router.add(Route(r'/world', None))

        self.assertEqual(router.__repr__(), "Router([Route('/world', None, name=None, defaults={}, build_only=False), Route('/hello', None, name='hello', defaults={}, build_only=True)])")
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:6,代码来源:test_router.py


示例12: test_build_full_without_request

 def test_build_full_without_request(self):
     router = Router(None)
     router.add(Route(r"/hello", None, name="hello"))
     self.assertRaises(AttributeError, router.build, "hello", None, (), dict(_full=True))
     self.assertRaises(AttributeError, router.build, "hello", None, (), dict(_scheme="https"))
开发者ID:strogo,项目名称:webapp-improved,代码行数:5,代码来源:test_routing.py


示例13: test_no_variable

    def test_no_variable(self):
        router = Router(None, [(r'/', 'my_handler')])

        matched_route, args, kwargs = router.match(Request.blank('/'))
        self.assertEqual(args, ())
        self.assertEqual(kwargs, {})
开发者ID:martinc,项目名称:webapp-improved,代码行数:6,代码来源:test_routing_simple.py


示例14: test_simple_variables

    def test_simple_variables(self):
        router = Router(None, [(r'/(\d{4})/(\d{2})', 'my_handler')])

        matched_route, args, kwargs = router.match(Request.blank('/2007/10'))
        self.assertEqual(args, ('2007', '10'))
        self.assertEqual(kwargs, {})
开发者ID:martinc,项目名称:webapp-improved,代码行数:6,代码来源:test_routing_simple.py


示例15: test_route_redirect_to

 def test_route_redirect_to(self):
     router = Router(None, [ImprovedRoute('/foo', redirect_to='/bar')])
     handler, args, kwargs = router.match(Request.blank('/foo'))
     self.assertEqual(handler, RedirectHandler)
     self.assertEqual(args, ())
     self.assertEqual(kwargs, {'url': '/bar'})
开发者ID:martinc,项目名称:webapp-improved,代码行数:6,代码来源:test_routing_extra.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.User类代码示例发布时间:2022-05-26
下一篇:
Python webapp2.Route类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap