Skip to content

Instantly share code, notes, and snippets.

@loic
Created June 11, 2014 17:24
Show Gist options
  • Save loic/c9394317d8f950761588 to your computer and use it in GitHub Desktop.
Save loic/c9394317d8f950761588 to your computer and use it in GitHub Desktop.
commit e0b05dfcd74c803f872500c040cc6de88fcefe45
Author: Loic Bistuer <[email protected]>
Date: Thu Jun 12 00:21:14 2014 +0700
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.
diff --git a/django/core/files/temp.py b/django/core/files/temp.py
index 58fbd23..77563ee 100644
--- a/django/core/files/temp.py
+++ b/django/core/files/temp.py
@@ -69,6 +69,13 @@ if os.name == 'nt':
def __del__(self):
self.close()
+ def __enter__(self):
+ self.file.__enter__()
+ return self
+
+ def __exit__(self, exc, value, tb):
+ self.file.__exit__(exc, value, tb)
+
NamedTemporaryFile = TemporaryFile
else:
NamedTemporaryFile = tempfile.NamedTemporaryFile
@timgraham
Copy link

ship it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment