Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
4ff29a53
Kaydet (Commit)
4ff29a53
authored
Mar 03, 2018
tarafından
Sergey Fedoseev
Kaydeden (comit)
Tim Graham
Mar 03, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #17476 -- Removed obsolete simplification of timezone names in cache key generation.
üst
683341db
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
42 deletions
+3
-42
cache.py
django/utils/cache.py
+2
-7
timezone.py
django/utils/timezone.py
+1
-6
tests.py
tests/cache/tests.py
+0
-29
No files found.
django/utils/cache.py
Dosyayı görüntüle @
4ff29a53
...
@@ -24,7 +24,7 @@ import time
...
@@ -24,7 +24,7 @@ import time
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.cache
import
caches
from
django.core.cache
import
caches
from
django.http
import
HttpResponse
,
HttpResponseNotModified
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
(
from
django.utils.http
import
(
http_date
,
parse_etags
,
parse_http_date_safe
,
quote_etag
,
http_date
,
parse_etags
,
parse_http_date_safe
,
quote_etag
,
)
)
...
@@ -295,12 +295,7 @@ def _i18n_cache_key_suffix(request, cache_key):
...
@@ -295,12 +295,7 @@ def _i18n_cache_key_suffix(request, cache_key):
# which in turn can also fall back to settings.LANGUAGE_CODE
# which in turn can also fall back to settings.LANGUAGE_CODE
cache_key
+=
'.
%
s'
%
getattr
(
request
,
'LANGUAGE_CODE'
,
get_language
())
cache_key
+=
'.
%
s'
%
getattr
(
request
,
'LANGUAGE_CODE'
,
get_language
())
if
settings
.
USE_TZ
:
if
settings
.
USE_TZ
:
# The datetime module doesn't restrict the output of tzname().
cache_key
+=
'.
%
s'
%
get_current_timezone_name
()
# 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
(
' '
,
'_'
)
return
cache_key
return
cache_key
...
...
django/utils/timezone.py
Dosyayı görüntüle @
4ff29a53
...
@@ -98,12 +98,7 @@ def get_current_timezone_name():
...
@@ -98,12 +98,7 @@ def get_current_timezone_name():
def
_get_timezone_name
(
timezone
):
def
_get_timezone_name
(
timezone
):
"""Return the name of ``timezone``."""
"""Return the name of ``timezone``."""
try
:
return
timezone
.
tzname
(
None
)
# for pytz timezones
return
timezone
.
zone
except
AttributeError
:
# for regular tzinfo objects
return
timezone
.
tzname
(
None
)
# Timezone selection functions.
# Timezone selection functions.
...
...
tests/cache/tests.py
Dosyayı görüntüle @
4ff29a53
...
@@ -1855,10 +1855,7 @@ class CacheI18nTest(TestCase):
...
@@ -1855,10 +1855,7 @@ class CacheI18nTest(TestCase):
@override_settings
(
USE_I18N
=
False
,
USE_L10N
=
False
,
USE_TZ
=
True
)
@override_settings
(
USE_I18N
=
False
,
USE_L10N
=
False
,
USE_TZ
=
True
)
def
test_cache_key_i18n_timezone
(
self
):
def
test_cache_key_i18n_timezone
(
self
):
request
=
self
.
factory
.
get
(
self
.
path
)
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
=
timezone
.
get_current_timezone_name
()
tz
=
tz
.
encode
(
'ascii'
,
'ignore'
)
.
decode
(
'ascii'
)
.
replace
(
' '
,
'_'
)
response
=
HttpResponse
()
response
=
HttpResponse
()
key
=
learn_cache_key
(
request
,
response
)
key
=
learn_cache_key
(
request
,
response
)
self
.
assertIn
(
tz
,
key
,
"Cache keys should include the time zone name when time zones are active"
)
self
.
assertIn
(
tz
,
key
,
"Cache keys should include the time zone name when time zones are active"
)
...
@@ -1870,37 +1867,11 @@ class CacheI18nTest(TestCase):
...
@@ -1870,37 +1867,11 @@ class CacheI18nTest(TestCase):
request
=
self
.
factory
.
get
(
self
.
path
)
request
=
self
.
factory
.
get
(
self
.
path
)
lang
=
translation
.
get_language
()
lang
=
translation
.
get_language
()
tz
=
timezone
.
get_current_timezone_name
()
tz
=
timezone
.
get_current_timezone_name
()
tz
=
tz
.
encode
(
'ascii'
,
'ignore'
)
.
decode
(
'ascii'
)
.
replace
(
' '
,
'_'
)
response
=
HttpResponse
()
response
=
HttpResponse
()
key
=
learn_cache_key
(
request
,
response
)
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
(
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"
)
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
(
@override_settings
(
CACHE_MIDDLEWARE_KEY_PREFIX
=
"test"
,
CACHE_MIDDLEWARE_KEY_PREFIX
=
"test"
,
CACHE_MIDDLEWARE_SECONDS
=
60
,
CACHE_MIDDLEWARE_SECONDS
=
60
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment