smtlib.py PEP8 normalization via pep8.py script.

This commit is contained in:
Giampaolo Rodolà 2011-02-24 20:43:11 +00:00
parent 2bd4795e94
commit 5c12ec6fee
1 changed files with 75 additions and 60 deletions

View File

@ -60,6 +60,7 @@ CRLF="\r\n"
OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I)
# Exception classes used by this module.
class SMTPException(Exception):
"""Base class for all exceptions raised by this module."""
@ -128,6 +129,7 @@ class SMTPAuthenticationError(SMTPResponseException):
combination provided.
"""
def quoteaddr(addr):
"""Quote a subset of the email addresses defined by RFC 821.
@ -175,7 +177,8 @@ else:
chr = None
while chr != "\n":
chr = self.sslobj.read(1)
if not chr: break
if not chr:
break
str += chr
return str
@ -269,7 +272,8 @@ class SMTP:
def _get_socket(self, port, host, timeout):
# This makes it simpler for SMTP_SSL to use the SMTP connect code
# and just alter the socket connection bit.
if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
if self.debuglevel > 0:
print>>stderr, 'connect:', (host, port)
return socket.create_connection((port, host), timeout)
def connect(self, host='localhost', port=0):
@ -287,19 +291,24 @@ class SMTP:
i = host.rfind(':')
if i >= 0:
host, port = host[:i], host[i + 1:]
try: port = int(port)
try:
port = int(port)
except ValueError:
raise socket.error, "nonnumeric port"
if not port: port = self.default_port
if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
if not port:
port = self.default_port
if self.debuglevel > 0:
print>>stderr, 'connect:', (host, port)
self.sock = self._get_socket(host, port, self.timeout)
(code, msg) = self.getreply()
if self.debuglevel > 0: print>>stderr, "connect:", msg
if self.debuglevel > 0:
print>>stderr, "connect:", msg
return (code, msg)
def send(self, str):
"""Send `str' to the server."""
if self.debuglevel > 0: print>>stderr, 'send:', repr(str)
if self.debuglevel > 0:
print>>stderr, 'send:', repr(str)
if hasattr(self, 'sock') and self.sock:
try:
self.sock.sendall(str)
@ -341,7 +350,8 @@ class SMTP:
if line == '':
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed")
if self.debuglevel > 0: print>>stderr, 'reply:', repr(line)
if self.debuglevel > 0:
print>>stderr, 'reply:', repr(line)
resp.append(line[4:].strip())
code = line[:3]
# Check that the error code is syntactically correct.
@ -470,7 +480,8 @@ class SMTP:
"""
self.putcmd("data")
(code, repl) = self.getreply()
if self.debuglevel >0 : print>>stderr, "data:", (code,repl)
if self.debuglevel > 0:
print>>stderr, "data:", (code, repl)
if code != 354:
raise SMTPDataError(code, repl)
else:
@ -480,7 +491,8 @@ class SMTP:
q = q + "." + CRLF
self.send(q)
(code, msg) = self.getreply()
if self.debuglevel >0 : print>>stderr, "data:", (code,msg)
if self.debuglevel > 0:
print>>stderr, "data:", (code, msg)
return (code, msg)
def verify(self, address):
@ -753,7 +765,8 @@ if _have_ssl:
self.default_port = SMTP_SSL_PORT
def _get_socket(self, host, port, timeout):
if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
if self.debuglevel > 0:
print>>stderr, 'connect:', (host, port)
new_socket = socket.create_connection((host, port), timeout)
new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
self.file = SSLFakeFile(new_socket)
@ -795,13 +808,15 @@ class LMTP(SMTP):
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.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
if self.debuglevel > 0:
print>>stderr, "connect:", msg
return (code, msg)