Esempio n. 1
0
        def validate(s):
            if not len(s) >= 2 or not len(s) <= 50:
                raise ValidationError("{} must be 2 to 50 characters long" %
                                      name)

            if not fullmatch('[A-Za-z]{2,25}( [A-Za-z]{2,25})?', s):
                raise ValidationError('{} must be a valid input'.format(name))
            else:
                return s
Esempio n. 2
0
    def validate(n):
        int_n = int(n)
        if minimum is not None:
            if int_n < minimum:
                raise ValidationError(
                    f'must be greater equal {minimum} value.')

        if maximum is not None:
            if maximum < int_n:
                raise ValidationError(f'must be less equal {maximum} value.')

        return int_n
Esempio n. 3
0
    def request(self, city_id) -> dict:
        response_data, status_code = ApiAdvisor(city_id).get_city_data()

        if not status.is_success(status_code):
            raise ValidationError(response_data.get('detail'))

        return response_data
Esempio n. 4
0
def validate_warehouse_id_list(value):
    item_schema = {
        'type': 'dict',
        'schema': {
            'warehouse_id': {
                'type': 'integer',
                'required': True
            },
            'num_days_borrow': {
                'type': 'integer',
                'min': 1,
                'required': True
            }
        }
    }
    list_schema = {
        'data': {
            'type': 'list',
            "schema": item_schema,
            'required': True
        }
    }
    wrap_value = {'data': value}
    # print(wrap_value)
    v = Validator(list_schema)
    if v.validate(wrap_value):
        return value
    raise ValidationError("Missing or bad parameter in the warehouse_id list")
Esempio n. 5
0
    def validate(s):
        if length is not None:
            if len(s) != length:
                raise ValidationError(f'must be {length} characters')

        if max_length is not None:
            if len(s) > max_length:
                raise ValidationError(
                    f'must be {max_length} characters or less')

        if min_length is not None:
            if len(s) < min_length:
                raise ValidationError(
                    f'must be at least {min_length} characters')

        return s
Esempio n. 6
0
    def validate_tag_format(self, tag: str) -> Tuple[str, int]:
        regex = re.compile(r'(태그|tag|タグ)_\d+')
        matched = regex.match(tag)

        if not matched:
            raise ValidationError(
                'invalid tag format. format must be {태그|tag|タグ}_{number} ')

        word, number = tag.split('_')
        language = self.check_language_type(word)

        return language, number
Esempio n. 7
0
def validate_phone_number(value):
    schema = {
        'phone': {
            'type':
            'string',
            'regex':
            '^(\(?\+\d{1,2}\)?\s?)?1?\-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4,5}$'
        }
    }
    v = Validator(schema)
    wrap_value = {'phone': value}
    if v.validate(wrap_value):
        return value
    raise ValidationError("Invalid phone number")
Esempio n. 8
0
    def validate_domain(self, domain):
        """
        从缓存中获取domain对应的商户名称,获取不到认为是非法的域名,则禁止访问
        :param domain:
        :return:
        """
        # current_app.logger.info('request domain: %s', domain.data)

        merchant = MerchantDomainConfig.get_merchant(domain.data)
        if not merchant:
            current_app.config['SENTRY_DSN'] and current_app.logger.fatal(
                'invalid domain: %s', domain.data)
            raise ValidationError("无效的域名: %s" % domain.data)

        self.merchant.data = merchant
Esempio n. 9
0
 def validate(s):
     if len(s) >= min_length:
         return s
     raise ValidationError("Not long enough")
Esempio n. 10
0
 def validate(s):
     if len(s) <= max_len:
         return s
     raise ValidationError(
         "{} cannot be greater than {} characters".format(
             name, max_len))
Esempio n. 11
0
 def validate(s):
     if len(s) >= min_len:
         return s
     raise ValidationError(
         "{} must be at least {} characters long".format(name, min_len))
Esempio n. 12
0
 def validate(s):
     if min_len <= len(s) <= max_len:
         return s
     raise ValidationError("{} must be {} to {} characters long".format(
         name, min_len, max_len))
Esempio n. 13
0
 def validate(s):
     if required_length == len(s):
         return s
     raise ValidationError("{} must be {} characters long".format(
         name, required_length))