本文整理汇总了Python中types.ModuleType.handler2方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.handler2方法的具体用法?Python ModuleType.handler2怎么用?Python ModuleType.handler2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.handler2方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple_config
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import handler2 [as 别名]
def test_simple_config(self):
module = ModuleType('module')
module.handler1 = lambda: sentinel.a2
module.handler2 = lambda a1, a2: (a1, a2, sentinel.result)
config = '''
index /{a1:\d+} (a1: int):
handler1 (a2)
handler2
'''
router = configparser.parse_config(config.splitlines(), module)
self.assertEqual(router.reverse('index', a1=37), '/37')
ctx = Context(path_info='/42')
self.assertEqual(
ctx.inject(router),
(42, sentinel.a2, sentinel.result)
)
示例2: test_complex_config
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import handler2 [as 别名]
def test_complex_config(self):
module = ModuleType('module')
module.exc1 = type('exc1', (Exception,), {})
module.exc2 = type('exc2', (Exception,), {})
module.exc3 = type('exc3', (Exception,), {})
module.handler1 = lambda: sentinel.a2
module.handler2 = lambda a1, a2: (a1, a2, sentinel.result)
module.handler3 = lambda: Mock(side_effect=module.exc2)()
module.handler4 = lambda: sentinel.a4
module.handler5 = lambda: sentinel.a5
module.handler6 = lambda r1: (r1, sentinel.a6)
module.handler7 = lambda: sentinel.a7
module.handler8 = lambda: sentinel.a8
module.handler9 = lambda r1, r2: (r1, r2, sentinel.a9)
config = """
index /:
* GET, HEAD:
handler1 (a2)
handler2
* POST:
handler1
todo /{todo_id:\d+} (todo_id: int):
* GET, HEAD:
handler3 (r1):
exc1, exc2: handler4
exc3: handler5
handler6
other /foo:
handler7 (r1)
* DELETE:
handler8 (r2)
handler9
"""
router = configparser.parse_config(config.splitlines(), module)
ctx = Context(path_info='/42', request_method='GET')
self.assertEqual(ctx.inject(router), (sentinel.a4, sentinel.a6))
ctx = Context(path_info='/foo', request_method='DELETE')
self.assertEqual(
ctx.inject(router),
(sentinel.a7, sentinel.a8, sentinel.a9)
)
示例3: test_medium_config
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import handler2 [as 别名]
def test_medium_config(self):
module = ModuleType('module')
module.handler1 = lambda: sentinel.a2
module.handler2 = lambda a1, a2: (a1, a2, sentinel.result)
config = '''
index /{a1:\d+} (a1: int):
* GET, HEAD:
handler1 (a2)
handler2
* POST:
handler1
'''
router = configparser.parse_config(config.splitlines(), module)
self.assertEqual(router.reverse('index', a1=37), '/37')
ctx = Context(path_info='/42', request_method='GET')
self.assertEqual(
ctx.inject(router),
(42, sentinel.a2, sentinel.result)
)
ctx = Context(path_info='/42', request_method='POST')
self.assertIs(ctx.inject(router), sentinel.a2)