From 6e8d614acd1b65a1ae472da7db88a7b2751dc388 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Thu, 12 Jun 2014 00:21:14 +0700 Subject: [PATCH] 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. --- django/core/files/temp.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/django/core/files/temp.py b/django/core/files/temp.py index 58fbd231dc..77563eed37 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