本文整理汇总了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;未经允许,请勿转载。 |
请发表评论