def validateInputByName(name, rules, error_msg=dict(), default=''): #不准使用error关键字作为请求参数,请求参数都会被格式化成string,无法使用int去验证 if name == 'error': error = {} error['msg'] = '不能使用error关键字作用请求参数' error['error_code'] = Code.ERROR error['error'] = True error['show'] = True return error v = cerberus.Validator( rules, error_handler=CustomErrorHandler(custom_messages=error_msg)) #这边修改成json格式接收参数 method = request.method if method == 'GET': requests = request.values if method == 'POST': requests = request.get_json() if requests == None: requests = dict() if name not in requests: requests[name] = default cookedReqVal = {name: requests[name]} if (v.validate(cookedReqVal)): # validate return requests error = {} error['msg'] = v.errors error['error_code'] = Code.ERROR error['error'] = True error['show'] = True return error
def validateSocketDataByName(name, params, rules, error_msg=dict(), default=''): #不准使用error关键字作为请求参数,请求参数都会被格式化成string,无法使用int去验证 if name == 'error': error = {} error['msg'] = '不能使用error关键字作用请求参数' error['error_code'] = Code.ERROR error['error'] = True error['show'] = True return error v = cerberus.Validator( rules, error_handler=CustomErrorHandler(custom_messages=error_msg)) #这边修改成json格式接收参数 cookedReqVal = {name: params[name]} if (v.validate(cookedReqVal)): # validate return params error = {} error['msg'] = v.errors error['error_code'] = Code.ERROR error['error'] = True error['show'] = True return error
def validateInputByName(self, name, rules, error_msg=None): v = cerberus.Validator( rules, error_handler=CustomErrorHandler(custom_messages=error_msg)) #v = ObjectValidator(rules) #这边修改成json格式接收参数 try: requests = request.values() except TypeError: requests = request.get_json() if (v.validate({name: requests[name]})): # validate return requests error = {} error['msg'] = v.errors error['error_code'] = Code.BAD_REQUEST error['error'] = True return self.json(error)
def validateInput(self, rules, error_msg=None): v = cerberus.Validator( rules, error_handler=CustomErrorHandler(custom_messages=error_msg)) #v = ObjectValidator(rules) #这边修改成json格式接收参数 try: requests = request.values() except TypeError: requests = request.get_json() if (v.validate(requests)): # validate return requests error = {} error['msg'] = v.errors error['error_code'] = CONST['CODE']['BAD_REQUEST']['value'] error['error'] = True return self.json(error)