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


Python validators.validator_for方法代碼示例

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


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

示例1: getValidator

# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import validator_for [as 別名]
def getValidator(schema, schema_store):
    """
    Get a L{jsonschema} validator for C{schema}.

    @param schema: The JSON Schema to validate against.
    @type schema: L{dict}

    @param dict schema_store: A mapping between schema paths
        (e.g. ``b/v1/types.json``) and the JSON schema structure.
    """
    # The base_uri here isn't correct for the schema,
    # but does give proper relative paths.
    resolver = LocalRefResolver(
        base_uri=b'',
        referrer=schema, store=schema_store)
    return validator_for(schema)(
        schema, resolver=resolver, format_checker=draft4_format_checker) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:19,代碼來源:_schema.py

示例2: full_validate

# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import validator_for [as 別名]
def full_validate(
    schema: RawSchema, raw_items: RawItems, keys: pd.Index
) -> Dict[str, set]:
    """This function uses jsonschema validator which returns all found error per item.
    See `fast_validate()` for arguments descriptions.
    """
    errors: DefaultDict = defaultdict(set)

    validator = validators.validator_for(schema)(schema)
    validator.format_checker = FormatChecker()
    for i, raw_item in enumerate(tqdm(raw_items, desc="JSON Schema Validation")):
        raw_item.pop("_type", None)
        raw_item.pop("_key", None)
        for e in validator.iter_errors(raw_item):
            error = format_validation_message(
                e.message, e.path, e.schema_path, e.validator
            )
            errors[error].add(keys[i])
    return dict(errors) 
開發者ID:scrapinghub,項目名稱:arche,代碼行數:21,代碼來源:schema.py

示例3: parse_args

# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import validator_for [as 別名]
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:7,代碼來源:cli.py

示例4: _validate

# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import validator_for [as 別名]
def _validate(self, data, strict=False):
        validator_cls = validator_for(self._schema)
        validator = validator_cls(schema=self._schema, format_checker=format_checker)
        errors = validator.iter_errors(data)

        for error in errors:
            absolute_path = list(error.absolute_path)
            required_match = REQUIRED_RE.search(error.message)
            if required_match:
                absolute_path.append(required_match.group(1))
            field_name = ".".join([str(p) for p in absolute_path])
            self._add_errors({field_name: [error.message]}) 
開發者ID:scrapinghub,項目名稱:spidermon,代碼行數:14,代碼來源:validator.py

示例5: validate

# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import validator_for [as 別名]
def validate(parsed_data):
        # Load the schema
        schema_file = open(RULES_FILE, 'r')
        schema_data = json.load(schema_file)

        # Validate the file
        validator = validator_for(schema_data)
        errors = validator(schema=schema_data).iter_errors(parsed_data)

        # Extract error messages and return
        messages = []
        for error in errors:
            messages.append('---- ISSUE: ' + error.schema['title'] + '; ' + error.message)
        return messages 
開發者ID:nightwatchcybersecurity,項目名稱:truegaze,代碼行數:16,代碼來源:adobe_mobile_sdk.py


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