Commits

Philip Jenvey committed 1da0833

fix the database exts using the BLOB column type that doesn't work on postgres
with SQLAlchemy 0.6, and use PickleType for compatibility with Jython

Comments (0)

Files changed (3)

   will then be set on the cookie for the session.
 * Added support for cookie-based sessions in Jython via the JCE (Java
   Cryptography Extensions). Patch from Alex Grönholm.
+* Update Beaker database extensions to work with SQLAlchemy 0.6
+  PostgreSQL and Jython.
 
 Release 1.3.1 (5/5/2009)
 ===============================

beaker/ext/database.py

 import cPickle
 import logging
+import pickle
 from datetime import datetime
 
 from beaker.container import OpenResourceNamespaceManager, Container
                              sa.Column('namespace', types.String(255), nullable=False),
                              sa.Column('accessed', types.DateTime, nullable=False),
                              sa.Column('created', types.DateTime, nullable=False),
-                             sa.Column('data', types.BLOB(), nullable=False),
+                             sa.Column('data', types.PickleType, nullable=False),
                              sa.UniqueConstraint('namespace')
             )
             cache.create(checkfirst=True)
         else:
             self._is_new = False
             try:
-                self.hash = cPickle.loads(str(result['data']))
-            except (IOError, OSError, EOFError, cPickle.PickleError):
+                self.hash = result['data']
+            except (IOError, OSError, EOFError, cPickle.PickleError,
+                    pickle.PickleError):
                 log.debug("Couln't load pickle data, creating new storage")
                 self.hash = {}
                 self._is_new = True
         if self.flags is not None and (self.flags == 'c' or self.flags == 'w'):
             cache = self.cache
             if self._is_new:
-                cache.insert().execute(namespace=self.namespace, 
-                                       data=cPickle.dumps(self.hash),
-                                       accessed=datetime.now(), 
+                cache.insert().execute(namespace=self.namespace, data=self.hash,
+                                       accessed=datetime.now(),
                                        created=datetime.now())
                 self._is_new = False
             else:
                 cache.update(cache.c.namespace==self.namespace).execute(
-                    data=cPickle.dumps(self.hash), accessed=datetime.now())
+                    data=self.hash, accessed=datetime.now())
         self.flags = None
     
     def do_remove(self):
         return self.hash.keys()
 
 class DatabaseContainer(Container):
-    namespace_manager = DatabaseNamespaceManager
+    namespace_manager = DatabaseNamespaceManager

beaker/ext/sqla.py

 import cPickle
 import logging
+import pickle
 from datetime import datetime
 
 from beaker.container import OpenResourceNamespaceManager, Container
         else:
             self._is_new = False
             try:
-                self.hash = cPickle.loads(str(result['data']))
-            except (IOError, OSError, EOFError, cPickle.PickleError):
+                self.hash = result['data']
+            except (IOError, OSError, EOFError, cPickle.PickleError,
+                    pickle.PickleError):
                 log.debug("Couln't load pickle data, creating new storage")
                 self.hash = {}
                 self._is_new = True
 
     def do_close(self):
         if self.flags is not None and (self.flags == 'c' or self.flags == 'w'):
-            data = cPickle.dumps(self.hash)
             if self._is_new:
                 insert = self.table.insert()
-                self.bind.execute(insert, namespace=self.namespace, data=data,
-                                  accessed=datetime.now(),
-                                  created=datetime.now())
+                self.bind.execute(insert, namespace=self.namespace, data=self.hash,
+                                  accessed=datetime.now(), created=datetime.now())
                 self._is_new = False
             else:
                 update = self.table.update(self.table.c.namespace == self.namespace)
-                self.bind.execute(update, data=data, accessed=datetime.now())
+                self.bind.execute(update, data=self.hash, accessed=datetime.now())
         self.flags = None
 
     def do_remove(self):
                     sa.Column('namespace', sa.String(255), primary_key=True),
                     sa.Column('accessed', sa.DateTime, nullable=False),
                     sa.Column('created', sa.DateTime, nullable=False),
-                    sa.Column('data', sa.BLOB(), nullable=False))
+                    sa.Column('data', sa.PickleType, nullable=False))