summaryrefslogtreecommitdiff
path: root/Lib/socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/socket.py')
-rw-r--r--Lib/socket.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 004d6a9445..bfc9a72655 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -93,6 +93,13 @@ class socket(_socket.socket):
self._io_refs = 0
self._closed = False
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ if not self._closed:
+ self.close()
+
def __repr__(self):
"""Wrap __repr__() to reveal the real class name."""
s = _socket.socket.__repr__(self)