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


Python validators.extend方法代码示例

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


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

示例1: extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_default(validator_class):
    validate_properties = validator_class.VALIDATORS["properties"]

    def set_defaults(validator, properties, instance, schema):
        for error in validate_properties(validator, properties, instance, schema):
            yield error

        for prop, subschema in properties.items():
            if "format" in subschema:
                if subschema['format'] == 'date-time' and instance.get(prop) is not None:
                    try:
                        datetime.utcfromtimestamp(rfc3339_to_timestamp(instance[prop]))
                    except Exception:
                        raise Exception('Error parsing property {}, value {}'
                                        .format(prop, instance[prop]))

    return validators.extend(validator_class, {"properties": set_defaults}) 
开发者ID:singer-io,项目名称:singer-tools,代码行数:19,代码来源:check_tap.py

示例2: _extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def _extend_with_default(self, validator_class):
        '''
        Method to add default fields to our schema validation
        ( From the docs )
        '''
        validate_properties = validator_class.VALIDATORS["properties"]

        def set_defaults(validator, properties, instance, schema):
            for error in validate_properties(
                validator, properties, instance, schema,
            ):
                yield error

            for property, subschema in list(properties.items()):
                if "default" in subschema:
                    instance.setdefault(property, subschema["default"])

        return validators.extend(
            validator_class, {"properties": set_defaults},
        ) 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:22,代码来源:rest_service.py

示例3: extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_default(self, validator_class):
        '''
        Method to add default fields to our schema validation
        ( From the docs )
        '''
        validate_properties = validator_class.VALIDATORS["properties"]

        def set_defaults(validator, properties, instance, schema):
            for error in validate_properties(
                validator, properties, instance, schema,
            ):
                yield error

            for property, subschema in list(properties.items()):
                if "default" in subschema:
                    instance.setdefault(property, subschema["default"])

        return validators.extend(
            validator_class, {"properties": set_defaults},
        ) 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:22,代码来源:kafka_monitor.py

示例4: get_body_validator

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def get_body_validator(models):
    """Returns a validator for the request body, based on a
    :class:`jsonschema.validators.Draft4Validator`, with extra validations
    added for swaggers extensions to jsonschema.

    :param models: a mapping of reference to models
    :returns: a :class:`jsonschema.validators.Validator` which can validate
        the request body.
    """
    return validators.extend(
        Draft4Validator,
        {
            'paramType': ignore,
            'name': ignore,
            'type': build_swagger_type_validator(models),
            'required': required_validator,
        }
    ) 
开发者ID:striglia,项目名称:pyramid_swagger,代码行数:20,代码来源:load_schema.py

示例5: extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_default(validator_class):
    validate_properties = validator_class.VALIDATORS["properties"]

    def set_defaults(validator, properties, instance, schema):
        for prop, subschema in properties.items():
            if "default" in subschema and instance is not None:
                instance.setdefault(prop, subschema["default"])

            for error in validate_properties(
                validator, properties, instance, schema
            ):
                yield error

    return validators.extend(validator_class,
                             {"properties": set_defaults})


# Parameter strict check extension as jsonschema doesn't support it 
开发者ID:openstack,项目名称:watcher,代码行数:20,代码来源:utils.py

示例6: extend_with_strict_schema

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_strict_schema(validator_class):
    validate_properties = validator_class.VALIDATORS["properties"]

    def strict_schema(validator, properties, instance, schema):
        if instance is None:
            return

        for para in instance.keys():
            if para not in properties.keys():
                raise exception.AuditParameterNotAllowed(parameter=para)

            for error in validate_properties(
                validator, properties, instance, schema
            ):
                yield error

    return validators.extend(validator_class, {"properties": strict_schema}) 
开发者ID:openstack,项目名称:watcher,代码行数:19,代码来源:utils.py

示例7: extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_default(self, validator_class):
        '''
        Method to add default fields to our schema validation
        ( From the docs )
        '''
        validate_properties = validator_class.VALIDATORS["properties"]

        def set_defaults(validator, properties, instance, schema):
            for error in validate_properties(
                    validator, properties, instance, schema,
            ):
                yield error

            for property, subschema in properties.iteritems():
                if "default" in subschema:
                    instance.setdefault(property, subschema["default"])

        return validators.extend(
            validator_class, {"properties": set_defaults},
        ) 
开发者ID:openslack,项目名称:openslack-crawler,代码行数:22,代码来源:kafka-monitor.py

示例8: factory

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def factory(cls, *args, **kwargs):
        factory = extend(Draft4Validator, dict(required=cls._required))
        return factory(*args, format_checker=cls.format_checker, **kwargs) 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:5,代码来源:validate.py

示例9: _raises

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def _raises(raises):
        r = [ConvertTo, WithMessages]
        if isinstance(raises, (list, tuple)):
            r.extend(raises)
        else:
            r.append(raises)
        return tuple(r) 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:9,代码来源:validate.py

示例10: extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_default(validator_class):
    validate_properties = validator_class.VALIDATORS["properties"]

    def set_defaults(validator, properties, instance, schema):
        for prop, subschema in properties.items():
            if "default" in subschema:
                instance.setdefault(prop, subschema["default"])

        for error in validate_properties(validator, properties, instance, schema):
            yield error

    return validators.extend(validator_class, {"properties": set_defaults}) 
开发者ID:matrix-org,项目名称:pantalaimon,代码行数:14,代码来源:client.py

示例11: list_json_files

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def list_json_files(directory, recursive=False):
    """Return a list of file paths for JSON files within `directory`.

    Args:
        directory: A path to a directory.
        recursive: If ``True``, this function will descend into all
            subdirectories.

    Returns:
        A list of JSON file paths directly under `directory`.

    """
    json_files = []

    for top, dirs, files in os.walk(directory):
        dirs.sort()
        # Get paths to each file in `files`
        paths = (os.path.join(top, f) for f in sorted(files))

        # Add all the .json files to our return collection
        json_files.extend(x for x in paths if is_json(x))

        if not recursive:
            break

    return json_files 
开发者ID:oasis-open,项目名称:cti-stix-validator,代码行数:28,代码来源:validator.py

示例12: get_json_files

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def get_json_files(files, recursive=False):
    """Return a list of files to validate from `files`. If a member of `files`
    is a directory, its children with a ``.json`` extension will be added to
    the return value.

    Args:
        files: A list of file paths and/or directory paths.
        recursive: If ``true``, this will descend into any subdirectories
            of input directories.

    Returns:
        A list of file paths to validate.

    """
    json_files = []

    if not files:
        return json_files

    for fn in files:
        if os.path.isdir(fn):
            children = list_json_files(fn, recursive)
            json_files.extend(children)
        elif is_json(fn):
            json_files.append(fn)
        else:
            continue

    if not json_files:
        raise NoJSONFileFoundError("No JSON files found!")
    return json_files 
开发者ID:oasis-open,项目名称:cti-stix-validator,代码行数:33,代码来源:validator.py

示例13: fill_defaults

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def fill_defaults(validator_class):
    validate_props = validator_class.VALIDATORS['properties']

    def set_defaults(validator, props, instance, schema):
        for prop, subschema in props.items():
            if isinstance(instance, dict) and 'default' in subschema:
                instance.setdefault(prop, subschema['default'])

        for error in validate_props(validator, props, instance, schema):
            yield error

    return validators.extend(validator_class, {'properties': set_defaults}) 
开发者ID:naspeh,项目名称:mailur,代码行数:14,代码来源:schema.py

示例14: from_schema

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def from_schema(cls, schema, resolver, validator_class):
        type_checker = deepcopy(validator_class.TYPE_CHECKER)
        type_checker.redefine_many({
            type_name: lambda checker, value: all(check(value) for check in checks)
            for type_name, checks in iteritems(EXTENDED_TYPES)
        })
        extended_validator_class = jsonschema.validators.extend(
            validator_class,
            type_checker=type_checker,
        )
        return cls(
            schema,
            extended_validator_class(schema, resolver=resolver)) 
开发者ID:striglia,项目名称:pyramid_swagger,代码行数:15,代码来源:load_schema.py

示例15: extend_with_default

# 需要导入模块: from jsonschema import validators [as 别名]
# 或者: from jsonschema.validators import extend [as 别名]
def extend_with_default(validator_class):
    validate_properties = validator_class.VALIDATORS["properties"]

    def set_defaults(validator, properties, instance, schema):
        for _property, subschema in six.iteritems(properties):
            if "default" in subschema:
                instance.setdefault(_property, subschema["default"])

        for error in validate_properties(
                validator, properties, instance, schema):
            yield error

    return validators.extend(
        validator_class, {"properties": set_defaults},
    ) 
开发者ID:etsy,项目名称:boundary-layer,代码行数:17,代码来源:validator.py


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