Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refs #13573 -- Modified the key technique added in r13295 to be more …

…robust against potential key collisions while keeping key names human-readable. Thanks to Alex for being finicky.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13299 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 84060a1f7aff712f6fde71884c501b50c9ef3d46 1 parent 5acd9cd
Russell Keith-Magee authored May 21, 2010

Showing 1 changed file with 6 additions and 3 deletions. Show diff stats Hide diff stats

  1. 9  django/template/loaders/cached.py
9  django/template/loaders/cached.py
@@ -3,10 +3,11 @@
3 3
 to load templates from them in order, caching the result.
4 4
 """
5 5
 
  6
+from django.core.exceptions import ImproperlyConfigured
6 7
 from django.template import TemplateDoesNotExist
7 8
 from django.template.loader import BaseLoader, get_template_from_string, find_template_loader, make_origin
  9
+from django.utils.hashcompat import sha_constructor
8 10
 from django.utils.importlib import import_module
9  
-from django.core.exceptions import ImproperlyConfigured
10 11
 
11 12
 class Loader(BaseLoader):
12 13
     is_usable = True
@@ -34,8 +35,10 @@ def find_template(self, name, dirs=None):
34 35
         raise TemplateDoesNotExist(name)
35 36
 
36 37
     def load_template(self, template_name, template_dirs=None):
37  
-        # Use hash(..) to avoid saving potentially large template_dirs values
38  
-        key = hash((template_name, template_dirs))
  38
+        key = template_name
  39
+        if template_dirs:
  40
+            # If template directories were specified, use a hash to differentiate
  41
+            key = '-'.join([template_name, sha_constructor('|'.join(template_dirs)).hexdigest()])
39 42
 
40 43
         if key not in self.template_cache:
41 44
             template, origin = self.find_template(template_name, template_dirs)

0 notes on commit 84060a1

Please sign in to comment.
Something went wrong with that request. Please try again.