mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
smtlib.py PEP8 normalization via pep8.py script.
This commit is contained in:
parent
2bd4795e94
commit
5c12ec6fee
1 changed files with 75 additions and 60 deletions
|
@ -60,6 +60,7 @@ CRLF="\r\n"
|
||||||
|
|
||||||
OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I)
|
OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I)
|
||||||
|
|
||||||
|
|
||||||
# Exception classes used by this module.
|
# Exception classes used by this module.
|
||||||
class SMTPException(Exception):
|
class SMTPException(Exception):
|
||||||
"""Base class for all exceptions raised by this module."""
|
"""Base class for all exceptions raised by this module."""
|
||||||
|
@ -128,6 +129,7 @@ class SMTPAuthenticationError(SMTPResponseException):
|
||||||
combination provided.
|
combination provided.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def quoteaddr(addr):
|
def quoteaddr(addr):
|
||||||
"""Quote a subset of the email addresses defined by RFC 821.
|
"""Quote a subset of the email addresses defined by RFC 821.
|
||||||
|
|
||||||
|
@ -175,7 +177,8 @@ else:
|
||||||
chr = None
|
chr = None
|
||||||
while chr != "\n":
|
while chr != "\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
|
||||||
|
|
||||||
|
@ -269,7 +272,8 @@ class SMTP:
|
||||||
def _get_socket(self, port, host, timeout):
|
def _get_socket(self, port, host, 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>>stderr, 'connect:', (host, port)
|
if self.debuglevel > 0:
|
||||||
|
print>>stderr, 'connect:', (host, port)
|
||||||
return socket.create_connection((port, host), timeout)
|
return socket.create_connection((port, host), timeout)
|
||||||
|
|
||||||
def connect(self, host='localhost', port=0):
|
def connect(self, host='localhost', port=0):
|
||||||
|
@ -287,19 +291,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>>stderr, 'connect:', (host, port)
|
port = self.default_port
|
||||||
|
if self.debuglevel > 0:
|
||||||
|
print>>stderr, 'connect:', (host, port)
|
||||||
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>>stderr, "connect:", msg
|
if self.debuglevel > 0:
|
||||||
|
print>>stderr, "connect:", msg
|
||||||
return (code, msg)
|
return (code, msg)
|
||||||
|
|
||||||
def send(self, str):
|
def send(self, str):
|
||||||
"""Send `str' to the server."""
|
"""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:
|
if hasattr(self, 'sock') and self.sock:
|
||||||
try:
|
try:
|
||||||
self.sock.sendall(str)
|
self.sock.sendall(str)
|
||||||
|
@ -341,7 +350,8 @@ class SMTP:
|
||||||
if line == '':
|
if line == '':
|
||||||
self.close()
|
self.close()
|
||||||
raise SMTPServerDisconnected("Connection unexpectedly closed")
|
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())
|
resp.append(line[4:].strip())
|
||||||
code = line[:3]
|
code = line[:3]
|
||||||
# Check that the error code is syntactically correct.
|
# Check that the error code is syntactically correct.
|
||||||
|
@ -470,7 +480,8 @@ class SMTP:
|
||||||
"""
|
"""
|
||||||
self.putcmd("data")
|
self.putcmd("data")
|
||||||
(code, repl) = self.getreply()
|
(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:
|
if code != 354:
|
||||||
raise SMTPDataError(code, repl)
|
raise SMTPDataError(code, repl)
|
||||||
else:
|
else:
|
||||||
|
@ -480,7 +491,8 @@ class SMTP:
|
||||||
q = q + "." + CRLF
|
q = q + "." + CRLF
|
||||||
self.send(q)
|
self.send(q)
|
||||||
(code, msg) = self.getreply()
|
(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)
|
return (code, msg)
|
||||||
|
|
||||||
def verify(self, address):
|
def verify(self, address):
|
||||||
|
@ -753,7 +765,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>>stderr, 'connect:', (host, port)
|
if self.debuglevel > 0:
|
||||||
|
print>>stderr, 'connect:', (host, port)
|
||||||
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)
|
||||||
|
@ -795,13 +808,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, msg:
|
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:
|
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>>stderr, "connect:", msg
|
if self.debuglevel > 0:
|
||||||
|
print>>stderr, "connect:", msg
|
||||||
return (code, msg)
|
return (code, msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue