Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _validate_item(self, validator, data, path, strict, key):
"""
Fetch item from data at the postion key and validate with validator.
Returns an array of errors.
"""
errors = []
path = path + DataPath(key)
try: # Pull value out of data. Data can be a map or a list/sequence
data_item = data[key]
except (KeyError, IndexError): # Oops, that field didn't exist.
# Optional? Who cares.
if isinstance(validator, val.Validator) and validator.is_optional:
return errors
# SHUT DOWN EVERTYHING
errors.append('%s: Required field missing' % path)
return errors
return self._validate(validator, data_item, path, strict)