本文整理汇总了Python中validator.Validator.check方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.check方法的具体用法?Python Validator.check怎么用?Python Validator.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validator.Validator
的用法示例。
在下文中一共展示了Validator.check方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apigen_validate
# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import check [as 别名]
def apigen_validate(param_container, instructions, errors):
# define the validated field values
validated_fieldvalues = {}
# create the validator
vinst = Validator({ 'datetime': is_datetime })
# iterate through the instructions and check to see if everything stacks up
for fname, finst in instructions.iteritems():
logging.info("checking validity of field: %s\n" % fname)
# get the field value
field_value = None
if param_container.__contains__(fname):
field_value = param_container[fname]
# save the field data to the dict
validated_fieldvalues[fname] = field_value
# if the field is required and no data is supplied then add a validation error
if finst['required'] and (not field_value):
errors.append(create_error("validation", message = "Field is required", target = fname))
# TODO: run sql injection attack checks
# if we get past the requiredness check, let run the specified validators
elif finst.__contains__('checks') and finst['checks']:
# iterate through the validators and dynamically run
for check_name in finst['checks']:
logging.info("running check %s\n" % check_name)
# ask the validator to run the required check
try:
# print >> sys.stderr, "attempting to call module function %s" % dir(validators),
validated_fieldvalues[fname] = vinst.check(check_name, field_value)
except ValidateError, err:
logging.info("Caught validation error %s" % err.message)
errors.append(create_error("validation", message = err.message, target = fname))