From: <umg...@us...> - 2007-07-22 15:52:06
|
Revision: 488 http://svn.sourceforge.net/pybridge/?rev=488&view=rev Author: umgangee Date: 2007-07-22 08:52:02 -0700 (Sun, 22 Jul 2007) Log Message: ----------- Borrow an email address validator from Django. Modified Paths: -------------- trunk/pybridge/pybridge/server/database.py Modified: trunk/pybridge/pybridge/server/database.py =================================================================== --- trunk/pybridge/pybridge/server/database.py 2007-07-22 15:49:44 UTC (rev 487) +++ trunk/pybridge/pybridge/server/database.py 2007-07-22 15:52:02 UTC (rev 488) @@ -79,6 +79,13 @@ sqlhub.processConnection = connection # Set all SQLObjects to use connection. +# Email address validator from Django: see django/core/validators.py +email_re = re.compile( + r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"' # quoted-string + r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain + + class UserAccount(SQLObject): """A store of user information. @@ -89,6 +96,7 @@ password = StringCol(length=40, notNone=True) # Store SHA-1 hex hashes. allowLogin = BoolCol(default=True) # If False, account login is disabled. email = StringCol(default=None, length=320) # See RFC 2821 section 4.5.3.1. + # Don't split name field - see http://people.w3.org/rishida/blog/?p=100 realname = UnicodeCol(default=None, length=40) profile = UnicodeCol(default=None) created = DateTimeCol(default=datetime.now) @@ -109,7 +117,7 @@ def _set_email(self, value): # This regexp matches virtually all well-formatted email addresses. - if value and not re.match("^[A-z0-9_.+-]+@([A-z0-9-]+\.)+[A-z]{2,6}$", value): + if value and not email_re.search(value): raise ValueError, "Invalid or ill-formatted email address" self._SO_set_email(value) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |