当前位置: 首页>>代码示例>>Python>>正文


Python Traject.consume方法代码示例

本文整理汇总了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'})
开发者ID:AndydeCleyre,项目名称:morepath,代码行数:9,代码来源:test_traject.py

示例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'})
开发者ID:iapilgrim,项目名称:morepath,代码行数:10,代码来源:test_traject.py

示例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, [], {})
开发者ID:reinout,项目名称:morepath,代码行数:18,代码来源:test_traject.py

示例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'], {})
开发者ID:AndydeCleyre,项目名称:morepath,代码行数:7,代码来源:test_traject.py

示例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'})
开发者ID:AndydeCleyre,项目名称:morepath,代码行数:6,代码来源:test_traject.py

示例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"})
开发者ID:reinout,项目名称:morepath,代码行数:8,代码来源:test_traject.py


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