Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
data,
path,
strict,
key)
return errors
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 __init__(self, *args, **kwargs):
self.regex_name = kwargs.pop('name', None)
flags = 0
for k, v in util.get_iter(self._regex_flags):
flags |= v if kwargs.pop(k, False) else 0
self.regexes = [re.compile(arg, flags) for arg in args if util.isstr(arg)]
super(Regex, self).__init__(*args, **kwargs)