Fixed #16378. Locmem now uses pickle.HIGHEST_PROTOCOL for better compatibility with other hash backends. Thanks aaugustin for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17136 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Paul McMillan 2011-11-21 22:25:49 +00:00
parent 4d975b4f88
commit 0506facd86
3 changed files with 12 additions and 4 deletions

View File

@ -102,7 +102,8 @@ class DatabaseCache(BaseDatabaseCache):
exp = exp.replace(microsecond=0)
if num > self._max_entries:
self._cull(db, cursor, now)
encoded = base64.encodestring(pickle.dumps(value, 2)).strip()
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
encoded = base64.encodestring(pickled).strip()
cursor.execute("SELECT cache_key, expires FROM %s "
"WHERE cache_key = %%s" % table, [key])
try:

View File

@ -31,7 +31,8 @@ class LocMemCache(BaseCache):
exp = self._expire_info.get(key)
if exp is None or exp <= time.time():
try:
self._set(key, pickle.dumps(value), timeout)
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
self._set(key, pickled, timeout)
return True
except pickle.PickleError:
pass
@ -49,7 +50,8 @@ class LocMemCache(BaseCache):
return default
elif exp > time.time():
try:
return pickle.loads(self._cache[key])
pickled = self._cache[key]
return pickle.loads(pickled)
except pickle.PickleError:
return default
finally:
@ -78,7 +80,8 @@ class LocMemCache(BaseCache):
self.validate_key(key)
self._lock.writer_enters()
try:
self._set(key, pickle.dumps(value), timeout)
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
self._set(key, pickled, timeout)
except pickle.PickleError:
pass
finally:

View File

@ -501,6 +501,10 @@ Django 1.4 also includes several smaller improvements worth noting:
* Changed the default value for ``httponly`` on session cookies to
``True`` to help reduce the impact of potential XSS attacks.
* Changed the ``locmem`` cache backend to use
``pickle.HIGHEST_PROTOCOL`` for better compatibility with the other
cache backends.
.. _backwards-incompatible-changes-1.4:
Backwards incompatible changes in 1.4