|
From: <sub...@co...> - 2005-11-19 23:18:18
|
Author: ianb
Date: 2005-11-19 23:18:14 +0000 (Sat, 19 Nov 2005)
New Revision: 1298
Modified:
FormEncode/trunk/formencode/validators.py
Log:
Add email test; read resolv.conf when importing the DNS module
Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py 2005-11-19 23:12:57 UTC (rev 1297)
+++ FormEncode/trunk/formencode/validators.py 2005-11-19 23:18:14 UTC (rev 1298)
@@ -1038,15 +1038,39 @@
return []
class Email(FancyValidator):
- """
+ r"""
Validate an email address.
If you pass ``resolve_domain=True``, then it will try to resolve
the domain name to make sure it's valid. This takes longer, of
course. You must have the `pyDNS <http://pydns.sf.net>`_ modules
installed to look up MX records.
- """
+ ::
+
+ >>> e = Email()
+ >>> e.to_python(' te...@fo... ')
+ 'te...@fo...'
+ >>> e.to_python('test')
+ Traceback (most recent call last):
+ ...
+ Invalid: An email address must contain a single @
+ >>> e.to_python('te...@fo....5')
+ Traceback (most recent call last):
+ ...
+ Invalid: The domain portion of the email address is invalid (the portion after the @: foobar.com.5)
+ >>> e.to_python('o*re...@te...')
+ 'o*re...@te...'
+ >>> e = Email(resolve_domain=True)
+ >>> e.to_python('doe...@co...')
+ 'doe...@co...'
+ >>> e.to_python('te...@th...')
+ Traceback (most recent call last):
+ ...
+ Invalid: The domain of the email address does not exist (the portion after the @: thisdomaindoesnotexistithink.com)
+
+ """
+
resolve_domain = False
usernameRE = re.compile(r"^[^ \t\n\r@<>()]+$", re.I)
@@ -1066,6 +1090,8 @@
if self.resolve_domain:
if mxlookup is None:
try:
+ import DNS.Base
+ DNS.Base.ParseResolvConf()
from DNS.lazy import mxlookup
except ImportError:
import warnings
|