|
From: <sub...@co...> - 2006-07-19 17:36:00
|
Author: ianb
Date: 2006-07-19 11:35:55 -0600 (Wed, 19 Jul 2006)
New Revision: 1828
Modified:
FormEncode/trunk/formencode/validators.py
Log:
Applied patch from Arnaud Fontaine to catch MX lookup errors when the DNS server itself is not available
Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py 2006-06-21 18:30:15 UTC (rev 1827)
+++ FormEncode/trunk/formencode/validators.py 2006-07-19 17:35:55 UTC (rev 1828)
@@ -29,6 +29,7 @@
httplib = None
urlparse = None
socket = None
+DNSError = None
from interfaces import *
from api import *
sha = random = None
@@ -1142,6 +1143,7 @@
'empty': 'Please enter an email address',
'noAt': 'An email address must contain a single @',
'badUsername': 'The username portion of the email address is invalid (the portion before the @: %(username)s)',
+ 'socketError': 'An error occured when trying to connect to the server: %(error)s',
'badDomain': 'The domain portion of the email address is invalid (the portion after the @: %(domain)s)',
'domainDoesNotExist': 'The domain of the email address does not exist (the portion after the @: %(domain)s)',
}
@@ -1185,7 +1187,19 @@
domain=splitted[1]),
value, state)
if self.resolve_domain:
- domains = mxlookup(splitted[1])
+ global socket, DNSError
+ if socket is None:
+ import socket
+
+ if DNSError is None:
+ from DNS.Base import DNSError
+
+ try:
+ domains = mxlookup(splitted[1])
+ except (socket.error, DNSError), e:
+ raise Invalid(
+ self.message('socketError', state, error=e),
+ value, state)
if not domains:
raise Invalid(
self.message('domainDoesNotExist', state,
|