當前位置: 首頁>>代碼示例>>Python>>正文


Python jsonschema.Draft6Validator方法代碼示例

本文整理匯總了Python中jsonschema.Draft6Validator方法的典型用法代碼示例。如果您正苦於以下問題:Python jsonschema.Draft6Validator方法的具體用法?Python jsonschema.Draft6Validator怎麽用?Python jsonschema.Draft6Validator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jsonschema的用法示例。


在下文中一共展示了jsonschema.Draft6Validator方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validate

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import Draft6Validator [as 別名]
def validate(spec, schema_name, version=None):
    schema = load_schema(schema_name, version=version)
    try:
        resolver = jsonschema.RefResolver(
            base_uri='file://{0:s}'.format(
                pkg_resources.resource_filename(__name__, 'schemas/')
            ),
            referrer=schema_name,
            store=SCHEMA_CACHE,
        )
        validator = jsonschema.Draft6Validator(
            schema, resolver=resolver, format_checker=None
        )
        return validator.validate(spec)
    except jsonschema.ValidationError as err:
        raise InvalidSpecification(err) 
開發者ID:scikit-hep,項目名稱:pyhf,代碼行數:18,代碼來源:utils.py

示例2: validate_json_schema

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import Draft6Validator [as 別名]
def validate_json_schema(input_filepath: str):
    """
    Validates the input json schema using validation meta-schema provided in
    `validation_filepath.json` according to the specification in
    `http://json-schema.org`.
    If the tested json is not valid, a `jsonschema.exceptions.ValidationError`
    is thrown.
    Args:
        input_filepath: Filepath of the json schema to be validated
    """
    validation_file_path = os.path.normpath(
        os.path.join(os.path.dirname(__file__), 'validation_schema.json'))
    with open(validation_file_path, 'r') as validation_json_file:
        validation_schema = json.loads(validation_json_file.read())
    with open(input_filepath, 'r') as input_json_file:
        input_schema = json.loads(input_json_file.read())
    jsonschema.Draft6Validator(validation_schema).validate(input_schema) 
開發者ID:asyml,項目名稱:forte,代碼行數:19,代碼來源:utils.py

示例3: load_json_schema

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import Draft6Validator [as 別名]
def load_json_schema(path):
    '''
    Load a JSON schema from the augur included set of schemas
    (located in augur/data)
    '''
    try:
        schema = json.loads(resource_string(__package__, os.path.join("data", path)))
    except json.JSONDecodeError as err:
        raise ValidateError("Schema {} is not a valid JSON file. Error: {}".format(path, err))
    # check loaded schema is itself valid -- see http://python-jsonschema.readthedocs.io/en/latest/errors/
    try:
        jsonschema.Draft6Validator.check_schema(schema)
    except jsonschema.exceptions.SchemaError as err:
        raise ValidateError("Schema {} is not a valid JSON file. Error: {}".format(path, err))
    return jsonschema.Draft6Validator(schema) 
開發者ID:nextstrain,項目名稱:augur,代碼行數:17,代碼來源:validate.py

示例4: _get_validator

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import Draft6Validator [as 別名]
def _get_validator(cls, schema):
        """
        Helper to return a jsonschema.IValidator instance for the given JSON schema object.
        """
        return jsonschema.Draft6Validator(schema) 
開發者ID:CityofSantaMonica,項目名稱:mds-provider,代碼行數:7,代碼來源:schemas.py


注:本文中的jsonschema.Draft6Validator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。