1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #14749 -- added support for using Django's file object as context managers. Thanks to Florian Apolloner for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2010-11-21 17:51:41 +00:00
parent 73cd9b61c9
commit f5f18a38ab
6 changed files with 39 additions and 8 deletions

View File

@@ -101,6 +101,12 @@ class File(FileProxyMixin):
if buffer_ is not None:
yield buffer_
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
self.close()
def open(self, mode=None):
if not self.closed:
self.seek(0)