本文整理汇总了Python中morepath.traject.Traject.consume方法的典型用法代码示例。如果您正苦于以下问题:Python Traject.consume方法的具体用法?Python Traject.consume怎么用?Python Traject.consume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类morepath.traject.Traject
的用法示例。
在下文中一共展示了Traject.consume方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_traject_variable_specific_first
# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import consume [as 别名]
def test_traject_variable_specific_first():
traject = Traject()
traject.add_pattern('a/{x}/b', 'axb')
traject.add_pattern('a/prefix{x}/b', 'aprefixxb')
assert traject.consume(['b', 'lah', 'a']) == ('axb', [], {'x': 'lah'})
assert traject.consume(['b', 'prefixlah', 'a']) == (
'aprefixxb', [], {'x': 'lah'})
示例2: test_traject_greedy_middle_prefix
# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import consume [as 别名]
def test_traject_greedy_middle_prefix():
traject = Traject()
traject.add_pattern('a/prefix{x}/y', 'prefix')
traject.add_pattern('a/{x}/z', 'no_prefix')
assert traject.consume(['y', 'prefixX', 'a']) == ('prefix', [], {'x': 'X'})
assert traject.consume(['z', 'prefixX', 'a']) == (None, ['z'], {'x': 'X'})
assert traject.consume(['z', 'blah', 'a']) == ('no_prefix', [], {'x': 'blah'})
示例3: test_traject_simple
# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import consume [as 别名]
def test_traject_simple():
traject = Traject()
traject.add_pattern("a/b/c", "abc")
traject.add_pattern("a/b/d", "abd")
traject.add_pattern("x/y", "xy")
traject.add_pattern("x/z", "xz")
assert traject.consume(["c", "b", "a"]) == ("abc", [], {})
assert traject.consume(["d", "b", "a"]) == ("abd", [], {})
assert traject.consume(["y", "x"]) == ("xy", [], {})
assert traject.consume(["z", "x"]) == ("xz", [], {})
assert traject.consume(["d", "c", "b", "a"]) == ("abc", ["d"], {})
assert traject.consume(["d", "d", "b", "a"]) == ("abd", ["d"], {})
assert traject.consume(["3", "2", "1", "y", "x"]) == ("xy", ["3", "2", "1"], {})
assert traject.consume(["3", "2", "1"]) == (None, ["3", "2", "1"], {})
assert traject.consume(["b", "a"]) == (None, [], {})
示例4: test_traject_with_converter
# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import consume [as 别名]
def test_traject_with_converter():
traject = Traject()
traject.add_pattern('{x}', 'found', dict(x=Converter(int)))
assert traject.consume(['1']) == ('found', [], {'x': 1})
assert traject.consume(['foo']) == (None, ['foo'], {})
示例5: test_traject_multiple_steps_with_variables
# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import consume [as 别名]
def test_traject_multiple_steps_with_variables():
traject = Traject()
traject.add_pattern('{x}/{y}', 'xy')
assert traject.consume(['y', 'x']) == ('xy', [], {'x': 'x', 'y': 'y'})
示例6: test_traject_variable_specific_first
# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import consume [as 别名]
def test_traject_variable_specific_first():
traject = Traject()
traject.add_pattern("a/{x}/b", "axb")
traject.add_pattern("a/prefix{x}/b", "aprefixxb")
assert traject.consume(["b", "lah", "a"]) == ("axb", [], {"x": "lah"})
assert traject.consume(["b", "prefixlah", "a"]) == ("aprefixxb", [], {"x": "lah"})