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
45baaaba
Kaydet (Commit)
45baaaba
authored
Agu 13, 2012
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[py3] Fixed encoding issues in cache key generation
üst
d774ad75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
6 deletions
+7
-6
base.py
django/core/cache/backends/base.py
+3
-3
cache.py
django/utils/cache.py
+2
-1
tests.py
tests/regressiontests/cache/tests.py
+2
-2
No files found.
django/core/cache/backends/base.py
Dosyayı görüntüle @
45baaaba
"Base Cache class."
from
__future__
import
unicode_literals
import
warnings
from
django.core.exceptions
import
ImproperlyConfigured
,
DjangoRuntimeWarning
from
django.utils.encoding
import
smart_bytes
from
django.utils.importlib
import
import_module
class
InvalidCacheBackendError
(
ImproperlyConfigured
):
...
...
@@ -23,7 +23,7 @@ def default_key_func(key, key_prefix, version):
the `key_prefix'. KEY_FUNCTION can be used to specify an alternate
function with custom key making behavior.
"""
return
':'
.
join
([
key_prefix
,
str
(
version
),
smart_bytes
(
key
)
])
return
':'
.
join
([
key_prefix
,
str
(
version
),
key
])
def
get_key_func
(
key_func
):
"""
...
...
@@ -62,7 +62,7 @@ class BaseCache(object):
except
(
ValueError
,
TypeError
):
self
.
_cull_frequency
=
3
self
.
key_prefix
=
smart_bytes
(
params
.
get
(
'KEY_PREFIX'
,
''
)
)
self
.
key_prefix
=
params
.
get
(
'KEY_PREFIX'
,
''
)
self
.
version
=
params
.
get
(
'VERSION'
,
1
)
self
.
key_func
=
get_key_func
(
params
.
get
(
'KEY_FUNCTION'
,
None
))
...
...
django/utils/cache.py
Dosyayı görüntüle @
45baaaba
...
...
@@ -16,6 +16,7 @@ cache keys to prevent delivery of wrong content.
An example: i18n middleware would need to distinguish caches by the
"Accept-language" header.
"""
from
__future__
import
unicode_literals
import
hashlib
import
re
...
...
@@ -170,7 +171,7 @@ def _i18n_cache_key_suffix(request, cache_key):
# 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'
)
.
replace
(
' '
,
'_'
)
cache_key
+=
'.
%
s'
%
tz_name
.
encode
(
'ascii'
,
'ignore'
)
.
decode
(
'ascii'
)
.
replace
(
' '
,
'_'
)
return
cache_key
def
_generate_cache_key
(
request
,
method
,
headerlist
,
key_prefix
):
...
...
tests/regressiontests/cache/tests.py
Dosyayı görüntüle @
45baaaba
...
...
@@ -1308,7 +1308,7 @@ class CacheI18nTest(TestCase):
# This is tightly coupled to the implementation,
# but it's the most straightforward way to test the key.
tz
=
force_text
(
timezone
.
get_current_timezone_name
(),
errors
=
'ignore'
)
tz
=
tz
.
encode
(
'ascii'
,
'ignore'
)
.
replace
(
' '
,
'_'
)
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"
)
...
...
@@ -1320,7 +1320,7 @@ class CacheI18nTest(TestCase):
request
=
self
.
_get_request
()
lang
=
translation
.
get_language
()
tz
=
force_text
(
timezone
.
get_current_timezone_name
(),
errors
=
'ignore'
)
tz
=
tz
.
encode
(
'ascii'
,
'ignore'
)
.
replace
(
' '
,
'_'
)
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"
)
...
...
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