from setuptools import setup
setup(name='wrpylib',
- version='0.0.18',
+ version='0.0.19',
description='Winterrodeln Python Library',
author='Philipp Spitzer',
author_email='philipp.spitzer@winterrodeln.org',
assert v.from_python(u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456') == u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456'
+def test_MaskedEmail():
+ v = wrpylib.wrvalidators.MaskedEmail()
+ assert v.to_python(u'') == (None, None)
+ assert v.to_python(u'abc.def@example.com') == (u'abc.def@example.com', False)
+ assert v.to_python(u'abc.def(at)example.com') == (u'abc.def@example.com', True)
+ assert v.from_python((None, None)) == u''
+ assert v.from_python((u'abc.def@example.com', False)) == u'abc.def@example.com'
+ assert v.from_python((u'abc.def@example.com', True)) == u'abc.def(at)example.com'
+
+
def test_EmailCommentListNeinLoopNone():
v = wrpylib.wrvalidators.EmailCommentListNeinLoopNone()
assert v.to_python(u'') == None
assert v.from_python(u'Nein') == u'Nein'
assert v.from_python(u'first@example.com') == u'first@example.com'
assert v.from_python(u'first@example.com (Nur Winter); second@example.com') == u'first@example.com (Nur Winter); second@example.com'
+ testvalue = u'abc.def(at)example.com (comment)'
+ try:
+ v.to_python(testvalue)
+ assert False
+ except formencode.Invalid:
+ pass
+ try:
+ v.from_python(testvalue)
+ assert False
+ except formencode.Invalid:
+ pass
+ v = wrpylib.wrvalidators.EmailCommentListNeinLoopNone(allow_masked_email=True)
+ assert v.to_python(testvalue) == testvalue
+ assert v.from_python(testvalue) == testvalue
def test_GermanLift():
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrsledruncache(engine.connect())
"""
metadata = schema.MetaData()
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrinncache(engine.connect())
"""
metadata = schema.MetaData()
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrreportcache(engine.connect())
"""
metadata = schema.MetaData()
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
>>> # or: engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0&passwd=XXXXX')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> connection = engine.connect()
>>> update_wrmapcache(connection)
"""
elif key == u'Rodelverleih': inn.sled_rental, inn.sled_rental_comment = _conv(wrpylib.wrvalidators.BoolUnicodeTupleValidator().to_python, value, key)
elif key == u'Handyempfang': inn.mobile_provider = _conv(wrpylib.wrvalidators.ValueCommentListNeinLoopNone().to_python, value, key)
elif key == u'Homepage': inn.homepage = _conv(wrpylib.wrvalidators.UrlNeinNone().to_python, value, key)
- elif key == u'E-Mail': inn.email_list = _conv(wrpylib.wrvalidators.EmailCommentListNeinLoopNone().to_python, value, key)
+ elif key == u'E-Mail': inn.email_list = _conv(wrpylib.wrvalidators.EmailCommentListNeinLoopNone(allow_masked_email=True).to_python, value, key)
elif key == u'Telefon': inn.phone_list = _conv(wrpylib.wrvalidators.PhoneCommentListNeinLoopNone(comments_are_optional=True).to_python, value, key)
elif key == u'Bild': inn.image = _conv(wrpylib.wrvalidators.UnicodeNone().to_python, value, key)
elif key == u'Rodelbahnen': inn.sledding_list = _conv(wrpylib.wrvalidators.WikiPageListLoopNone().to_python, value, key)
keys.append(u'Homepage')
values.append(wrpylib.wrvalidators.UrlNeinNone().from_python(inn.homepage))
keys.append(u'E-Mail')
- values.append(wrpylib.wrvalidators.EmailCommentListNeinLoopNone().from_python(inn.email_list))
+ values.append(wrpylib.wrvalidators.EmailCommentListNeinLoopNone(allow_masked_email=True).from_python(inn.email_list))
keys.append(u'Telefon')
values.append(wrpylib.wrvalidators.PhoneCommentListNeinLoopNone(comments_are_optional=True).from_python(inn.phone_list))
keys.append(u'Bild')
NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(PhoneNumber(default_cc=43), comments_are_optional=comments_are_optional))))
+class MaskedEmail(formencode.FancyValidator):
+ """A masked email address as defined here is an email address that has the `@` character replacted by the text `(at)`.
+ So instead of `abd.def@example.com` it would be `abc.def(at)example.com`.
+ This validator takes either a normal or a masked email address in it's to_python method and returns the normal email address as well
+ as a bool indicating whether the email address was masked.
+ u'' <=> (None, None)
+ u'abc.def@example.com' <=> (u'abc.def@example.com', False)
+ u'abc.def(at)example.com' <=> (u'abc.def@example.com', True)
+
+ """
+ def __init__(self, *args, **kw):
+ if not kw.has_key('strip'): kw['strip'] = True
+ if not kw.has_key('not_empty'): kw['not_empty'] = False
+ if not kw.has_key('if_empty'): kw['if_empty'] = (None, None)
+ self.at = '(at)'
+ formencode.FancyValidator.__init__(self, *args, **kw)
+
+ def _to_python(self, value, state):
+ email = value.replace(self.at, '@')
+ masked = value != email
+ val_email = formencode.validators.Email()
+ return val_email.to_python(email), masked
+
+ def _from_python(self, value, state):
+ email, masked = value
+ if email is None: return u''
+ val_email = formencode.validators.Email()
+ email = val_email.from_python(email)
+ if masked: email = email.replace('@', self.at)
+ return email
+
+
class EmailCommentListNeinLoopNone(NoneValidator):
"""Converts a semicolon-separated list of email addresses with optional comments to itself.
The special value of u'Nein' indicates that there are no email addresses.
u'Nein' <=> u'Nein'
u'first@example.com' <=> u'first@example.com'
u'first@example.com (Nur Winter); second@example.com' <=> u'first@example.com (Nur Winter); second@example.com'
+
+ If the parameter allow_masked_email is true, the following gives no error:
+ u'abc.def(at)example.com (comment)' <=> u'abc.def(at)example.com (comment)'
"""
- def __init__(self):
- NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(formencode.validators.Email()))))
+ def __init__(self, allow_masked_email=False):
+ NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(MaskedEmail() if allow_masked_email else formencode.validators.Email()))))
class WikiPage(formencode.FancyValidator):