diff -r 3b67f41e85b7 django/core/cache/backends/memcached.py
a
|
b
|
|
1 | 1 | "Memcached cache backend" |
2 | 2 | |
3 | 3 | from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError |
4 | | from django.utils.encoding import smart_unicode, smart_str |
| 4 | from django.utils.encoding import smart_unicode, smart_str, DjangoUnicodeDecodeError |
5 | 5 | |
6 | 6 | try: |
7 | 7 | import cmemcache as memcache |
… |
… |
|
27 | 27 | return default |
28 | 28 | else: |
29 | 29 | if isinstance(val, basestring): |
30 | | return smart_unicode(val) |
| 30 | try: |
| 31 | return smart_unicode(val) |
| 32 | except DjangoUnicodeDecodeError: |
| 33 | return val |
31 | 34 | else: |
32 | 35 | return val |
33 | 36 | |
diff -r 3b67f41e85b7 tests/regressiontests/cache/tests.py
a
|
b
|
|
21 | 21 | class C: |
22 | 22 | def m(n): |
23 | 23 | return 24 |
| 24 | |
| 25 | # The simplest possible GIF: a 43-byte, 1x1-pixel transparent image |
| 26 | EMPTY_GIF_BYTES = 'GIF89a\x01\x00\x01\x00\xf0\x00\x00\xb0\x8cZ\x00\x00\x00!\xf9\x04\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' |
| 27 | |
24 | 28 | |
25 | 29 | class Cache(unittest.TestCase): |
26 | 30 | def test_simple(self): |
… |
… |
|
105 | 109 | cache.set(key, value) |
106 | 110 | self.assertEqual(cache.get(key), value) |
107 | 111 | |
| 112 | def test_binary(self): |
| 113 | cache.set("binary_stuff", EMPTY_GIF_BYTES) |
| 114 | self.assertEqual(cache.get("binary_stuff"), EMPTY_GIF_BYTES) |
| 115 | |
108 | 116 | |
109 | 117 | class FileBasedCacheTests(unittest.TestCase): |
110 | 118 | """ |