-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added helper function for public email domain check
- Loading branch information
Bibhas
committed
Mar 20, 2018
1 parent
47bfa25
commit 136876e
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .validators import IsPublicEmailDomain, ValidationError | ||
|
||
__all__ = ['is_public_email_domain'] | ||
|
||
|
||
class DummyField(object): | ||
# Validators need a field param to work, we're going to pass a dummy | ||
# https://github.com/wtforms/wtforms/blob/master/tests/validators.py#L14 | ||
def __init__(self, data): | ||
self.data = data | ||
|
||
|
||
def is_public_email_domain(email_or_domain): | ||
""" | ||
Checks if the given email address or domain belongs to a public email domain | ||
""" | ||
try: | ||
validator = IsPublicEmailDomain() | ||
# custom validators need to accept a form and field to work | ||
# as our validator doesn't do anything with the form, can just pass a dummy object | ||
validator(dict(), DummyField(email_or_domain)) | ||
except ValidationError: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters