From ffe95861be82c9ec22312579114838dc522b5e90 Mon Sep 17 00:00:00 2001 From: palewire Date: Tue, 9 Jun 2015 17:28:27 -0700 Subject: [PATCH] Python 3 fix to static_views from the Django source code --- bakery/static_views.py | 12 ++++-------- setup.py | 2 +- tox.ini | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bakery/static_views.py b/bakery/static_views.py index 0c05afe..d34acf3 100644 --- a/bakery/static_views.py +++ b/bakery/static_views.py @@ -9,12 +9,11 @@ import re import stat from six.moves.urllib.parse import unquote -from email.Utils import parsedate_tz, mktime_tz from django.template import loader from django.http import Http404, HttpResponse, HttpResponseRedirect from django.http import HttpResponseNotModified from django.template import Template, Context, TemplateDoesNotExist -from django.utils.http import http_date +from django.utils.http import http_date, parse_http_date def serve(request, path, document_root=None, show_indexes=False, default=''): @@ -135,14 +134,11 @@ def directory_index(path, fullpath): def was_modified_since(header=None, mtime=0, size=0): """ Was something modified since the user last downloaded it? - header This is the value of the If-Modified-Since header. If this is None, I'll just return True. - mtime This is the modification time of the item we're talking about. - size This is the size of the item we're talking about. """ @@ -151,12 +147,12 @@ def was_modified_since(header=None, mtime=0, size=0): raise ValueError matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header, re.IGNORECASE) - header_mtime = mktime_tz(parsedate_tz(matches.group(1))) + header_mtime = parse_http_date(matches.group(1)) header_len = matches.group(3) if header_len and int(header_len) != size: raise ValueError - if mtime > header_mtime: + if int(mtime) > header_mtime: raise ValueError - except (AttributeError, ValueError): + except (AttributeError, ValueError, OverflowError): return True return False diff --git a/setup.py b/setup.py index be1562b..75a7667 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ def run(self): setup( name='django-bakery', - version='0.7.3', + version='0.7.4', description='A set of helpers for baking your Django site out as flat files', author='The Los Angeles Times Data Desk', author_email='datadesk@latimes.com', diff --git a/tox.ini b/tox.ini index 42d3d65..ce8bb97 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py27,py34 +envlist=py34 [testenv] deps= @@ -9,5 +9,4 @@ deps= boto django-celery commands= - pyflakes bakery python setup.py test