Created
June 11, 2014 17:21
-
-
Save loic/2cb25058a6ce406cc7cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit a6340bcc2667d74e3c01da8e0a8e018264d1ba3b | |
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. | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment