當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。