-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 'strip' not in kw: kw['strip'] = True
- if 'not_empty' not in kw: kw['not_empty'] = False
- if 'if_empty' not in kw: kw['if_empty'] = (None, None)
- self.at = '(at)'
- formencode.FancyValidator.__init__(self, *args, **kw)
-
- def _to_python(self, value, state=None):
- email = value.replace(self.at, '@')
- masked = value != email
- val_email = formencode.validators.Email()
- return val_email.to_python(email, state), masked
-
- def _from_python(self, value, state=None):
- email, masked = value
- if email is None: return ''
- val_email = formencode.validators.Email()
- email = val_email.from_python(email, state)
- 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.
- The empty string translates to None:
- u'' <=> None
- 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, allow_masked_email=False):
- NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(MaskedEmail() if allow_masked_email else formencode.validators.Email()))))
-'''
-
-class WikiPage(formencode.FancyValidator):
- """Validates wiki page name like u'[[Birgitzer Alm]]'.