Ejemplo n.º 1
0
 def __call__(self, value):
     """
     Validates that the input matches the regular expression.
     """
     if not self.regex.search(text_type(value)):
         raise ValidationError(self.message, code=self.code)
     else:
         return value
Ejemplo n.º 2
0
 def __call__(self, value):
     """
     Validates that the input matches the regular expression.
     """
     if not self.regex.search(text_type(value)):
         raise ValidationError(self.message, code=self.code)
     else:
         return value
Ejemplo n.º 3
0
 def __call__(self, value):
     try:
         super(URLValidator, self).__call__(value)
     except ValidationError as e:
         # Trivial case failed. Try for possible IDN domain
         if value:
             value = text_type(value)
             scheme, netloc, path, query, fragment = urlsplit(value)
             try:
                 netloc = netloc.encode('idna').decode('ascii')  # IDN -> ACE
             except UnicodeError:  # invalid domain part
                 raise ValidationError(self.message.format(value), code=self.code)
             url = urlunsplit((scheme, netloc, path, query, fragment))
             return super(URLValidator, self).__call__(url)
         else:
             raise ValidationError(self.message.format(value), code=self.code)
     return value
Ejemplo n.º 4
0
 def __call__(self, value):
     try:
         super(URLValidator, self).__call__(value)
     except ValidationError as e:
         # Trivial case failed. Try for possible IDN domain
         if value:
             value = text_type(value)
             scheme, netloc, path, query, fragment = urlsplit(value)
             try:
                 netloc = netloc.encode('idna').decode(
                     'ascii')  # IDN -> ACE
             except UnicodeError:  # invalid domain part
                 raise ValidationError(self.message.format(value),
                                       code=self.code)
             url = urlunsplit((scheme, netloc, path, query, fragment))
             return super(URLValidator, self).__call__(url)
         else:
             raise ValidationError(self.message.format(value),
                                   code=self.code)
     return value