self.assertEqual(telefonauskunft_to_str([('+43-512-1234', 'untertags'), ('+43-664-123456', 'Alm')]), '+43-512-1234 (untertags); +43-664-123456 (Alm)')
+class TestEmail(unittest.TestCase):
+ def setUp(self):
+ self.good_addresses = ['office@example.com', 'winter+rodeln@localhost', 'joe.doe@exämple.com']
+ self.bad_addresses = ['öffice@example.com', 'winter rodeln@localhost', 'www.winterrodeln.org', 'mailto:info@example.com', 'info@example.com.']
+
+ def test_from_str(self):
+ for value in self.good_addresses:
+ self.assertEqual(value, email_from_str(value))
+ for value in self.bad_addresses:
+ with self.assertRaises(ValueError):
+ email_from_str(value)
+ print(value)
+
+ def test_to_str(self):
+ for value in self.good_addresses:
+ self.assertEqual(value, email_from_str(value))
+
+
+
class TestBox(unittest.TestCase):
def test_from_str(self):
value = '{{MyTemplate|apple=2|banana=5}}'
undefined.
"""
import datetime
+import email.headerregistry
import urllib.parse
import re
import xml.dom.minidom as minidom
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):
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