Skip to content

Commit

Permalink
[py3] Encoded value before feeding it to hashlib.md5
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Aug 12, 2012
1 parent 99321e3 commit ac37c9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion django/core/cache/backends/filebased.py
Expand Up @@ -10,6 +10,7 @@
import pickle import pickle


from django.core.cache.backends.base import BaseCache from django.core.cache.backends.base import BaseCache
from django.utils.encoding import smart_bytes


class FileBasedCache(BaseCache): class FileBasedCache(BaseCache):
def __init__(self, dir, params): def __init__(self, dir, params):
Expand Down Expand Up @@ -136,7 +137,7 @@ def _key_to_file(self, key):
Thus, a cache key of "foo" gets turnned into a file named Thus, a cache key of "foo" gets turnned into a file named
``{cache-dir}ac/bd/18db4cc2f85cedef654fccc4a4d8``. ``{cache-dir}ac/bd/18db4cc2f85cedef654fccc4a4d8``.
""" """
path = hashlib.md5(key).hexdigest() path = hashlib.md5(smart_bytes(key)).hexdigest()
path = os.path.join(path[:2], path[2:4], path[4:]) path = os.path.join(path[:2], path[2:4], path[4:])
return os.path.join(self._dir, path) return os.path.join(self._dir, path)


Expand Down
6 changes: 3 additions & 3 deletions django/utils/cache.py
Expand Up @@ -23,7 +23,7 @@


from django.conf import settings from django.conf import settings
from django.core.cache import get_cache from django.core.cache import get_cache
from django.utils.encoding import iri_to_uri, force_text from django.utils.encoding import iri_to_uri, force_text, smart_bytes
from django.utils.http import http_date from django.utils.http import http_date
from django.utils.timezone import get_current_timezone_name from django.utils.timezone import get_current_timezone_name
from django.utils.translation import get_language from django.utils.translation import get_language
Expand Down Expand Up @@ -180,14 +180,14 @@ def _generate_cache_key(request, method, headerlist, key_prefix):
value = request.META.get(header, None) value = request.META.get(header, None)
if value is not None: if value is not None:
ctx.update(value) ctx.update(value)
path = hashlib.md5(iri_to_uri(request.get_full_path())) path = hashlib.md5(smart_bytes(iri_to_uri(request.get_full_path())))
cache_key = 'views.decorators.cache.cache_page.%s.%s.%s.%s' % ( cache_key = 'views.decorators.cache.cache_page.%s.%s.%s.%s' % (
key_prefix, method, path.hexdigest(), ctx.hexdigest()) key_prefix, method, path.hexdigest(), ctx.hexdigest())
return _i18n_cache_key_suffix(request, cache_key) return _i18n_cache_key_suffix(request, cache_key)


def _generate_cache_header_key(key_prefix, request): def _generate_cache_header_key(key_prefix, request):
"""Returns a cache key for the header cache.""" """Returns a cache key for the header cache."""
path = hashlib.md5(iri_to_uri(request.get_full_path())) path = hashlib.md5(smart_bytes(iri_to_uri(request.get_full_path())))
cache_key = 'views.decorators.cache.cache_header.%s.%s' % ( cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
key_prefix, path.hexdigest()) key_prefix, path.hexdigest())
return _i18n_cache_key_suffix(request, cache_key) return _i18n_cache_key_suffix(request, cache_key)
Expand Down

0 comments on commit ac37c9e

Please sign in to comment.