• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python traject.Traject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中morepath.traject.Traject的典型用法代码示例。如果您正苦于以下问题:Python Traject类的具体用法?Python Traject怎么用?Python Traject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Traject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    app = App()

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result
    traject.register('{first_id}', get_model)
    traject.register('{first_id}/{second_id}', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, obj, stack = traject_consumer(app, parse_path('a'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    assert obj.first_id == 'a'
    assert not hasattr(obj, 'second_id')
    found, obj, stack = traject_consumer(app, parse_path('a/b'), Lookup(app))
    assert found
    assert isinstance(obj, Special)
    assert stack == []
    assert obj.first_id == 'a'
    assert obj.second_id == 'b'
开发者ID:kingel,项目名称:morepath,代码行数:31,代码来源:test_traject.py


示例2: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    app = App()

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.register('{id}', get_model)
    traject.register('{id}/sub', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, obj, stack = traject_consumer(app, parse_path('a'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    found, obj, stack = traject_consumer(app, parse_path('b'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    found, obj, stack = traject_consumer(app, parse_path('a/sub'), Lookup(app))
    assert found
    assert isinstance(obj, Special)
    assert stack == []
开发者ID:kingel,项目名称:morepath,代码行数:31,代码来源:test_traject.py


示例3: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    class app(morepath.App):
        pass

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result
    traject.add_pattern('{first_id}', (get_model, paramfac))
    traject.add_pattern('{first_id}/{second_id}', (get_special, paramfac))

    registry = app.registry
    registry.register(generic.traject, [App], lambda base: traject)
    registry.register(generic.context, [object], lambda obj: {})

    found, request = consume(app(), 'a')
    assert isinstance(found, Model)
    assert found.first_id == 'a'
    assert not hasattr(found, 'second_id')
    assert request.unconsumed == []

    found, request = consume(app(), 'a/b')
    assert isinstance(found, Special)
    assert found.first_id == 'a'
    assert found.second_id == 'b'
    assert request.unconsumed == []
开发者ID:io41,项目名称:morepath,代码行数:34,代码来源:test_traject.py


示例4: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    app = App()

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.add_pattern("{id}", (get_model, paramfac))
    traject.add_pattern("{id}/sub", (get_special, paramfac))
    app.register(generic.traject, [App], lambda base: traject)
    app.register(generic.context, [object], lambda obj: {})

    found, request = consume(app, "a")
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, "b")
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, "a/sub")
    assert isinstance(found, Special)
    assert request.unconsumed == []
开发者ID:pombredanne,项目名称:morepath,代码行数:29,代码来源:test_traject.py


示例5: test_traject_consume_combination

def test_traject_consume_combination():

    class app(morepath.App):
        pass

    traject = Traject()

    def get_model(foo):
        result = Model()
        result.foo = foo
        return result

    traject.add_pattern('special', (Special, paramfac))
    traject.add_pattern('{foo}', (get_model, paramfac))

    registry = app.registry
    registry.register(generic.traject, [App], lambda base: traject)
    registry.register(generic.context, [object], lambda obj: {})

    found, request = consume(app(), 'something')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    assert found.foo == 'something'

    found, request = consume(app(), 'special')
    assert isinstance(found, Special)
    assert request.unconsumed == []
开发者ID:io41,项目名称:morepath,代码行数:27,代码来源:test_traject.py


示例6: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    class app(morepath.App):
        pass

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.add_pattern('{id}', (get_model, paramfac))
    traject.add_pattern('{id}/sub', (get_special, paramfac))

    registry = app.registry

    registry.register(generic.traject, [App], lambda base: traject)
    registry.register(generic.context, [object], lambda obj: {})

    found, request = consume(app(), 'a')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app(), 'b')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app(), 'a/sub')
    assert isinstance(found, Special)
    assert request.unconsumed == []
开发者ID:io41,项目名称:morepath,代码行数:33,代码来源:test_traject.py


示例7: register_path

def register_path(app, model, path, variables, converters, required,
                  model_factory, arguments=None):
    traject = app.traject
    if traject is None:
        traject = Traject()
        app.traject = traject

    converters = converters or {}
    if arguments is None:
        arguments = get_arguments(model_factory, SPECIAL_ARGUMENTS)
    converters = get_converters(arguments, converters,
                                app.converter_for_type, app.converter_for_value)
    exclude = Path(path).variables()
    exclude.update(app.mount_variables())
    parameters = get_url_parameters(arguments, exclude)
    if required is None:
        required = set()
    required = set(required)
    parameter_factory = ParameterFactory(parameters, converters, required)

    if variables is None:
        variables = get_variables_func(arguments, app.mount_variables())

    traject.add_pattern(path, (model_factory, parameter_factory),
                        converters)
    traject.inverse(model, path, variables, converters, list(parameters.keys()))


    def get_app(model):
        return app

    app.register(generic.app, [model], get_app)
开发者ID:iapilgrim,项目名称:morepath,代码行数:32,代码来源:path.py


示例8: test_traject_consume_parameter

def test_traject_consume_parameter():
    class app(morepath.App):
        pass

    traject = Traject()

    class Model(object):
        def __init__(self, a):
            self.a = a

    get_param = ParameterFactory({'a': 0}, {'a': Converter(int)}, [])
    traject.add_pattern('sub', (Model, get_param))

    registry = app.registry
    registry.register(generic.traject, [App], lambda base: traject)
    registry.register(generic.context, [object], lambda obj: {})

    found, request = consume(app(), 'sub?a=1')
    assert isinstance(found, Model)
    assert found.a == 1
    assert request.unconsumed == []
    found, request = consume(app(), 'sub')
    assert isinstance(found, Model)
    assert found.a == 0
    assert request.unconsumed == []
开发者ID:io41,项目名称:morepath,代码行数:25,代码来源:test_traject.py


示例9: test_traject_with_converter_and_fallback3

def test_traject_with_converter_and_fallback3():
    traject = Traject()
    # XXX should have a conflict
    traject.add_pattern('{x:str}', 'found_explicit')
    traject.add_pattern('{x}', 'found_implicit')

    assert traject(['foo']) == ('found_explicit', [], {'x': 'foo'})
开发者ID:kod3r,项目名称:morepath,代码行数:7,代码来源:test_traject.py


示例10: test_traject_with_converter_and_fallback2

def test_traject_with_converter_and_fallback2():
    traject = Traject()
    traject.add_pattern('{x}', 'found_str')
    traject.add_pattern('{x:int}', 'found_int')

    assert traject(['1']) == ('found_int', [], {'x': 1})
    assert traject(['foo']) == ('found_str', [], {'x': 'foo'})
开发者ID:kod3r,项目名称:morepath,代码行数:7,代码来源:test_traject.py


示例11: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    app = App()

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.add_pattern('{id}', get_model)
    traject.add_pattern('{id}/sub', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, 'a')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, 'b')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, 'a/sub')
    assert isinstance(found, Special)
    assert request.unconsumed == []
开发者ID:kod3r,项目名称:morepath,代码行数:28,代码来源:test_traject.py


示例12: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    app = App()

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result
    traject.add_pattern('{first_id}', get_model)
    traject.add_pattern('{first_id}/{second_id}', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, 'a')
    assert isinstance(found, Model)
    assert found.first_id == 'a'
    assert not hasattr(found, 'second_id')
    assert request.unconsumed == []

    found, request = consume(app, 'a/b')
    assert isinstance(found, Special)
    assert found.first_id == 'a'
    assert found.second_id == 'b'
    assert request.unconsumed == []
开发者ID:kod3r,项目名称:morepath,代码行数:30,代码来源:test_traject.py


示例13: test_traject_no_duplicate_variables

def test_traject_no_duplicate_variables():
    traject = Traject()

    with pytest.raises(TrajectError):
        traject.add_pattern('{foo}-{foo}', 'value')
    with pytest.raises(TrajectError):
        traject.add_pattern('{foo}/{foo}', 'value')
开发者ID:kod3r,项目名称:morepath,代码行数:7,代码来源:test_traject.py


示例14: test_traject_consumer_combination

def test_traject_consumer_combination():
    app = App()

    traject = Traject()

    def get_model(foo):
        result = Model()
        result.foo = foo
        return result

    traject.register('special', Special)
    traject.register('{foo}', get_model)
    app.register(generic.traject, [App], lambda base: traject)

    found, obj, stack = traject_consumer(app, parse_path('something'),
                                         Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    assert obj.foo == 'something'
    found, obj, stack = traject_consumer(app, parse_path('special'),
                                         Lookup(app))
    assert found
    assert isinstance(obj, Special)
    assert stack == []
开发者ID:kingel,项目名称:morepath,代码行数:25,代码来源:test_traject.py


示例15: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    app = App()

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result

    traject.add_pattern("{first_id}", (get_model, paramfac))
    traject.add_pattern("{first_id}/{second_id}", (get_special, paramfac))
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, "a")
    assert isinstance(found, Model)
    assert found.first_id == "a"
    assert not hasattr(found, "second_id")
    assert request.unconsumed == []

    found, request = consume(app, "a/b")
    assert isinstance(found, Special)
    assert found.first_id == "a"
    assert found.second_id == "b"
    assert request.unconsumed == []
开发者ID:reinout,项目名称:morepath,代码行数:31,代码来源:test_traject.py


示例16: test_traject_no_concecutive_variables

def test_traject_no_concecutive_variables():
    traject = Traject()

    def get_model(foo, bar):
        return Model()

    with py.test.raises(TrajectError):
        traject.register('{foo}{bar}', get_model)
开发者ID:kingel,项目名称:morepath,代码行数:8,代码来源:test_traject.py


示例17: test_traject_consume

def test_traject_consume():
    app = App()
    traject = Traject()
    traject.add_pattern('sub', Model)
    app.register(generic.traject, [App], lambda base: traject)
    found, request = consume(app, 'sub')
    assert isinstance(found, Model)
    assert request.unconsumed == []
开发者ID:kod3r,项目名称:morepath,代码行数:8,代码来源:test_traject.py


示例18: test_traject_greedy_middle_prefix

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(['y', 'prefixX', 'a']) == ('prefix', [], {'x': 'X'})
    assert traject(['z', 'prefixX', 'a']) == (None, ['z'], {'x': 'X'})
    assert traject(['z', 'blah', 'a']) == ('no_prefix', [], {'x': 'blah'})
开发者ID:kod3r,项目名称:morepath,代码行数:8,代码来源:test_traject.py


示例19: test_traject_greedy_middle_converter

def test_traject_greedy_middle_converter():
    traject = Traject()
    traject.add_pattern('a/{x:int}/y', 'int')
    traject.add_pattern('a/{x}/z', 'str')

    assert traject(['y', '1', 'a']) == ('int', [], {'x': 1})
    assert traject(['z', '1', 'a']) == (None,  ['z'], {'x': 1})
    assert traject(['z', 'x', 'a']) == ('str', [], {'x': 'x'})
开发者ID:kod3r,项目名称:morepath,代码行数:8,代码来源:test_traject.py


示例20: test_traject_conflicting_type_registrations

def test_traject_conflicting_type_registrations():
    traject = Traject()

    def get_model(foo):
        return Model()

    traject.register('{foo:str}', get_model)
    with py.test.raises(TrajectError):
        traject.register('{foo:int}', get_model)
开发者ID:kingel,项目名称:morepath,代码行数:9,代码来源:test_traject.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tween.TweenRegistry类代码示例发布时间:2022-05-27
下一篇:
Python traject.Step类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap