pyDNS should be a lazy requirement
- From:
- Don Spaulding
- Date:
- 2009-08-12 @ 23:18
I've not done an exhaustive study of the code to see if this is the
only case, but the following patch removes the need to install pyDNS
on my lamson server at least. A shorter patch would be to simply
remove the "import DNS" line into the else clause of
resolve_relay_host.
=== modified file 'lamson/server.py'
--- lamson/server.py 2009-08-01 08:53:06 +0000
+++ lamson/server.py 2009-08-12 23:11:33 +0000
@@ -50,7 +50,7 @@
recipient = To or message['To']
sender = From or message['From']
- hostname = self.resolve_relay_host(recipient)
+ hostname = self.hostname or self.resolve_relay_host(recipient)
relay_host = smtplib.SMTP(hostname, self.port)
relay_host.set_debuglevel(self.debug)
@@ -60,18 +60,15 @@
def resolve_relay_host(self, To):
import DNS
- if self.hostname:
- return self.hostname
+ address, target_host = To.split('@')
+ mx_hosts = DNS.mxlookup(target_host)
+
+ if not mx_hosts:
+ logging.debug("Domain %r does not have an MX record,
using %r instead.", target_host, target_host)
+ return target_host
else:
- address, target_host = To.split('@')
- mx_hosts = DNS.mxlookup(target_host)
-
- if not mx_hosts:
- logging.debug("Domain %r does not have an MX record,
using %r instead.", target_host, target_host)
- return target_host
- else:
- logging.debug("Delivering to MX record %r for target
%r", mx_hosts[0], target_host)
- return mx_hosts[0][1]
+ logging.debug("Delivering to MX record %r for target %r",
mx_hosts[0], target_host)
+ return mx_hosts[0][1]
def __repr__(self):
--
Don Spaulding II
Re: pyDNS should be a lazy requirement
- From:
- Zed A. Shaw
- Date:
- 2009-08-14 @ 17:39
On Wed, Aug 12, 2009 at 06:18:23PM -0500, Don Spaulding wrote:
> I've not done an exhaustive study of the code to see if this is the
> only case, but the following patch removes the need to install pyDNS
> on my lamson server at least. A shorter patch would be to simply
> remove the "import DNS" line into the else clause of
> resolve_relay_host.
So I'm gonna throw this quick fix in for Lamson 1.0pre3, and mock out
the pyDNS calls in the tests. Then I'll work on a more standalone
standalone module. :-)
--
Zed A. Shaw
http://zedshaw.com/
Re: pyDNS should be a lazy requirement
- From:
- Zed A. Shaw
- Date:
- 2009-08-13 @ 06:06
On Wed, Aug 12, 2009 at 06:18:23PM -0500, Don Spaulding wrote:
> I've not done an exhaustive study of the code to see if this is the
> only case, but the following patch removes the need to install pyDNS
> on my lamson server at least. A shorter patch would be to simply
> remove the "import DNS" line into the else clause of
> resolve_relay_host.
I think what I'll probably do, and what I should have done, is create a
different module with new classes/subclasses for the "standalone" stuff.
That way if you don't use that module then it's jut not even touched.
It'd also be cleaner and easier to test.
--
Zed A. Shaw
http://zedshaw.com/