Blame pagure/validators.py
|
Lenka Segura |
64cf5d |
import re
|
|
Lenka Segura |
64cf5d |
|
|
Lenka Segura |
64cf5d |
import six
|
|
Lenka Segura |
64cf5d |
from wtforms import validators
|
|
Lenka Segura |
64cf5d |
|
|
Lenka Segura |
64cf5d |
|
|
Lenka Segura |
64cf5d |
class EmailValidator(object):
|
|
Lenka Segura |
64cf5d |
"""Validates wtform email field"""
|
|
Lenka Segura |
64cf5d |
|
|
Lenka Segura |
64cf5d |
def __init__(self, message="The field data was not an email"):
|
|
Lenka Segura |
64cf5d |
self._message = message
|
|
Lenka Segura |
64cf5d |
|
|
Lenka Segura |
64cf5d |
def __call__(self, form, email):
|
|
Lenka Segura |
64cf5d |
if not isinstance(email.data, six.text_type):
|
|
Lenka Segura |
64cf5d |
raise validators.ValidationError(
|
|
Lenka Segura |
64cf5d |
"Email fields should be of text type. Found {0}".format(
|
|
Lenka Segura |
64cf5d |
type(email.data)
|
|
Lenka Segura |
64cf5d |
)
|
|
Lenka Segura |
64cf5d |
)
|
|
Lenka Segura |
64cf5d |
elif not re.match(r"[^@]+@[^@]+\.[^@]+", email.data):
|
|
Lenka Segura |
64cf5d |
raise validators.ValidationError(self._message)
|