当前位置: 首页>>代码示例>>Python>>正文


Python Validator.check方法代码示例

本文整理汇总了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))
开发者ID:jaredwy,项目名称:taskoverflow,代码行数:40,代码来源:api_views.py


注:本文中的validator.Validator.check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。