Add basic/generic email validator logic
for use mostly in non-web scenarios, probably
This commit is contained in:
parent
a8db5db308
commit
684363bcde
3
setup.py
3
setup.py
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -73,6 +73,7 @@ requires = [
|
|||
# (still, probably a better idea is to refactor so we can use 0.9)
|
||||
'webhelpers2_grid==0.1', # 0.1
|
||||
|
||||
'colander', # 1.7.0
|
||||
'ColanderAlchemy', # 0.3.3
|
||||
'cornice', # 3.4.2
|
||||
'deform', # 2.0.4
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -35,6 +35,7 @@ import humanize
|
|||
from rattail.time import timezone, make_utc
|
||||
from rattail.files import resource_path
|
||||
|
||||
import colander
|
||||
from pyramid.renderers import get_renderer
|
||||
from webhelpers2.html import HTML, tags
|
||||
|
||||
|
@ -175,3 +176,25 @@ def get_effective_theme(rattail_config, theme=None, session=None):
|
|||
raise ValueError("theme not available: {}".format(theme))
|
||||
|
||||
return theme
|
||||
|
||||
|
||||
def validate_email_address(address):
|
||||
"""
|
||||
Perform basic validation on the given email address. This leverages the
|
||||
``colander`` package for actual validation logic.
|
||||
"""
|
||||
node = colander.SchemaNode(typ=colander.String)
|
||||
validator = colander.Email()
|
||||
validator(node, address)
|
||||
return address
|
||||
|
||||
|
||||
def email_address_is_valid(address):
|
||||
"""
|
||||
Returns boolean indicating whether the address can validate.
|
||||
"""
|
||||
try:
|
||||
validate_email_address(address)
|
||||
except colander.Invalid:
|
||||
return False
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue