Ticket #9180: 9180.diff

File 9180.diff, 1.7 KB (added by Adam Gomaa, 16 years ago)

Patch that fixes this issue, is backwards-compatible & includes a regression test

  • django/core/cache/backends/memcached.py

    diff -r 3b67f41e85b7 django/core/cache/backends/memcached.py
    a b  
    11"Memcached cache backend"
    22
    33from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
    4 from django.utils.encoding import smart_unicode, smart_str
     4from django.utils.encoding import smart_unicode, smart_str, DjangoUnicodeDecodeError
    55
    66try:
    77    import cmemcache as memcache
     
    2727            return default
    2828        else:
    2929            if isinstance(val, basestring):
    30                 return smart_unicode(val)
     30                try:
     31                    return smart_unicode(val)
     32                except DjangoUnicodeDecodeError:
     33                    return val
    3134            else:
    3235                return val
    3336
  • tests/regressiontests/cache/tests.py

    diff -r 3b67f41e85b7 tests/regressiontests/cache/tests.py
    a b  
    2121class C:
    2222    def m(n):
    2323        return 24
     24
     25# The simplest possible GIF: a 43-byte, 1x1-pixel transparent image
     26EMPTY_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
    2428
    2529class Cache(unittest.TestCase):
    2630    def test_simple(self):
     
    105109            cache.set(key, value)
    106110            self.assertEqual(cache.get(key), value)
    107111
     112    def test_binary(self):
     113        cache.set("binary_stuff", EMPTY_GIF_BYTES)
     114        self.assertEqual(cache.get("binary_stuff"), EMPTY_GIF_BYTES)
     115
    108116
    109117class FileBasedCacheTests(unittest.TestCase):
    110118    """
Back to Top