To make it easier to add stuff to SQLObject -- including the internal
stuff like joins and whatnot -- I'd like to add an event system. Right
now I'm thinking of basing it on PyDispatcher:
http://pydispatcher.sourceforge.net/
This will allow things like cascading deletes to be implemented as event
listeners. Now that I think about it, classregistry also could be
implemented that way. Though the lazy class loading that Randall has
been working on really approaches it in the opposite way (pull vs.
push). Pull (lazily) is probably better... but anyway, there's other
cases where events are useful.
One issue is that events can be a little opaque -- in that one bit of
code can listen to events and cause signficant changes, even though it
is far from the code that is calling the event. So I worry that it
hurts backtrack-ability. OTOH, it seems really useful. There's also a
question about how heavily to use it internally. E.g., I could easily
use it to do stuff on class creation, instead of putting all that logic
in __classinit__. But that doesn't necessarily *improve* anything, and
then you have to wonder what order the event listeners are called in and
whatnot. But for instance, for objects that shouldn't be shared with
subclasses (i.e., mutable class variables) it could provide a good way
to make copies of those objects.
Anyway, my proposed set of events is here:
http://svn.colorstudy.com/SQLObject/trunk/sqlobject/events.py
The other change that I'm thinking about is changing the metaclass to be
a bit more like this (from Wareweb):
def __classinit__(cls, new_attrs):
for attr, value in new_attrs.items():
cls.add_attr(attr, value, set=False)
@classmethod
def add_attr(cls, attr, value, set=True):
if set:
setattr(cls, attr, value)
if hasattr(value, '__addtoclass__'):
value.__addtoclass__(attr, cls)
This would actually replace things like ``addColumn``, as column objects
would have an __addtoclass__ method that would do all the appropriate
work to add a column. Intercepting setting of attributes on classes is
rather hard (in my experience), hence the class method. I guess if the
metaclass as a __setattribute__ method or somesuch it might be able to
intercept sets -- but it's just annoyingly hard.
Ian
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more.
http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@???
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss