[py3] Always pass bytes to hashlib.md5.

This commit is contained in:
Florian Apolloner 2012-08-15 11:31:23 +02:00
parent 52c351a151
commit ebc1325721
1 changed files with 4 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import hashlib
from django.template import Library, Node, TemplateSyntaxError, Variable, VariableDoesNotExist
from django.template import resolve_variable
from django.core.cache import cache
from django.utils.encoding import smart_bytes
from django.utils.http import urlquote
register = Library()
@ -24,8 +25,9 @@ class CacheNode(Node):
expire_time = int(expire_time)
except (ValueError, TypeError):
raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
# Build a unicode key for this fragment and all vary-on's.
args = hashlib.md5(':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on]))
# Build a key for this fragment and all vary-on's.
key = smart_bytes(':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on]))
args = hashlib.md5(key)
cache_key = 'template.cache.%s.%s' % (self.fragment_name, args.hexdigest())
value = cache.get(cache_key)
if value is None: