Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _process_schema(self, path, schema_data, validators):
"""
Go through a schema and construct validators.
"""
if util.is_map(schema_data) or util.is_list(schema_data):
for key, data in util.get_iter(schema_data):
schema_data[key] = self._process_schema(path + DataPath(key),
data,
validators)
else:
schema_data = self._parse_schema_item(path,
schema_data,
validators)
return schema_data
def _validate(self, validator, data, path, strict):
"""
Validate data with validator.
Special handling of non-primitive validators.
Returns an array of errors.
"""
if util.is_list(validator) or util.is_map(validator):
return self._validate_static_map_list(validator,
data,
path,
strict)
errors = []
# Optional field with optional value? Who cares.
if (data is None and
validator.is_optional and
validator.can_be_none):
return errors
errors += self._validate_primitive(validator, data, path)
if errors:
return errors
def _validate_static_map_list(self, validator, data, path, strict):
if util.is_map(validator) and not util.is_map(data):
return ["%s : '%s' is not a map" % (path, data)]
if util.is_list(validator) and not util.is_list(data):
return ["%s : '%s' is not a list" % (path, data)]
errors = []
if strict:
data_keys = set(util.get_keys(data))
validator_keys = set(util.get_keys(validator))
for key in data_keys - validator_keys:
error_path = path + DataPath(key)
errors += ['%s: Unexpected element' % error_path]
for key, sub_validator in util.get_iter(validator):
errors += self._validate_item(sub_validator,