X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wrpylib.git/blobdiff_plain/702bca32d33a3942bc422806b928eeafa9656abd..58f8607bf95fe69570397a1e1e7b1b9e5748fb85:/wrpylib/wrvalidators.py diff --git a/wrpylib/wrvalidators.py b/wrpylib/wrvalidators.py index 5182345..f8511de 100644 --- a/wrpylib/wrvalidators.py +++ b/wrpylib/wrvalidators.py @@ -10,6 +10,7 @@ can assume that the value it has to convert to a string is valid. If it gets an undefined. """ import datetime +import email.headerregistry import urllib.parse import re import xml.dom.minidom as minidom @@ -1041,6 +1042,13 @@ def telefonauskunft_to_str(value): telefonauskunft_converter = FromToConverter(telefonauskunft_from_str, telefonauskunft_to_str) +def email_from_str(value): + """Takes an email address like 'office@example.com', checks it for correctness and returns it again as string.""" + try: + email.headerregistry.Address(addr_spec=value) + except email.errors.HeaderParseError as e: + raise ValueError('Invalid email address: {}'.format(value), e) + return value class PhoneNumber(formencode.FancyValidator): """Telefonnumber in international format, e.g. u'+43-699-1234567'""" def __init__(self, default_cc=43): @@ -1053,6 +1061,10 @@ class PhoneNumber(formencode.FancyValidator): return self.validator.from_python(value, state) +def email_to_str(value): + return str(email) + + class PhoneCommentListNeinLoopNone(NoneValidator): """List with semicolon-separated phone numbers in international format with optional comment or 'Nein' as string: u'' <=> None