summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2018-03-04 00:56:39 +0500
committerTim Graham <timograham@gmail.com>2018-03-03 14:56:39 -0500
commit4ff29a53e68ef44b2f4947548a224b569d4b0394 (patch)
treeb520726c3052f35dc5940ac877bfdc1ec7390222
parent683341db4396d92e4578d348b7fcce3312df505d (diff)
Refs #17476 -- Removed obsolete simplification of timezone names in cache key generation.
-rw-r--r--django/utils/cache.py9
-rw-r--r--django/utils/timezone.py7
-rw-r--r--tests/cache/tests.py29
3 files changed, 3 insertions, 42 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py
index 86234f7aed..7117d40526 100644
--- a/django/utils/cache.py
+++ b/django/utils/cache.py
@@ -24,7 +24,7 @@ import time
from django.conf import settings
from django.core.cache import caches
from django.http import HttpResponse, HttpResponseNotModified
-from django.utils.encoding import force_bytes, force_text, iri_to_uri
+from django.utils.encoding import force_bytes, iri_to_uri
from django.utils.http import (
http_date, parse_etags, parse_http_date_safe, quote_etag,
)
@@ -295,12 +295,7 @@ 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:
- # The datetime module doesn't restrict the output of tzname().
- # Windows is known to use non-standard, locale-dependent names.
- # User-defined tzinfo classes may return absolutely anything.
- # Hence this paranoid conversion to create a valid cache key.
- tz_name = force_text(get_current_timezone_name(), errors='ignore')
- cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
+ cache_key += '.%s' % get_current_timezone_name()
return cache_key
diff --git a/django/utils/timezone.py b/django/utils/timezone.py
index deabab5176..c1f0d70bc1 100644
--- a/django/utils/timezone.py
+++ b/django/utils/timezone.py
@@ -98,12 +98,7 @@ def get_current_timezone_name():
def _get_timezone_name(timezone):
"""Return the name of ``timezone``."""
- try:
- # for pytz timezones
- return timezone.zone
- except AttributeError:
- # for regular tzinfo objects
- return timezone.tzname(None)
+ return timezone.tzname(None)
# Timezone selection functions.
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 86f5bdce38..95fa5d68e6 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -1855,10 +1855,7 @@ class CacheI18nTest(TestCase):
@override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
def test_cache_key_i18n_timezone(self):
request = self.factory.get(self.path)
- # This is tightly coupled to the implementation,
- # but it's the most straightforward way to test the key.
tz = timezone.get_current_timezone_name()
- tz = tz.encode('ascii', 'ignore').decode('ascii').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")
@@ -1870,37 +1867,11 @@ class CacheI18nTest(TestCase):
request = self.factory.get(self.path)
lang = translation.get_language()
tz = timezone.get_current_timezone_name()
- tz = tz.encode('ascii', 'ignore').decode('ascii').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")
self.assertNotIn(tz, key, "Cache keys shouldn't include the time zone name when i18n isn't active")
- @override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
- def test_cache_key_with_non_ascii_tzname(self):
- # Timezone-dependent cache keys should use ASCII characters only
- # (#17476). The implementation here is a bit odd (timezone.utc is an
- # instance, not a class), but it simulates the correct conditions.
- class CustomTzName(timezone.utc):
- pass
-
- request = self.factory.get(self.path)
- response = HttpResponse()
- with timezone.override(CustomTzName):
- CustomTzName.zone = 'Hora estándar de Argentina'.encode('UTF-8') # UTF-8 string
- sanitized_name = 'Hora_estndar_de_Argentina'
- self.assertIn(
- sanitized_name, learn_cache_key(request, response),
- "Cache keys should include the time zone name when time zones are active"
- )
-
- CustomTzName.name = 'Hora estándar de Argentina' # unicode
- sanitized_name = 'Hora_estndar_de_Argentina'
- self.assertIn(
- sanitized_name, learn_cache_key(request, response),
- "Cache keys should include the time zone name when time zones are active"
- )
-
@override_settings(
CACHE_MIDDLEWARE_KEY_PREFIX="test",
CACHE_MIDDLEWARE_SECONDS=60,