diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-23 19:04:45 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-23 19:04:45 (GMT) |
commit | d89824b0e2fa9a44b56394a5185de737a6527ea7 (patch) | |
tree | 0235c71c6142864e64f931874a9e79d99a154564 /Lib | |
parent | ff790aac6613b5e6e894a3113876c800012863b3 (diff) | |
download | cpython-d89824b0e2fa9a44b56394a5185de737a6527ea7.zip cpython-d89824b0e2fa9a44b56394a5185de737a6527ea7.tar.gz cpython-d89824b0e2fa9a44b56394a5185de737a6527ea7.tar.bz2 |
Issue #4473: Ensure the socket is shutdown cleanly in POP3.close().
Patch by Lorenzo Catucci.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/poplib.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py index d42d9dd..094aaa1 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 |