[Checkins] SVN: z3c.dobbin/trunk/ Added patch to support old-style
mixin classes.
Malthe Borch
mborch at gmail.com
Wed Jul 23 06:35:14 EDT 2008
Log message for revision 88755:
Added patch to support old-style mixin classes.
Changed:
U z3c.dobbin/trunk/CHANGES.txt
U z3c.dobbin/trunk/setup.py
U z3c.dobbin/trunk/src/z3c/dobbin/__init__.py
U z3c.dobbin/trunk/src/z3c/dobbin/mapper.py
U z3c.dobbin/trunk/src/z3c/dobbin/utility.py
-=-
Modified: z3c.dobbin/trunk/CHANGES.txt
===================================================================
--- z3c.dobbin/trunk/CHANGES.txt 2008-07-23 09:40:46 UTC (rev 88754)
+++ z3c.dobbin/trunk/CHANGES.txt 2008-07-23 10:35:12 UTC (rev 88755)
@@ -4,6 +4,9 @@
0.4dev
------
+- Added patch to support old-style mixin classes in the inheritance
+ tree of a mapper class.
+
- All attributes that are not declared as interface names are now
persisted automatically using the Pickle-protocol. The exception to
this rule is attributes starting with the characters "_v_" (volatile
Modified: z3c.dobbin/trunk/setup.py
===================================================================
--- z3c.dobbin/trunk/setup.py 2008-07-23 09:40:46 UTC (rev 88754)
+++ z3c.dobbin/trunk/setup.py 2008-07-23 10:35:12 UTC (rev 88755)
@@ -51,5 +51,6 @@
'zope.configuration',
'z3c.saconfig',
'transaction',
- 'SQLAlchemy>0.4'],
+ 'monkey',
+ 'SQLAlchemy==0.5beta2'],
)
Modified: z3c.dobbin/trunk/src/z3c/dobbin/__init__.py
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/__init__.py 2008-07-23 09:40:46 UTC (rev 88754)
+++ z3c.dobbin/trunk/src/z3c/dobbin/__init__.py 2008-07-23 10:35:12 UTC (rev 88755)
@@ -1 +1,14 @@
-#
+from sqlalchemy import util
+from monkey import wrap
+
+import types
+
+# patch sqlalchemy.util.class_hierarchy to filter out old-style classes
+# reference:
+# http://groups.google.com/group/sqlalchemy/browse_thread/thread/97f81966830da19b#
+ at wrap(util.class_hierarchy, '02daa72fd6238e668a27fa11781b7b372548e910')
+def filtered_class_hierarchy(func, cls):
+ hier = func(cls)
+ return [cls for cls in hier if not isinstance(cls, types.ClassType)]
+
+util.class_hierarchy = filtered_class_hierarchy
Modified: z3c.dobbin/trunk/src/z3c/dobbin/mapper.py
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/mapper.py 2008-07-23 09:40:46 UTC (rev 88754)
+++ z3c.dobbin/trunk/src/z3c/dobbin/mapper.py 2008-07-23 10:35:12 UTC (rev 88755)
@@ -26,6 +26,7 @@
import soup
import zs2sa
import types
+import utility
def decode(name):
return resolve(name.replace(':', '.'))
@@ -55,8 +56,6 @@
def createMapper(spec):
"""Create a mapper for the specification."""
- interface.alsoProvides(spec, IMapped)
-
engine = Session().bind
metadata = engine.metadata
@@ -78,6 +77,7 @@
if not ifaces:
spec.__mapper__ = bootstrap.Soup
+ interface.alsoProvides(spec, IMapped)
return spec.__mapper__
# create joined table
@@ -137,6 +137,11 @@
[Mapper], table.join(
soup_table, first_table.c.id==soup_table.c.id))
+ # XXX: currently SQLAlchemy expects all classes to be new-style;
+ # we 'fix' these classes by patching on a ``__subclasses__``
+ # class-method.
+ utility.fixup_class_hierarchy(Mapper)
+
orm.mapper(
Mapper,
table,
@@ -147,6 +152,7 @@
inherit_condition=(first_table.c.id==soup_table.c.id))
spec.__mapper__ = Mapper
+ interface.alsoProvides(spec, IMapped)
return Mapper
Modified: z3c.dobbin/trunk/src/z3c/dobbin/utility.py
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/utility.py 2008-07-23 09:40:46 UTC (rev 88754)
+++ z3c.dobbin/trunk/src/z3c/dobbin/utility.py 2008-07-23 10:35:12 UTC (rev 88755)
@@ -1,6 +1,7 @@
import soup
import session as tx
import interfaces
+import types
class dictproxy(dict):
"""Dictionary proxy.
@@ -38,3 +39,24 @@
def __repr__(self):
return "<dictproxy %s>" % dict.__repr__(self)
+
+def fixup_class_hierarchy(cls):
+ hier = set([cls])
+ process = list(cls.__mro__)
+ while process:
+ c = process.pop()
+ for b in [_ for _ in c.__bases__ if _ not in hier]:
+ process.append(b)
+ hier.add(b)
+ if c.__module__ == '__builtin__':
+ continue
+
+ try:
+ subclasses = c.__subclasses__()
+ except AttributeError:
+ assert isinstance(c, types.ClassType)
+ c.__subclasses__ = classmethod(lambda cls: ())
+
+ for s in [_ for _ in subclasses if _ not in hier]:
+ process.append(s)
+ hier.add(s)
More information about the Checkins
mailing list