Ejemplo n.º 1
0
    def __call__(self, form, field):
        try:
            import email_validator
        except ImportError as exc:  # pragma: no cover
            raise Exception(
                "Install 'email_validator' for email validation support."
            ) from exc

        try:
            if field.data is None:
                raise email_validator.EmailNotValidError()
            email_validator.validate_email(
                field.data,
                check_deliverability=self.check_deliverability,
                allow_smtputf8=self.allow_smtputf8,
                allow_empty_local=self.allow_empty_local,
            )
        except email_validator.EmailNotValidError as e:
            message = self.message
            if message is None:
                if self.granular_message:
                    message = field.gettext(e)
                else:
                    message = field.gettext("Invalid email address.")
            raise ValidationError(message) from e
Ejemplo n.º 2
0
 def __call__(self, form, field):
     try:
         if field.data is None:
             raise email_validator.EmailNotValidError()
         email_validator.validate_email(
             field.data,
             check_deliverability=self.check_deliverability,
             allow_smtputf8=self.allow_smtputf8,
             allow_empty_local=self.allow_empty_local,
         )
     except email_validator.EmailNotValidError as e:
         message = self.message
         if message is None:
             if self.granular_message:
                 message = field.gettext(e)
             else:
                 message = field.gettext("Invalid email address.")
         raise ValidationError(message)