Beispiel #1
0
def register_path(app, model, path, variables, converters, required,
                  model_factory, arguments=None):
    traject = app.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)
Beispiel #2
0
def register_path(app, model, path, variables, converters, required,
                  get_converters, model_factory, arguments=None):
    traject = app.traject

    converters = converters or {}
    if get_converters is not None:
        converters.update(get_converters())
    if arguments is None:
        arguments = get_arguments(model_factory, SPECIAL_ARGUMENTS)
    converters = app.argument_and_explicit_converters(arguments, converters)
    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,
                                         'extra_parameters' in arguments)
    if variables is None:
        variables = get_variables_func(arguments, app.mount_variables())

    traject.add_pattern(path, (model_factory, parameter_factory),
                        converters)

    inverse = Inverse(path, variables, converters, parameters.keys())
    app.register(generic.path, [model], inverse)
Beispiel #3
0
def test_path_discriminator():
    p = Path('/foo/{x}/bar/{y}')
    assert p.discriminator() == 'foo/{}/bar/{}'
Beispiel #4
0
def test_path_discriminator():
    p = Path('/foo/{x:int}/bar/{y}')
    assert p.discriminator() == 'foo/{int}/bar/{str}'
Beispiel #5
0
def test_path_discriminator():
    p = Path("/foo/{x}/bar/{y}")
    assert p.discriminator() == "foo/{}/bar/{}"
Beispiel #6
0
def test_path_discriminator():
    p = Path('/foo/{x}/bar/{y}')
    assert p.discriminator() == 'foo/{}/bar/{}'
Beispiel #7
0
def test_interpolation_str():
    assert Path('{foo} is {bar}').interpolation_str() == '%(foo)s is %(bar)s'
Beispiel #8
0
def test_path_discriminator():
    p = Path("/foo/{x}/bar/{y}")
    assert p.discriminator() == "foo/{}/bar/{}"
Beispiel #9
0
def test_interpolation_str():
    assert Path("{foo} is {bar}").interpolation_str() == "%(foo)s is %(bar)s"