From ebc1325721e43808cef4334edaffc23a43f86614 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Wed, 15 Aug 2012 11:31:23 +0200 Subject: [PATCH] [py3] Always pass bytes to hashlib.md5. --- django/templatetags/cache.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django/templatetags/cache.py b/django/templatetags/cache.py index 056eadc7de..e431f99d0d 100644 --- a/django/templatetags/cache.py +++ b/django/templatetags/cache.py @@ -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: