Re: session2: a persistent session library

Mike Orr <[email protected]>
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
Damjan wrote:

>>That was the problem I had.  I'm using MySQL 4.0, and with a BLOB type 
>>it returns unicode, 
>>    
>>
>
>Thats strange, it shouldn't return a unicode object??! It returns an
>array.array object for me.
>  
>

You're right, it was a char array.  I did the test early last week at work.

I tried your strategy and it worked.  You can download version 0.4
http://quixote.idyll.org/session2/session2-0.4.tar.gz
or use the attached patch.

-- Mike Orr <[email protected]>

_______________________________________________
Quixote-users mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/quixote-users
diff.txt (text/plain, 1.2 KB)
Index: MySQLSessionStore.py
===================================================================
--- MySQLSessionStore.py	(revision 92)
+++ MySQLSessionStore.py	(working copy)
@@ -21,6 +21,7 @@
 class MySQLSessionStore(SessionStore):
     is_multiprocess_safe = True
     is_thread_safe = False  # Can't share db connection between threads.
+    pickle_protocol = 2
 
     def __init__(self, conn, table=None):
         if table is None:
@@ -43,11 +44,12 @@
             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.
         obj = pickle.loads(pck)
         return obj
 
     def save_session(self, session):
-        pck = pickle.dumps(session)
+        pck = pickle.dumps(session, protocol=self.pickle_protocol)
         c = self.conn.cursor()
         # decide whether to INSERT or UPDATE:
         sql = "REPLACE INTO %s (id, pickle) VALUES (%%(id)s, %%(p)s)"
@@ -74,7 +76,7 @@
         c.execute("""\
 CREATE TABLE %s (
 id VARCHAR(255) NOT NULL PRIMARY KEY,
-pickle TEXT NOT NULL,
+pickle BLOB NOT NULL,
 modify_time TIMESTAMP)""" % self.table)
 
     def delete_old_sessions(self, minutes):
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.