mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
imaplib: IMAP4 constructor closes the socket on error
Fix a ResourceWarning(unclosed socket) if an exception is raised in the constructor after the creation of the socket. Patch written by Nadeem Vawda.
This commit is contained in:
parent
a686725859
commit
33e649cf6d
1 changed files with 11 additions and 0 deletions
|
@ -169,6 +169,17 @@ class IMAP4:
|
|||
|
||||
self.open(host, port)
|
||||
|
||||
try:
|
||||
self._connect()
|
||||
except Exception:
|
||||
try:
|
||||
self.shutdown()
|
||||
except socket.error:
|
||||
pass
|
||||
raise
|
||||
|
||||
|
||||
def _connect(self):
|
||||
# Create unique tag for this session,
|
||||
# and compile tagged response matcher.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue