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


Python traject.Traject类代码示例

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


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


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