Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 20fbfbadcd79feab5077b84cbbed2b5908e685f3 1 parent c3db0b0
Alex Gaynor authored May 27, 2011

Showing 1 changed file with 3 additions and 1 deletion. Show diff stats Hide diff stats

  1. 4  django/views/static.py
4  django/views/static.py
@@ -2,6 +2,7 @@
2 2
 Views and functions for serving static files. These are only to be used
3 3
 during development, and SHOULD NOT be used in a production setting.
4 4
 """
  5
+from __future__ import with_statement
5 6
 
6 7
 import mimetypes
7 8
 import os
@@ -57,7 +58,8 @@ def serve(request, path, document_root=None, show_indexes=False):
57 58
     if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
58 59
                               statobj.st_mtime, statobj.st_size):
59 60
         return HttpResponseNotModified(mimetype=mimetype)
60  
-    response = HttpResponse(open(fullpath, 'rb').read(), mimetype=mimetype)
  61
+    with open(fullpath, 'rb') as f:
  62
+        response = HttpResponse(f.read(), mimetype=mimetype)
61 63
     response["Last-Modified"] = http_date(statobj.st_mtime)
62 64
     if stat.S_ISREG(statobj.st_mode):
63 65
         response["Content-Length"] = statobj.st_size

0 notes on commit 20fbfba

Please sign in to comment.
Something went wrong with that request. Please try again.