Issue #7461: objects returned by os.popen() should support the context manager protocol

This commit is contained in:
Antoine Pitrou 2009-12-09 00:01:27 +00:00
parent 9b14f6044c
commit ac62535164
2 changed files with 12 additions and 0 deletions

View file

@ -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):