summaryrefslogtreecommitdiff
path: root/django/views
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2011-05-27 04:06:23 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2011-05-27 04:06:23 +0000
commit20fbfbadcd79feab5077b84cbbed2b5908e685f3 (patch)
tree7e0fcc242a7f4417897d4448acb5485f14aba782 /django/views
parentc3db0b058c832f6f275f97d8e2e40c8e6f9f7e99 (diff)
Explicitly close a file in the static serve view. Thanks to Benjamin Peterson for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16282 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/views')
-rw-r--r--django/views/static.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/django/views/static.py b/django/views/static.py
index 72eb1a7f75..387b7da06b 100644
--- a/django/views/static.py
+++ b/django/views/static.py
@@ -2,6 +2,7 @@
Views and functions for serving static files. These are only to be used
during development, and SHOULD NOT be used in a production setting.
"""
+from __future__ import with_statement
import mimetypes
import os
@@ -57,7 +58,8 @@ def serve(request, path, document_root=None, show_indexes=False):
if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
statobj.st_mtime, statobj.st_size):
return HttpResponseNotModified(mimetype=mimetype)
- response = HttpResponse(open(fullpath, 'rb').read(), mimetype=mimetype)
+ with open(fullpath, 'rb') as f:
+ response = HttpResponse(f.read(), mimetype=mimetype)
response["Last-Modified"] = http_date(statobj.st_mtime)
if stat.S_ISREG(statobj.st_mode):
response["Content-Length"] = statobj.st_size