diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-07-16 09:36:10 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-07-16 09:36:10 +0000 |
| commit | 2679bc0304574edf5ded0c72889fb2e4d8cac911 (patch) | |
| tree | f30155bdb9b5e69c9bce30a0265ea994d568eebe /django | |
| parent | 7aac81d28038dce5f1a250caa63cf5a86692be1c (diff) | |
Fixed #4845 -- Fixed some problems with Unicode usage and caching. Thanks,
Jeremy Dunck.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5718 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/cache/backends/filebased.py | 5 | ||||
| -rw-r--r-- | django/core/cache/backends/memcached.py | 16 |
2 files changed, 14 insertions, 7 deletions
diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py index faaf8910ce..d5415c8ace 100644 --- a/django/core/cache/backends/filebased.py +++ b/django/core/cache/backends/filebased.py @@ -1,7 +1,8 @@ "File-based cache backend" from django.core.cache.backends.simple import CacheClass as SimpleCacheClass -import os, time, urllib +from django.utils.http import urlquote_plus +import os, time try: import cPickle as pickle except ImportError: @@ -77,4 +78,4 @@ class CacheClass(SimpleCacheClass): raise EnvironmentError, "Cache directory '%s' does not exist and could not be created'" % self._dir def _key_to_file(self, key): - return os.path.join(self._dir, urllib.quote_plus(key)) + return os.path.join(self._dir, urlquote_plus(key)) diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index 1ab019221a..52610daef1 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -1,6 +1,7 @@ "Memcached cache backend" from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError +from django.utils.encoding import smart_unicode, smart_str try: import cmemcache as memcache @@ -16,17 +17,22 @@ class CacheClass(BaseCache): self._cache = memcache.Client(server.split(';')) def get(self, key, default=None): - val = self._cache.get(key) + val = self._cache.get(smart_str(key)) if val is None: return default else: - return val + if isinstance(val, basestring): + return smart_unicode(val) + else: + return val def set(self, key, value, timeout=0): - self._cache.set(key, value, timeout or self.default_timeout) + if isinstance(value, unicode): + value = value.encode('utf-8') + self._cache.set(smart_str(key), value, timeout or self.default_timeout) def delete(self, key): - self._cache.delete(key) + self._cache.delete(smart_str(key)) def get_many(self, keys): - return self._cache.get_multi(keys) + return self._cache.get_multi(map(smart_str,keys)) |
