Issue #16647: save socket error details in LMTP.connect()
Initial patch by Serhiy Storchaka.
This commit is contained in:
commit
2ade6f24cb
|
@ -309,7 +309,7 @@ class SMTP:
|
|||
try:
|
||||
port = int(port)
|
||||
except ValueError:
|
||||
raise socket.error("nonnumeric port")
|
||||
raise OSError("nonnumeric port")
|
||||
if not port:
|
||||
port = self.default_port
|
||||
if self.debuglevel > 0:
|
||||
|
@ -330,7 +330,7 @@ class SMTP:
|
|||
s = s.encode("ascii")
|
||||
try:
|
||||
self.sock.sendall(s)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
self.close()
|
||||
raise SMTPServerDisconnected('Server not connected')
|
||||
else:
|
||||
|
@ -363,7 +363,7 @@ class SMTP:
|
|||
while 1:
|
||||
try:
|
||||
line = self.file.readline()
|
||||
except socket.error as e:
|
||||
except OSError as e:
|
||||
self.close()
|
||||
raise SMTPServerDisconnected("Connection unexpectedly closed: "
|
||||
+ str(e))
|
||||
|
@ -920,13 +920,13 @@ class LMTP(SMTP):
|
|||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.file = None
|
||||
self.sock.connect(host)
|
||||
except socket.error as msg:
|
||||
except OSError:
|
||||
if self.debuglevel > 0:
|
||||
print('connect fail:', host, file=stderr)
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
raise socket.error(msg)
|
||||
raise
|
||||
(code, msg) = self.getreply()
|
||||
if self.debuglevel > 0:
|
||||
print('connect:', msg, file=stderr)
|
||||
|
|
|
@ -140,12 +140,8 @@ def gethostbyname(name):
|
|||
return ""
|
||||
|
||||
|
||||
class gaierror(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class error(Exception):
|
||||
pass
|
||||
gaierror = socket_module.gaierror
|
||||
error = socket_module.error
|
||||
|
||||
|
||||
# Constants
|
||||
|
|
|
@ -542,9 +542,9 @@ class NonConnectingTests(unittest.TestCase):
|
|||
|
||||
def testNonnumericPort(self):
|
||||
# check that non-numeric port raises socket.error
|
||||
self.assertRaises(mock_socket.error, smtplib.SMTP,
|
||||
self.assertRaises(OSError, smtplib.SMTP,
|
||||
"localhost", "bogus")
|
||||
self.assertRaises(mock_socket.error, smtplib.SMTP,
|
||||
self.assertRaises(OSError, smtplib.SMTP,
|
||||
"localhost:bogus")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue