Commit 59caf9cd authored by Carl Meyer's avatar Carl Meyer

smart_unicode does not exist with Python 3 / Django 1.5.

parent 28f14177
from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import importlib from django.utils import importlib
from django.utils.encoding import smart_unicode, smart_str
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from .compat import smart_text, smart_bytes
try: try:
import cPickle as pickle import cPickle as pickle
...@@ -35,7 +35,7 @@ class CacheKey(object): ...@@ -35,7 +35,7 @@ class CacheKey(object):
return self.__unicode__() return self.__unicode__()
def __unicode__(self): def __unicode__(self):
return smart_str(self._key) return smart_text(self._key)
class CacheConnectionPool(object): class CacheConnectionPool(object):
...@@ -243,7 +243,7 @@ class CacheClass(BaseCache): ...@@ -243,7 +243,7 @@ class CacheClass(BaseCache):
""" """
Unpickles the given value. Unpickles the given value.
""" """
value = smart_str(value) value = smart_bytes(value)
return pickle.loads(value) return pickle.loads(value)
def get_many(self, keys, version=None): def get_many(self, keys, version=None):
...@@ -264,7 +264,7 @@ class CacheClass(BaseCache): ...@@ -264,7 +264,7 @@ class CacheClass(BaseCache):
except (ValueError, TypeError): except (ValueError, TypeError):
value = self.unpickle(value) value = self.unpickle(value)
if isinstance(value, basestring): if isinstance(value, basestring):
value = smart_unicode(value) value = smart_text(value)
recovered_data[map_keys[key]] = value recovered_data[map_keys[key]] = value
return recovered_data return recovered_data
......
try:
# Django 1.5+
from django.utils.encoding import smart_text, smart_bytes
except ImportError:
# older Django, thus definitely Python 2
from django.utils.encoding import smart_unicode, smart_str
smart_text = smart_unicode
smart_bytes = smart_str
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment