]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
activemapper will use threadlocal mod's objectstore if its installed
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 Jul 2006 21:53:49 +0000 (21:53 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 Jul 2006 21:53:49 +0000 (21:53 +0000)
both objectstores no longer subclass SessionContext, get at it via .context attribute instead

CHANGES
lib/sqlalchemy/ext/activemapper.py
lib/sqlalchemy/mods/threadlocal.py

diff --git a/CHANGES b/CHANGES
index f6e4e63abb77f1635a2ff2d19e666b8aca4d7828..16e6a05d4dceb806a79b5416664395f4f76ebfa9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,11 @@
 0.2.6
 - tweaks to ActiveMapper, supports self-referential relationships
+- slight rearrangement to objectstore (in activemapper/threadlocal)
+so that the SessionContext is referenced by '.context' instead
+of subclassed directly.
+- activemapper will use threadlocal's objectstore if the mod is
+activated when activemapper is imported
+- small fix to URL regexp to allow filenames with '@' in them
 
 0.2.5
 - fixed endless loop bug in select_by(), if the traversal hit
index 6c6886c66fcd299262b7da5cf1796a6ab0e1c2cb..d21332e3ab3bcf82254394d8088d531286bda43f 100644 (file)
@@ -6,6 +6,7 @@ from sqlalchemy             import Table, Column, ForeignKey
 from sqlalchemy.ext.sessioncontext import SessionContext
 from sqlalchemy.ext.assignmapper import assign_mapper
 from sqlalchemy import backref as create_backref
+import sqlalchemy
 
 import inspect
 import sys
@@ -15,18 +16,16 @@ import sys
 #
 metadata = DynamicMetaData("activemapper")
 
-#
-# thread local SessionContext
-#
-class Objectstore(object):
-
-    def __init__(self, *args, **kwargs):
-        self._context = SessionContext(*args, **kwargs)
-
-    def __getattr__(self, name):
-        return getattr(self._context.current, name)
-
-objectstore = Objectstore(create_session)
+try:
+    objectstore = sqlalchemy.objectstore
+except AttributeError:
+    # thread local SessionContext
+    class Objectstore(object):
+        def __init__(self, *args, **kwargs):
+            self.context = SessionContext(*args, **kwargs)
+        def __getattr__(self, name):
+            return getattr(self.context.current, name)
+    objectstore = Objectstore(create_session)
 
 
 #
@@ -237,10 +236,10 @@ class ActiveMapperMeta(type):
             # check for inheritence
             if hasattr(bases[0], "mapping"):
                 cls._base_mapper= bases[0].mapper
-                assign_mapper(objectstore._context, cls, cls.table, 
+                assign_mapper(objectstore.context, cls, cls.table, 
                               inherits=cls._base_mapper)
             else:
-                assign_mapper(objectstore._context, cls, cls.table)
+                assign_mapper(objectstore.context, cls, cls.table)
             cls.relations = relations
             ActiveMapperMeta.classes[clsname] = cls
             
index f96bb56497d96788ce900f6167fcbc6a88e31142..760a37e810e6cc4934e5c5d9b00b82eb6e617223 100644 (file)
@@ -22,24 +22,24 @@ while this mod is installed will reference this global context when creating new
 
 __all__ = ['Objectstore', 'assign_mapper']
 
-class Objectstore(SessionContext):
-    def __getattr__(self, key):
-        return getattr(self.current, key)
-    def get_session(self):
-        return self.current
+class Objectstore(object):
+    def __init__(self, *args, **kwargs):
+        self.context = SessionContext(*args, **kwargs)
+    def __getattr__(self, name):
+        return getattr(self.context.current, name)
 
 def assign_mapper(class_, *args, **kwargs):
-    assignmapper.assign_mapper(objectstore, class_, *args, **kwargs)
+    assignmapper.assign_mapper(objectstore.context, class_, *args, **kwargs)
 
 objectstore = Objectstore(Session)
 def install_plugin():
     sqlalchemy.objectstore = objectstore
-    global_extensions.append(objectstore.mapper_extension)
+    global_extensions.append(objectstore.context.mapper_extension)
     engine.default_strategy = 'threadlocal'
     sqlalchemy.assign_mapper = assign_mapper
 
 def uninstall_plugin():
     engine.default_strategy = 'plain'
-    global_extensions.remove(objectstore.mapper_extension)
+    global_extensions.remove(objectstore.context.mapper_extension)
 
 install_plugin()