Ticket #14703: 13686_14703_unicode_in_memcached_backend_r14757.diff
File 13686_14703_unicode_in_memcached_backend_r14757.diff, 2.0 KB (added by , 14 years ago) |
---|
-
django/core/cache/backends/memcached.py
40 40 41 41 def add(self, key, value, timeout=0, version=None): 42 42 key = self.make_key(key, version=version) 43 if isinstance(value, unicode):44 value = value.encode('utf-8')45 43 return self._cache.add(key, value, self._get_memcache_timeout(timeout)) 46 44 47 45 def get(self, key, default=None, version=None): … … 106 104 safe_data = {} 107 105 for key, value in data.items(): 108 106 key = self.make_key(key, version=version) 109 if isinstance(value, unicode):110 value = value.encode('utf-8')111 107 safe_data[key] = value 112 108 self._cache.set_multi(safe_data, self._get_memcache_timeout(timeout)) 113 109 -
tests/regressiontests/cache/tests.py
315 315 u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2', 316 316 u'ascii': {u'x' : 1 } 317 317 } 318 # Test `set` 318 319 for (key, value) in stuff.items(): 319 320 self.cache.set(key, value) 320 321 self.assertEqual(self.cache.get(key), value) 321 322 323 # Test `add` 324 for (key, value) in stuff.items(): 325 self.cache.delete(key) 326 self.cache.add(key, value) 327 self.assertEqual(self.cache.get(key), value) 328 329 # Test `set_many` 330 for (key, value) in stuff.items(): 331 self.cache.delete(key) 332 self.cache.set_many(stuff) 333 for (key, value) in stuff.items(): 334 self.assertEqual(self.cache.get(key), value) 335 322 336 def test_binary_string(self): 323 337 # Binary strings should be cachable 324 338 from zlib import compress, decompress