Author: PaulM
Date: 2011-11-21 14:25:49 -0800 (Mon, 21 Nov 2011)
New Revision: 17136

Modified:
   django/trunk/django/core/cache/backends/db.py
   django/trunk/django/core/cache/backends/locmem.py
   django/trunk/docs/releases/1.4.txt
Log:
Fixed #16378. Locmem now uses pickle.HIGHEST_PROTOCOL for better compatibility 
with other hash backends. Thanks aaugustin for the initial patch.


Modified: django/trunk/django/core/cache/backends/db.py
===================================================================
--- django/trunk/django/core/cache/backends/db.py       2011-11-21 22:03:03 UTC 
(rev 17135)
+++ django/trunk/django/core/cache/backends/db.py       2011-11-21 22:25:49 UTC 
(rev 17136)
@@ -102,7 +102,8 @@
         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:

Modified: django/trunk/django/core/cache/backends/locmem.py
===================================================================
--- django/trunk/django/core/cache/backends/locmem.py   2011-11-21 22:03:03 UTC 
(rev 17135)
+++ django/trunk/django/core/cache/backends/locmem.py   2011-11-21 22:25:49 UTC 
(rev 17136)
@@ -31,7 +31,8 @@
             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 @@
                 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 @@
         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:

Modified: django/trunk/docs/releases/1.4.txt
===================================================================
--- django/trunk/docs/releases/1.4.txt  2011-11-21 22:03:03 UTC (rev 17135)
+++ django/trunk/docs/releases/1.4.txt  2011-11-21 22:25:49 UTC (rev 17136)
@@ -501,6 +501,10 @@
 * 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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to