smtlib.py PEP8 normalization via pep8.py script.

This commit is contained in:
Giampaolo Rodolà 2011-02-22 15:56:20 +00:00
parent e2dfefbe85
commit bd258bd4c6
1 changed files with 73 additions and 63 deletions

View File

@ -185,7 +185,8 @@ else:
chr = None
while chr != b"\n":
chr = self.sslobj.read(1)
if not chr: break
if not chr:
break
str += chr
return str
@ -280,7 +281,8 @@ class SMTP:
def _get_socket(self, host, port, 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('connect:', (host, port), file=stderr)
if self.debuglevel > 0:
print('connect:', (host, port), file=stderr)
return socket.create_connection((host, port), timeout)
def connect(self, host='localhost', port=0):
@ -298,19 +300,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('connect:', (host, port), file=stderr)
if not port:
port = self.default_port
if self.debuglevel > 0:
print('connect:', (host, port), file=stderr)
self.sock = self._get_socket(host, port, self.timeout)
(code, msg) = self.getreply()
if self.debuglevel > 0: print("connect:", msg, file=stderr)
if self.debuglevel > 0:
print("connect:", msg, file=stderr)
return (code, msg)
def send(self, s):
"""Send `s' to the server."""
if self.debuglevel > 0: print('send:', repr(s), file=stderr)
if self.debuglevel > 0:
print('send:', repr(s), file=stderr)
if hasattr(self, 'sock') and self.sock:
if isinstance(s, str):
s = s.encode("ascii")
@ -354,7 +361,8 @@ class SMTP:
if not line:
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed")
if self.debuglevel > 0: print('reply:', repr(line), file=stderr)
if self.debuglevel > 0:
print('reply:', repr(line), file=stderr)
resp.append(line[4:].strip(b' \t\r\n'))
code = line[:3]
# Check that the error code is syntactically correct.
@ -486,7 +494,8 @@ class SMTP:
"""
self.putcmd("data")
(code, repl) = self.getreply()
if self.debuglevel >0 : print("data:", (code,repl), file=stderr)
if self.debuglevel > 0:
print("data:", (code, repl), file=stderr)
if code != 354:
raise SMTPDataError(code, repl)
else:
@ -498,7 +507,8 @@ class SMTP:
q = q + b"." + bCRLF
self.send(q)
(code, msg) = self.getreply()
if self.debuglevel >0 : print("data:", (code,msg), file=stderr)
if self.debuglevel > 0:
print("data:", (code, msg), file=stderr)
return (code, msg)
def verify(self, address):
@ -564,7 +574,6 @@ class SMTP:
s = "\0%s\0%s" % (user, password)
return encode_base64(s.encode('ascii'), eol='')
AUTH_PLAIN = "PLAIN"
AUTH_CRAM_MD5 = "CRAM-MD5"
AUTH_LOGIN = "LOGIN"
@ -770,7 +779,6 @@ class SMTP:
return self.sendmail(from_addr, to_addrs, flatmsg, mail_options,
rcpt_options)
def close(self):
"""Close the connection to the SMTP server."""
if self.file:
@ -780,7 +788,6 @@ class SMTP:
self.sock.close()
self.sock = None
def quit(self):
"""Terminate the SMTP session."""
res = self.docmd("quit")
@ -806,7 +813,8 @@ if _have_ssl:
self.default_port = SMTP_SSL_PORT
def _get_socket(self, host, port, timeout):
if self.debuglevel > 0: print('connect:', (host, port), file=stderr)
if self.debuglevel > 0:
print('connect:', (host, port), file=stderr)
new_socket = socket.create_connection((host, port), timeout)
new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
self.file = SSLFakeFile(new_socket)
@ -848,13 +856,15 @@ class LMTP(SMTP):
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(host)
except socket.error as msg:
if self.debuglevel > 0: print('connect fail:', host, file=stderr)
if self.debuglevel > 0:
print('connect fail:', host, file=stderr)
if self.sock:
self.sock.close()
self.sock = None
raise socket.error(msg)
(code, msg) = self.getreply()
if self.debuglevel > 0: print('connect:', msg, file=stderr)
if self.debuglevel > 0:
print('connect:', msg, file=stderr)
return (code, msg)