コード例 #1
0
ファイル: utils.py プロジェクト: cbernet/patacrep
def validate_yaml_schema(data, schema):
    """Check that the data respects the schema

    Will raise `SchemaError` if the schema is not respected.
    """
    schema = Rx.make_schema(schema)

    if isinstance(data, DictOfDict):
        data = dict(data)

    try:
        schema.validate(data)
    except Rx.SchemaMismatch as exception:
        raise errors.SchemaError(rx_exception=exception)
コード例 #2
0
def validate_yaml_schema(data, schema):
    """Check that the data respects the schema

    Will raise `SchemaError` if the schema is not respected.
    """
    schema = Rx.make_schema(schema)

    if isinstance(data, DictOfDict):
        data = dict(data)

    try:
        schema.validate(data)
    except Rx.SchemaMismatch as exception:
        raise errors.SchemaError(rx_exception=exception)
コード例 #3
0
ファイル: __init__.py プロジェクト: kether667/patacrep
def validate_parser_argument(raw_schema):
    """Check that the parser argument respects the schema

    Will raise `ContentError` if the schema is not respected.
    """
    schema = Rx.make_schema(yaml.load(raw_schema))

    def wrap(parse):
        """Wrap the parse function"""
        def wrapped(keyword, argument, config):
            """Check the argument schema before calling the plugin parser"""
            try:
                schema.validate(argument)
            except Rx.SchemaMismatch as exception:
                msg = 'Invalid syntax:\n---\n{}---\n{}'.format(
                    yaml.dump({keyword: argument}, default_flow_style=False),
                    str(exception)
                )
                raise ContentError(keyword, msg)
            return parse(keyword, argument=argument, config=config)
        return wrapped
    return wrap
コード例 #4
0
def validate_parser_argument(raw_schema):
    """Check that the parser argument respects the schema

    Will raise `ContentError` if the schema is not respected.
    """
    schema = Rx.make_schema(yaml.load(raw_schema))

    def wrap(parse):
        """Wrap the parse function"""
        def wrapped(keyword, argument, config):
            """Check the argument schema before calling the plugin parser"""
            try:
                schema.validate(argument)
            except Rx.SchemaMismatch as exception:
                msg = 'Invalid syntax:\n---\n{}---\n{}'.format(
                    yaml.dump({keyword: argument}, default_flow_style=False),
                    str(exception)
                )
                raise ContentError(keyword, msg)
            return parse(keyword, argument=argument, config=config)
        return wrapped
    return wrap