def setup(framework='tornado'): """ 设置Tyrion插件当前处理的Web框架 :param framework: Web框架的字符串表示 :return: """ framework_dict = { 'tornado': Tornado, 'django': Django, 'bottle': Bottle, 'flask': Flask } cls = framework_dict.get(framework) if cls: FrameworkFactory.set_framework(cls()) else: raise Exception('Tyrion模块setup方法参数必须为:%s (任意一种字符串)' % ','.join(framework_dict.keys()))
def valid(self, handler): """ 从请求中获取用户输入的值并和规则进行比较 :param handler: Tornado处理请求的XXXHandler对象 :return: """ input_value = FrameworkFactory.get_framework().get_arguments( handler, self.name, []) # input_value = handler.get_arguments(self.name) self.value = input_value if not input_value: if not self.required: self.status = True return if self.custom_error_dict.get('required', None): self.error = self.custom_error_dict['required'] else: self.error = "%s is required" % self.name return success_value_list = [] for value in input_value: ret = re.match(self.REGULAR, value) if not ret: if self.custom_error_dict.get('element', None): self.error = self.custom_error_dict['element'] else: self.error = "element %s is invalid" % self.name return value = int(value) success_value_list.append(value) if self.ele_max_value: if value > self.ele_max_value: if self.custom_error_dict.get('ele_max_value', None): self.error = self.custom_error_dict['ele_max_value'] else: self.error = "element %s max value is %s" % ( self.name, self.ele_max_value) return if self.ele_min_value: if value < self.ele_min_value: if self.custom_error_dict.get('ele_min_value', None): self.error = self.custom_error_dict['ele_min_value'] else: self.error = "element %s min value is %s" % ( self.name, self.ele_min_value) return self.value = success_value_list self.status = True
def valid(self, handler): """ 从请求中获取用户输入的值并和规则进行比较 :param handler: Tornado处理请求的XXXHandler对象 :return: """ input_value = FrameworkFactory.get_framework().get_argument( handler, self.name, None) # input_value = handler.get_argument(self.name, None) self.value = input_value if not input_value: if not self.required: self.status = True return if self.custom_error_dict.get('required', None): self.error = self.custom_error_dict['required'] else: self.error = "%s is required" % self.name return ret = re.match(self.REGULAR, input_value) if not ret: if self.custom_error_dict.get('invalid', None): self.error = self.custom_error_dict['invalid'] else: self.error = "%s is invalid" % self.name return input_value = int(input_value) self.value = input_value if self.max_value: if input_value > self.max_value: if self.custom_error_dict.get('max_value', None): self.error = self.custom_error_dict['max_value'] else: self.error = "%s max value is %s" % (self.name, self.max_value) return if self.min_value: if input_value < self.min_value: if self.custom_error_dict.get('min_value', None): self.error = self.custom_error_dict['min_value'] else: self.error = "%s min value is %s" % (self.name, self.min_value) return self.status = True
def valid(self, handler): """ 从请求中获取用户输入的值并和规则进行比较 :param handler: Tornado处理请求的XXXHandler对象 :return: """ input_value = FrameworkFactory.get_framework().get_arguments(handler, self.name, []) # input_value = handler.get_arguments(self.name) self.value = input_value if not input_value: if not self.required: self.status = True return if self.custom_error_dict.get('required', None): self.error = self.custom_error_dict['required'] else: self.error = "%s is required" % self.name return success_value_list = [] for value in input_value: ret = re.match(self.REGULAR, value) if not ret: if self.custom_error_dict.get('element', None): self.error = self.custom_error_dict['element'] else: self.error = "element %s is invalid" % self.name return value = int(value) success_value_list.append(value) if self.ele_max_value: if value > self.ele_max_value: if self.custom_error_dict.get('ele_max_value', None): self.error = self.custom_error_dict['ele_max_value'] else: self.error = "element %s max value is %s" % (self.name, self.ele_max_value) return if self.ele_min_value: if value < self.ele_min_value: if self.custom_error_dict.get('ele_min_value', None): self.error = self.custom_error_dict['ele_min_value'] else: self.error = "element %s min value is %s" % (self.name, self.ele_min_value) return self.value = success_value_list self.status = True
def valid(self, handler): """ 从请求中获取用户输入的值并和规则进行比较 :param handler: Tornado处理请求的XXXHandler对象 :return: """ input_value = FrameworkFactory.get_framework().get_argument(handler, self.name, None) # input_value = handler.get_argument(self.name, None) self.value = input_value if not input_value: if not self.required: self.status = True return if self.custom_error_dict.get('required', None): self.error = self.custom_error_dict['required'] else: self.error = "%s is required" % self.name return ret = re.match(self.REGULAR, input_value) if not ret: if self.custom_error_dict.get('invalid', None): self.error = self.custom_error_dict['invalid'] else: self.error = "%s is invalid" % self.name return input_value = int(input_value) self.value = input_value if self.max_value: if input_value > self.max_value: if self.custom_error_dict.get('max_value', None): self.error = self.custom_error_dict['max_value'] else: self.error = "%s max value is %s" % (self.name, self.max_value) return if self.min_value: if input_value < self.min_value: if self.custom_error_dict.get('min_value', None): self.error = self.custom_error_dict['min_value'] else: self.error = "%s min value is %s" % (self.name, self.min_value) return self.status = True