[1.7.x] Made the vendored NamedTemporaryFile work as a context manager. Refs #22680.

This fixes a regression on Windows introduced by b7de5f5.

Thanks Tim Graham for the report and review.

Backport of 6e8d614acd from master
This commit is contained in:
Loic Bistuer 2014-06-12 00:21:14 +07:00 committed by Tim Graham
parent 49d4ace2d2
commit d9eef1f4f7
1 changed files with 7 additions and 0 deletions

View File

@ -69,6 +69,13 @@ if os.name == 'nt':
def __del__(self): def __del__(self):
self.close() self.close()
def __enter__(self):
self.file.__enter__()
return self
def __exit__(self, exc, value, tb):
self.file.__exit__(exc, value, tb)
NamedTemporaryFile = TemporaryFile NamedTemporaryFile = TemporaryFile
else: else:
NamedTemporaryFile = tempfile.NamedTemporaryFile NamedTemporaryFile = tempfile.NamedTemporaryFile