#15281: Staticfiles sever view should use generator
----------------------------------------+-----------------------------------
Reporter: FunkyBob | Owner:
Status: new | Milestone:
Component: django.contrib.staticfiles | Version: SVN
Keywords: generator | Triage Stage: Unreviewed
Has patch: 1 |
----------------------------------------+-----------------------------------
Especially for larger files, this can greatly improve the response times.
Also, there's no reason for this module to use dict-style access to the
stat object.
{{{
Index: django/contrib/staticfiles/views.py
===================================================================
--- django/contrib/staticfiles/views.py (revision 15490)
+++ django/contrib/staticfiles/views.py (working copy)
@@ -7,7 +7,6 @@
import os
import posixpath
import re
-import stat
import urllib
from email.Utils import parsedate_tz, mktime_tz
@@ -80,12 +79,12 @@
mimetype, encoding = mimetypes.guess_type(fullpath)
mimetype = mimetype or 'application/octet-stream'
if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
- statobj[stat.ST_MTIME],
statobj[stat.ST_SIZE]):
+ statobj.st_mtime, statobj.st_size):
return HttpResponseNotModified(mimetype=mimetype)
- contents = open(fullpath, 'rb').read()
- response = HttpResponse(contents, mimetype=mimetype)
- response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
- response["Content-Length"] = len(contents)
+ contents = open(fullpath, 'rb')
+ response = HttpResponse(iter(contents), mimetype=mimetype)
+ response["Last-Modified"] = http_date(statobj.st_mtime)
+ response["Content-Length"] = statobj.st_size
if encoding:
response["Content-Encoding"] = encoding
return response
}}}
This does, however, make the view susceptible to generator-consuming
middleware, but that's another swag of tickets.
--
Ticket URL: <http://code.djangoproject.com/ticket/15281>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.