diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2007-03-10 03:19:18 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2007-03-10 03:19:18 +0000 |
commit | c8f6c23b0bef262216ec5385013e737c387d7fa1 (patch) | |
tree | a1146359413b02a3f1ee6db67f2c87ed8d9151b3 /Lib/smtplib.py | |
parent | 22c42ba88c7b28d4840078672bc7cefc75b95f71 (diff) | |
download | cpython-git-c8f6c23b0bef262216ec5385013e737c387d7fa1.tar.gz |
Simplify a little by handling the TCP case first.
Update to use predominant style of spaces around = in args list
and print to stderr if debugging.
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-x | Lib/smtplib.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py index 5f70b10ddd..850c06a85c 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -771,25 +771,25 @@ class LMTP(SMTP): """Initialize a new instance.""" SMTP.__init__(self, host, port, local_hostname) - def connect(self, host='localhost', port = 0): + def connect(self, host = 'localhost', port = 0): """Connect to the LMTP daemon, on either a Unix or a TCP socket.""" - if host[0] == '/': - try: - self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - self.sock.connect(host) - except socket.error, msg: - if self.debuglevel > 0: print 'connect fail:', host - if self.sock: - self.sock.close() - self.sock = None - if not self.sock: - raise socket.error, msg - (code, msg) = self.getreply() - if self.debuglevel > 0: print "connect:", msg - return (code, msg) - else: + if host[0] != '/': return SMTP.connect(self, host, port) + # Handle Unix-domain sockets. + try: + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.sock.connect(host) + except socket.error, msg: + if self.debuglevel > 0: print>>stderr, 'connect fail:', host + if self.sock: + self.sock.close() + self.sock = None + raise socket.error, msg + (code, msg) = self.getreply() + if self.debuglevel > 0: print>>stderr, "connect:", msg + return (code, msg) + # Test the sendmail method, which tests most of the others. # Note: This always sends to localhost. |