summaryrefslogtreecommitdiff
path: root/Lib/os.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-12-09 00:01:27 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2009-12-09 00:01:27 +0000
commit542d221b5f39c55a1785bcbda415ab31bd6318a7 (patch)
tree9bebf6680b66dfa3acf0a5515c274b5aca0d4342 /Lib/os.py
parent167361223610b3f74ffd02d3868912cbaea6840f (diff)
downloadcpython-542d221b5f39c55a1785bcbda415ab31bd6318a7.tar.gz
Issue #7461: objects returned by os.popen() should support the context manager protocol
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/os.py b/Lib/os.py
index ec5d280b9e..2a9937f12f 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -650,6 +650,10 @@ class _wrap_close:
return returncode
else:
return returncode << 8 # Shift left to match old behavior
+ def __enter__(self):
+ return self
+ def __exit__(self, *args):
+ self.close()
def __getattr__(self, name):
return getattr(self._stream, name)
def __iter__(self):