summaryrefslogtreecommitdiff
path: root/django/utils/cache.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2011-12-29 13:57:32 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2011-12-29 13:57:32 +0000
commit3367913c3db97a15b64f03646ac2c4486a77376f (patch)
treec2d95b672186557a97e5981b859749f7069e1eb3 /django/utils/cache.py
parentec07a30e821ada170904df8901787e05b7959594 (diff)
Fixed #17476 -- Ensure timezone-dependant cache keys only use ASCII characters, especially on Windows.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17286 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/cache.py')
-rw-r--r--django/utils/cache.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py
index 0ea84072fa..7ef3680db2 100644
--- a/django/utils/cache.py
+++ b/django/utils/cache.py
@@ -23,7 +23,7 @@ import time
from django.conf import settings
from django.core.cache import get_cache
-from django.utils.encoding import smart_str, iri_to_uri
+from django.utils.encoding import smart_str, iri_to_uri, force_unicode
from django.utils.http import http_date
from django.utils.timezone import get_current_timezone_name
from django.utils.translation import get_language
@@ -165,9 +165,12 @@ def _i18n_cache_key_suffix(request, cache_key):
# which in turn can also fall back to settings.LANGUAGE_CODE
cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language())
if settings.USE_TZ:
- # Windows uses non-standard timezone names that may include spaces,
- # which triggers CacheKeyWarning.
- cache_key += '.%s' % get_current_timezone_name().replace(' ', '_')
+ # The datetime module doesn't restrict the output of tzname().
+ # Windows is known to use non-standard, locale-dependant names.
+ # User-defined tzinfo classes may return absolutely anything.
+ # Hence this paranoid conversion to create a valid cache key.
+ tz_name = force_unicode(get_current_timezone_name(), errors='ignore')
+ cache_key += '.%s' % tz_name.encode('ascii', 'ignore').replace(' ', '_')
return cache_key
def _generate_cache_key(request, method, headerlist, key_prefix):