summaryrefslogtreecommitdiffstats
path: root/Lib/imaplib.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-05 23:01:37 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-05 23:01:37 (GMT)
commit33e649cf6dc9b1764f309ed0a3206b474f8d99e1 (patch)
tree1ff8d29ec8adb8f47564ca829514f4210921a820 /Lib/imaplib.py
parenta6867258593a3b939042e47da26919be20e7e7f0 (diff)
downloadcpython-33e649cf6dc9b1764f309ed0a3206b474f8d99e1.zip
cpython-33e649cf6dc9b1764f309ed0a3206b474f8d99e1.tar.gz
cpython-33e649cf6dc9b1764f309ed0a3206b474f8d99e1.tar.bz2
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.
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r--Lib/imaplib.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 9c38e1c..8c14728 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -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.