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


Python jsonschema.Draft4Validator方法代码示例

本文整理汇总了Python中jsonschema.Draft4Validator方法的典型用法代码示例。如果您正苦于以下问题:Python jsonschema.Draft4Validator方法的具体用法?Python jsonschema.Draft4Validator怎么用?Python jsonschema.Draft4Validator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonschema的用法示例。


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

示例1: validate_drydock_document

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def validate_drydock_document(self, doc):
        """Validate a parsed document via jsonschema.

        If a schema for a document Kind is not available, the document is
        considered valid. Schema is chosen by the doc['kind'] field.

        Returns a empty list for valid documents, otherwise returns a list
        of all found errors

        :param doc: dictionary of the parsed document.
        """
        schemaname = doc.get('schema', '')
        (schema_ns, doc_kind, doc_version) = schemaname.split('/')

        errors_found = []

        if doc_version == 'v1':
            if schemaname in self.v1_doc_schemas:
                validator = jsonschema.Draft4Validator(
                    self.v1_doc_schemas.get(schemaname))
                for error in validator.iter_errors(doc.get('data', [])):
                    errors_found.append(error.message)

        return errors_found 
开发者ID:airshipit,项目名称:drydock,代码行数:26,代码来源:deckhand.py

示例2: validate_drydock_document

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def validate_drydock_document(self, doc):
        """Validate a parsed document via jsonschema.

        If a schema for a document Kind is not available, the document is
        considered valid. Schema is chosen by the doc['kind'] field.

        Returns a empty list for valid documents, otherwise returns a list
        of all found errors

        :param doc: dictionary of the parsed document.
        """
        doc_kind = doc.get('kind')
        if doc_kind in self.v1_doc_schemas:
            validator = jsonschema.Draft4Validator(
                self.v1_doc_schemas.get(doc_kind))
            errors_found = []
            for error in validator.iter_errors(doc):
                errors_found.append(error.message)
            return errors_found
        else:
            return [] 
开发者ID:airshipit,项目名称:drydock,代码行数:23,代码来源:yaml.py

示例3: validate

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def validate(ctx):
    """
    Validate the paradrop.yaml file.

    A note about versions: this command validates the chute configuration
    against the current rules for the installed version of pdtools. If
    the chute is to be installed on a Paradrop node running a different
    version, then this command may not be reliable for determining
    compatibility.
    """
    with open('paradrop.yaml', 'r') as source:
        chute = yaml.safe_load(source)

    schema_path = pkg_resources.resource_filename('pdtools', 'schemas/chute.json')
    with open(schema_path, 'r') as source:
        schema = json.load(source)

    validator = jsonschema.Draft4Validator(schema)
    for error in sorted(validator.iter_errors(chute), key=str):
        click.echo(error.message) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:22,代码来源:chute.py

示例4: add

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def add(self, message):
        if isinstance(message, singer.RecordMessage):
            stream = self.ensure_stream(message.stream)
            if stream.latest_schema:
                validator_fn = extend_with_default(Draft4Validator)
                validator = validator_fn(
                    stream.latest_schema, format_checker=FormatChecker())
                validator.validate(copy.deepcopy(message.record))
            else:
                print('I saw a record for stream {} before the schema'.format(
                    message.stream))
                exit(1)
            stream.num_records += 1

        elif isinstance(message, singer.SchemaMessage):
            stream = self.ensure_stream(message.stream)
            stream.num_schemas += 1
            stream.latest_schema = message.schema

        elif isinstance(message, singer.StateMessage):
            self.latest_state = message.value
            self.num_states += 1 
开发者ID:singer-io,项目名称:singer-tools,代码行数:24,代码来源:check_tap.py

示例5: test_draft3_schema_draft4_validator

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_draft3_schema_draft4_validator(self):
        stdout, stderr = StringIO(), StringIO()
        with self.assertRaises(SchemaError):
            cli.run(
                {
                    "validator": Draft4Validator,
                    "schema": {
                        "anyOf": [
                            {"minimum": 20},
                            {"type": "string"},
                            {"required": True},
                        ],
                    },
                    "instances": [1],
                    "error_format": "{error.message}",
                },
                stdout=stdout,
                stderr=stderr,
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:test_cli.py

示例6: test_oneOf_and_anyOf_are_weak_matches

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties": 2,
                "anyOf": [{"type": "string"}, {"type": "number"}],
                "oneOf": [{"type": "string"}, {"type": "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:test_exceptions.py

示例7: test_if_the_most_relevant_error_is_anyOf_it_is_traversed

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "anyOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:test_exceptions.py

示例8: test_if_the_most_relevant_error_is_allOf_it_is_traversed

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_if_the_most_relevant_error_is_allOf_it_is_traversed(self):
        """
        Now, if the error is allOf, we traverse but select the *most* relevant
        error from the context, because all schemas here must match anyways.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "allOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "string") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:test_exceptions.py

示例9: test_nested_context_for_oneOf

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {
                                "oneOf": [
                                    {"type": "string"},
                                    {
                                        "properties": {
                                            "bar": {"type": "array"},
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:26,代码来源:test_exceptions.py

示例10: test_if_the_most_relevant_error_is_oneOf_it_is_traversed

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:test_exceptions.py

示例11: test_oneOf_and_anyOf_are_weak_matches

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
开发者ID:getavalon,项目名称:core,代码行数:18,代码来源:test_exceptions.py

示例12: test_if_the_most_relevant_error_is_anyOf_it_is_traversed

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:getavalon,项目名称:core,代码行数:27,代码来源:test_exceptions.py

示例13: test_if_the_most_relevant_error_is_oneOf_it_is_traversed

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:getavalon,项目名称:core,代码行数:27,代码来源:test_exceptions.py

示例14: test_nested_context_for_oneOf

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:getavalon,项目名称:core,代码行数:26,代码来源:test_exceptions.py

示例15: setup

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft4Validator [as 别名]
def setup(self, level=None, log_file=None, json=None):
        '''
        Load everything up. Note that any arg here will override both
        default and custom settings

        @param level: the log level
        @param log_file: boolean t/f whether to log to a file, else stdout
        @param json: boolean t/f whether to write the logs in json
        '''
        self.settings = self.wrapper.load(self.settings_name)

        my_level = level if level else self.settings['LOG_LEVEL']
        # negate because logger wants True for std out
        my_output = not log_file if log_file else self.settings['LOG_STDOUT']
        my_json = json if json else self.settings['LOG_JSON']
        self.logger = LogFactory.get_instance(json=my_json, stdout=my_output,
                                              level=my_level,
                                              name=self.settings['LOGGER_NAME'],
                                              dir=self.settings['LOG_DIR'],
                                              file=self.settings['LOG_FILE'],
                                              bytes=self.settings['LOG_MAX_BYTES'],
                                              backups=self.settings['LOG_BACKUPS'])

        self.validator = self.extend_with_default(Draft4Validator) 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:26,代码来源:kafka_monitor.py


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