summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-12-09 00:01:27 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-12-09 00:01:27 (GMT)
commitac625351643d5732bcaa77844ef1506bf5c978ab (patch)
tree620f07c70671ea90bd42d61ae51d0fcf19a93f34 /Lib/os.py
parent9b14f6044ce261ed2c9154d1c8466ff50e697c2e (diff)
downloadcpython-ac625351643d5732bcaa77844ef1506bf5c978ab.zip
cpython-ac625351643d5732bcaa77844ef1506bf5c978ab.tar.gz
cpython-ac625351643d5732bcaa77844ef1506bf5c978ab.tar.bz2
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 ec5d280..2a9937f 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):