Merged revisions 88501 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r88501 | giampaolo.rodola | 2011-02-22 16:56:20 +0100 (mar, 22 feb 2011) | 1 line

  smtlib.py PEP8 normalization via pep8.py script.
........
This commit is contained in:
Giampaolo Rodolà 2011-02-24 20:25:11 +00:00
parent 8edd2e9720
commit f4977d2f50
1 changed files with 73 additions and 63 deletions

View File

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