Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse(validator_string, validators=None):
validators = validators or val.DefaultValidators
try:
tree = ast.parse(validator_string, mode='eval')
# evaluate with access to a limited global scope only
return eval(compile(tree, '', 'eval'),
{'__builtins__': safe_builtins},
validators)
except (SyntaxError, NameError, TypeError) as e:
raise SyntaxError(
'Invalid validation syntax in \'%s\', ' % validator_string +
str(e)
)
def __init__(self, schema_dict, name='', validators=None, includes=None):
self.validators = validators or val.DefaultValidators
self.dict = schema_dict
self.name = name
self._schema = self._process_schema(DataPath(),
schema_dict,
self.validators)
# if this schema is included it shares the includes with the top level
# schema
self.includes = {} if includes is None else includes
def parse(validator_string, validators=None):
validators = validators or val.DefaultValidators
try:
tree = ast.parse(validator_string, mode='eval')
# evaluate with access to a limited global scope only
return eval(compile(tree, '', 'eval'),
{'__builtins__': safe_builtins},
validators)
except (SyntaxError, NameError, TypeError) as e:
raise SyntaxError(
'Invalid schema expression: \'%s\'. ' % validator_string +
str(e)
)