本文整理汇总了Python中webapp2.Route类的典型用法代码示例。如果您正苦于以下问题:Python Route类的具体用法?Python Route怎么用?Python Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Route类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_expr_variable
def test_expr_variable(self):
route = Route(r"/<year:\d{4}>", None)
self.assertEqual(route.match(Request.blank("/bar")), None)
self.assertEqual(route.match(Request.blank("/2010")), (None, (), {"year": "2010"}))
self.assertEqual(route.match(Request.blank("/1900")), (None, (), {"year": "1900"}))
url = route.build(Request.blank("/"), (), dict(year="2010"))
self.assertEqual(url, "/2010")
开发者ID:strogo,项目名称:webapp-improved,代码行数:7,代码来源:test_routing.py
示例2: test_build_extra_keyword
def test_build_extra_keyword(self):
route = Route(r'/<year:\d{4}>', None)
url = route.build(Request.blank('/'), (), dict(year='2010', foo='bar'))
self.assertEqual(url, '/2010?foo=bar')
# Arguments are sorted.
url = route.build(Request.blank('/'), (), dict(year='2010', foo='bar', baz='ding'))
self.assertEqual(url, '/2010?baz=ding&foo=bar')
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:7,代码来源:test_router.py
示例3: test_build_with_unnamed_variable
def test_build_with_unnamed_variable(self):
route = Route(r"/<:\d{4}>/<month:\d{2}>", None)
url = route.build(Request.blank("/"), (2010,), dict(month=10))
self.assertEqual(url, "/2010/10")
url = route.build(Request.blank("/"), ("1999",), dict(month="07"))
self.assertEqual(url, "/1999/07")
开发者ID:strogo,项目名称:webapp-improved,代码行数:8,代码来源:test_routing.py
示例4: test_build_extra_positional_keyword
def test_build_extra_positional_keyword(self):
route = Route(r'/<year:\d{4}>/<:\d{2}>', None)
url = route.build(Request.blank('/'), ('08', 'i-should-be-ignored', 'me-too'), dict(year='2010', foo='bar'))
self.assertEqual(url, '/2010/08?foo=bar')
url = route.build(Request.blank('/'), ('08', 'i-should-be-ignored', 'me-too'), dict(year='2010', foo='bar', baz='ding'))
self.assertEqual(url, '/2010/08?baz=ding&foo=bar')
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:8,代码来源:test_router.py
示例5: test_build_default_keyword
def test_build_default_keyword(self):
route = Route(r"/<year:\d{4}>/<month:\d{2}>", None, defaults={"month": 10})
url = route.build(Request.blank("/"), (), dict(year="2010"))
self.assertEqual(url, "/2010/10")
route = Route(r"/<year:\d{4}>/<month:\d{2}>", None, defaults={"year": 1900})
url = route.build(Request.blank("/"), (), dict(month="07"))
self.assertEqual(url, "/1900/07")
开发者ID:strogo,项目名称:webapp-improved,代码行数:8,代码来源:test_routing.py
示例6: test_simple_variable
def test_simple_variable(self):
route = Route(r'/<foo>', None)
self.assertEqual(
route.match(Request.blank('/bar')),
(route, (), {'foo': 'bar'})
)
url = route.build(Request.blank('/'), (), dict(foo='baz'))
self.assertEqual(url, '/baz')
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:8,代码来源:routing_test.py
示例7: test_build_default_keyword
def test_build_default_keyword(self):
route = Route(r'/<year:\d{4}>/<month:\d{2}>', None,
defaults={'month': 10})
url = route.build(Request.blank('/'), (), dict(year='2010'))
self.assertEqual(url, '/2010/10')
route = Route(r'/<year:\d{4}>/<month:\d{2}>', None,
defaults={'year': 1900})
url = route.build(Request.blank('/'), (), dict(month='07'))
self.assertEqual(url, '/1900/07')
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:10,代码来源:test_router.py
示例8: test_build_extra_positional_keyword
def test_build_extra_positional_keyword(self):
route = Route(r"/<year:\d{4}>/<:\d{2}>", None)
url = route.build(Request.blank("/"), ("08", "i-should-be-ignored", "me-too"), dict(year="2010", foo="bar"))
self.assertEqual(url, "/2010/08?foo=bar")
url = route.build(
Request.blank("/"), ("08", "i-should-be-ignored", "me-too"), dict(year="2010", foo="bar", baz="ding")
)
self.assertEqual(url, "/2010/08?baz=ding&foo=bar")
开发者ID:strogo,项目名称:webapp-improved,代码行数:10,代码来源:test_routing.py
示例9: test_positions
def test_positions(self):
template = '/<:\d+>' * 98
args = tuple(str(i) for i in range(98))
url_res = '/' + '/'.join(args)
route = Route(template, None)
self.assertEqual(route.match(Request.blank(url_res)), (None, args, {}))
url = route.build(Request.blank('/'), args, {})
self.assertEqual(url_res, url)
args = [str(i) for i in range(1000)]
random.shuffle(args)
args = tuple(args[:98])
url_res = '/' + '/'.join(args)
self.assertEqual(route.match(Request.blank(url_res)), (None, args, {}))
url = route.build(Request.blank('/'), args, {})
self.assertEqual(url_res, url)
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:17,代码来源:test_router.py
示例10: test_repetition_operator
def test_repetition_operator(self):
route = Route(r"/<:\d>", None)
self.assertEqual(route.match(Request.blank("/1")), (None, ("1",), {}))
self.assertEqual(route.match(Request.blank("/2")), (None, ("2",), {}))
route = Route(r"/<:\d{2,3}>", None)
self.assertEqual(route.match(Request.blank("/11")), (None, ("11",), {}))
self.assertEqual(route.match(Request.blank("/111")), (None, ("111",), {}))
self.assertEqual(route.match(Request.blank("/1111")), None)
开发者ID:strogo,项目名称:webapp-improved,代码行数:9,代码来源:test_routing.py
示例11: test_unnamed_variable
def test_unnamed_variable(self):
route = Route(r'/<:\d{4}>', None)
self.assertEqual(
route.match(Request.blank('/2010')),
(route, ('2010',), {})
)
self.assertEqual(route.match(Request.blank('/aaaa')), None)
route = Route(r'/<:\d{2}>.<:\d{2}>', None)
self.assertEqual(
route.match(Request.blank('/98.99')),
(route, ('98', '99'), {})
)
self.assertEqual(route.match(Request.blank('/aa.aa')), None)
route = Route(r'/<:\d{2}>.<:\d{2}>/<foo>', None)
self.assertEqual(
route.match(Request.blank('/98.99/test')),
(route, ('98', '99'), {'foo': 'test'})
)
self.assertEqual(route.match(Request.blank('/aa.aa/test')), None)
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:21,代码来源:routing_test.py
示例12: test_reverse_template
def test_reverse_template(self):
route = Route("/foo", None)
template = route.reverse_template or route._reverse_template()
self.assertEqual(template, "/foo")
route = Route("/foo/<bar>", None)
template = route.reverse_template or route._reverse_template()
self.assertEqual(template, "/foo/%(bar)s")
route = Route("/foo/<bar>/<baz:\d>", None)
template = route.reverse_template or route._reverse_template()
self.assertEqual(template, "/foo/%(bar)s/%(baz)s")
开发者ID:strogo,项目名称:webapp-improved,代码行数:12,代码来源:test_routing.py
示例13: test_no_variable
def test_no_variable(self):
route = Route(r"/hello", None)
handler, args, kwargs = route.match(Request.blank("/hello"))
self.assertEqual(kwargs, {})
url = route.build(Request.blank("/"), (), {})
self.assertEqual(url, "/hello")
route = Route(r"/hello/world/", None)
handler, args, kwargs = route.match(Request.blank("/hello/world/"))
self.assertEqual(kwargs, {})
url = route.build(Request.blank("/"), (), {})
self.assertEqual(url, "/hello/world/")
开发者ID:strogo,项目名称:webapp-improved,代码行数:12,代码来源:test_routing.py
示例14: test_unnamed_variable
def test_unnamed_variable(self):
route = Route(r"/<:\d{4}>", None)
self.assertEqual(route.match(Request.blank("/2010")), (None, ("2010",), {}))
self.assertEqual(route.match(Request.blank("/aaaa")), None)
route = Route(r"/<:\d{2}>.<:\d{2}>", None)
self.assertEqual(route.match(Request.blank("/98.99")), (None, ("98", "99"), {}))
self.assertEqual(route.match(Request.blank("/aa.aa")), None)
route = Route(r"/<:\d{2}>.<:\d{2}>/<foo>", None)
self.assertEqual(route.match(Request.blank("/98.99/test")), (None, ("98", "99"), {"foo": "test"}))
self.assertEqual(route.match(Request.blank("/aa.aa/test")), None)
开发者ID:strogo,项目名称:webapp-improved,代码行数:12,代码来源:test_routing.py
示例15: test_schemes
def test_schemes(self):
route = Route(r'/', schemes=['http'])
req = Request.blank('http://mydomain.com/')
self.assertTrue(route.match(req) is not None)
req = Request.blank('https://mydomain.com/')
self.assertTrue(route.match(req) is None)
route = Route(r'/', schemes=['https'])
req = Request.blank('https://mydomain.com/')
self.assertTrue(route.match(req) is not None)
req = Request.blank('http://mydomain.com/')
self.assertTrue(route.match(req) is None)
开发者ID:karlwmacmillan,项目名称:webapp2,代码行数:12,代码来源:routing_test.py
示例16: test_expr_variable2
def test_expr_variable2(self):
route = Route(r"/<year:\d{4}>/foo/", None)
url = route.build(Request.blank("/"), (), dict(year="2010"))
self.assertEqual(url, "/2010/foo/")
开发者ID:strogo,项目名称:webapp-improved,代码行数:4,代码来源:test_routing.py
示例17: test_build_int_keyword
def test_build_int_keyword(self):
route = Route(r"/<year:\d{4}>", None)
url = route.build(Request.blank("/"), (), dict(year=2010))
self.assertEqual(url, "/2010")
开发者ID:strogo,项目名称:webapp-improved,代码行数:4,代码来源:test_routing.py
示例18: test_build_int_variable
def test_build_int_variable(self):
route = Route(r"/<:\d{4}>", None)
url = route.build(Request.blank("/"), (2010,), {})
self.assertEqual(url, "/2010")
开发者ID:strogo,项目名称:webapp-improved,代码行数:4,代码来源:test_routing.py
示例19: test_invalid_template
def test_invalid_template(self):
# To break it:
# <>foo:><bar<:baz>
route = Route("/<foo/<:bar", None)
template = route.reverse_template or route._reverse_template()
self.assertEqual(template, "/<foo/<:bar")
开发者ID:strogo,项目名称:webapp-improved,代码行数:6,代码来源:test_routing.py
示例20: test_simple_variable
def test_simple_variable(self):
route = Route(r"/<foo>", None)
self.assertEqual(route.match(Request.blank("/bar")), (None, (), {"foo": "bar"}))
url = route.build(Request.blank("/"), (), dict(foo="baz"))
self.assertEqual(url, "/baz")
开发者ID:strogo,项目名称:webapp-improved,代码行数:5,代码来源:test_routing.py
注:本文中的webapp2.Route类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论