Author: aaugustin
Date: 2011-12-27 00:22:55 -0800 (Tue, 27 Dec 2011)
New Revision: 17277

Modified:
   django/trunk/django/utils/cache.py
   django/trunk/tests/regressiontests/cache/tests.py
Log:
Fixed a CacheKeyWarning under Windows.

Modified: django/trunk/django/utils/cache.py
===================================================================
--- django/trunk/django/utils/cache.py  2011-12-25 19:44:20 UTC (rev 17276)
+++ django/trunk/django/utils/cache.py  2011-12-27 08:22:55 UTC (rev 17277)
@@ -165,7 +165,9 @@
         # which in turn can also fall back to settings.LANGUAGE_CODE
         cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language())
     if settings.USE_TZ:
-        cache_key += '.%s' % get_current_timezone_name()
+        # Windows uses non-standard timezone names that may include spaces,
+        # which triggers CacheKeyWarning.
+        cache_key += '.%s' % get_current_timezone_name().replace(' ', '_')
     return cache_key
 
 def _generate_cache_key(request, method, headerlist, key_prefix):

Modified: django/trunk/tests/regressiontests/cache/tests.py
===================================================================
--- django/trunk/tests/regressiontests/cache/tests.py   2011-12-25 19:44:20 UTC 
(rev 17276)
+++ django/trunk/tests/regressiontests/cache/tests.py   2011-12-27 08:22:55 UTC 
(rev 17277)
@@ -1270,7 +1270,7 @@
     @override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
     def test_cache_key_i18n_timezone(self):
         request = self._get_request()
-        tz = timezone.get_current_timezone_name()
+        tz = timezone.get_current_timezone_name().replace(' ', '_')
         response = HttpResponse()
         key = learn_cache_key(request, response)
         self.assertIn(tz, key, "Cache keys should include the time zone name 
when time zones are active")
@@ -1281,7 +1281,7 @@
     def test_cache_key_no_i18n (self):
         request = self._get_request()
         lang = translation.get_language()
-        tz = timezone.get_current_timezone_name()
+        tz = timezone.get_current_timezone_name().replace(' ', '_')
         response = HttpResponse()
         key = learn_cache_key(request, response)
         self.assertNotIn(lang, key, "Cache keys shouldn't include the language 
name when i18n isn't active")

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to