summaryrefslogtreecommitdiff
path: root/Lib/poplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-11-23 20:04:45 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2012-11-23 20:04:45 +0100
commitd89824b0e2fa9a44b56394a5185de737a6527ea7 (patch)
tree0235c71c6142864e64f931874a9e79d99a154564 /Lib/poplib.py
parentff790aac6613b5e6e894a3113876c800012863b3 (diff)
downloadcpython-git-d89824b0e2fa9a44b56394a5185de737a6527ea7.tar.gz
Issue #4473: Ensure the socket is shutdown cleanly in POP3.close().
Patch by Lorenzo Catucci.
Diffstat (limited to 'Lib/poplib.py')
-rw-r--r--Lib/poplib.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py
index d42d9dd320..094aaa11b3 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -259,7 +259,14 @@ class POP3:
if self.file is not None:
self.file.close()
if self.sock is not None:
- self.sock.close()
+ try:
+ self.sock.shutdown(socket.SHUT_RDWR)
+ except socket.error as e:
+ # The server might already have closed the connection
+ if e.errno != errno.ENOTCONN:
+ raise
+ finally:
+ self.sock.close()
self.file = self.sock = None
#__del__ = quit