[Checkins] SVN: z3c.saconfig/trunk/ - works with sqlalchemy 0.6

Thomas Desvenain thomas.desvenain at gmail.com
Sat May 1 12:34:23 EDT 2010


Log message for revision 111841:
  - works with sqlalchemy 0.6
   (could'nt work with sqlalchemy > 5)
  

Changed:
  U   z3c.saconfig/trunk/CHANGES.txt
  U   z3c.saconfig/trunk/src/z3c/saconfig/utility.py

-=-
Modified: z3c.saconfig/trunk/CHANGES.txt
===================================================================
--- z3c.saconfig/trunk/CHANGES.txt	2010-05-01 16:23:09 UTC (rev 111840)
+++ z3c.saconfig/trunk/CHANGES.txt	2010-05-01 16:34:22 UTC (rev 111841)
@@ -4,6 +4,9 @@
 0.11 (unreleased)
 =================
 
+- works with sqlalchemy 0.6
+ (could'nt work with sqlalchemy > 5)
+
 - Nothing changed yet.
 
 

Modified: z3c.saconfig/trunk/src/z3c/saconfig/utility.py
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/utility.py	2010-05-01 16:23:09 UTC (rev 111840)
+++ z3c.saconfig/trunk/src/z3c/saconfig/utility.py	2010-05-01 16:34:22 UTC (rev 111841)
@@ -15,9 +15,11 @@
 from z3c.saconfig.interfaces import (IScopedSession, ISiteScopedSession,
                                      IEngineFactory, EngineCreatedEvent)
 
-SA_0_5 = sqlalchemy.__version__ == 'svn' or sqlalchemy.__version__.split('.')[:2] == ['0', '5']
+SA_0_5_andmore = sqlalchemy.__version__ == 'svn' \
+    or (int(sqlalchemy.__version__.split('.')[:2][0]) >= 0
+        and int(sqlalchemy.__version__.split('.')[:2][0] >= 5))
 
-if SA_0_5:
+if SA_0_5_andmore:
     SESSION_DEFAULTS = dict(
         autocommit=False,
         autoflush=True,
@@ -40,13 +42,13 @@
     to pass the right arguments to the superclasses __init__.
     """
     implements(IScopedSession)
-    
+
     def __init__(self, engine=u'', **kw):
         """Pass keywords arguments for sqlalchemy.orm.create_session.
 
         The `engine` argument is the name of a utility implementing
         IEngineFactory.
-        
+
         Note that GloballyScopedSesssion does have different defaults than
         ``create_session`` for various parameters where it makes sense
         for Zope integration, namely:
@@ -68,7 +70,7 @@
                                                   name=self.engine)
             kw['bind'] = engine_factory()
         return sqlalchemy.orm.create_session(**kw)
-    
+
     def scopeFunc(self):
         return thread.get_ident()
 
@@ -86,18 +88,18 @@
 
     Even though this makes the sessions scoped per site,
     the utility can be registered globally to make this work.
-    
+
     Creation arguments as for GloballyScopedSession, except that no ``bind``
     parameter should be passed. This means it is possible to create
     a SiteScopedSession utility without passing parameters to its constructor.
     """
     implements(ISiteScopedSession)
-    
+
     def __init__(self, engine=u'', **kw):
         assert 'bind' not in kw
         self.engine = engine
         self.kw = _zope_session_defaults(kw)
-        
+
     def sessionFactory(self):
         engine_factory = component.getUtility(IEngineFactory,
                                               name=self.engine)
@@ -147,7 +149,7 @@
             return  "%s_%f_%d" % (id(self), time.time(), _COUNTER)
         finally:
             _COUNTER_LOCK.release()
-    
+
     def __call__(self):
         # optimistically try get without lock
         engine = _ENGINES.get(self._key, None)



More information about the checkins mailing list