durusmail: quixote-users: session2 version 0.5: Python 2.3 compatibility update
session2 version 0.5: Python 2.3 compatibility update
2005-06-20
2005-06-30
session2 version 0.5: Python 2.3 compatibility update
2005-07-06
session2 version 0.5: Python 2.3 compatibility update
session2 version 0.5: Python 2.3 compatibility update
mso@oz.net
2005-06-20
Python 2.3.4 doesn't accept a 'protocol' keyword arg for cPickle.dumps,
and I sometimes get a string back rather than array.  So I've changed the
code to address these.

The docs say this syntax should use pickle protocol 2, but the value of
the picke does not begin with '\x80' like my manually-created protocol 3
pickles do.  So I'm not sure whether it is or not.  But the test program
is working in 2.3 and 2.4, and my application is working.

New version -->  http://quixote.idyll.org/session2/session2-0.5.tar.gz



--- session2/store/MySQLSessionStore.py (revision 93)
+++ session2/store/MySQLSessionStore.py (working copy)
@@ -13,6 +13,7 @@
 to avoid incompatible code stomping on each other's transactions.
 """
 import os, sys
+from array import array
 import cPickle as pickle
 from session2.store.SessionStore import SessionStore

@@ -44,14 +45,14 @@
             return default
         assert c.rowcount == 1, "more than one session with id %s" % (id,)
         pck = c.fetchone()[0]
-        pck = pck.tostring()  # Convert from array.array('c') type.
+        if isinstance(pck, array): # Object may be array.array('c') type.
+            pck = pck.tostring()
         obj = pickle.loads(pck)
         return obj

     def save_session(self, session):
-        pck = pickle.dumps(session, protocol=self.pickle_protocol)
+        pck = pickle.dumps(session, self.pickle_protocol)
         c = self.conn.cursor()
-        # decide whether to INSERT or UPDATE:
         sql = "REPLACE INTO %s (id, pickle) VALUES (%%(id)s, %%(p)s)"
         sql %= self.table
         dic = {'id': session.id, 'p': pck}


--
-- Mike Orr 

reply