Package moppy :: Module mop
[show private | hide private]
[frames | no frames]

Module moppy.mop

Classes
BaseHook BaseHook
CallContext CallContext
CallInterceptor CallInterceptor
MetaCallableObject MetaCallableObject A class that wraps and scripts (advises) a callable object during its call execution.
MetaObjectSystem Central Object of the Meta Object Programming System.
MetaStructuralObject MetaStructuralObject A class that injects (introduces) structure to another objects, usually without the injected object being aware of the injection.
ObjectDomain A container holding all of the regular runtime objects that we can map our MetaObjects onto.
Selection Selection
SelectionCriteria SelectionCriteria
SysModulesObjectDomain Container for all of the objects in all the modules loaded into the python runtime

Function Summary
  addMixIn(pyClass, mixInClass, makeAncestor)
Mixes in the attributes of the mixInClass into the pyClass.
  removeMixIn(pyClass, mixInClass, removeAncestor)

Function Details

addMixIn(pyClass, mixInClass, makeAncestor=0)

Mixes in the attributes of the mixInClass into the pyClass. These attributes are typically methods (but don't have to be). Note that private attributes, denoted by a double underscore, are not mixed in. Collisions are resolved by the mixInClass' attribute overwriting the pyClass'. This gives mix-ins the power to override the behavior of the pyClass.

After using MixIn(), instances of the pyClass will respond to the messages of the mixInClass.

An assertion fails if you try to mix in a class with itself.

The pyClass will be given a new attribute mixInsForCLASSNAME which is a list of all mixInClass' that have ever been installed, in the order they were installed. You may find this useful for inspection and debugging.

You are advised to install your mix-ins at the start up of your program, prior to the creation of any objects. This approach will result in less headaches. But like most things in Python, you're free to do whatever you're willing to live with. :-)

There is a bitchin' article in the Linux Journal, April 2001, Using Mix-ins with Python by Chuck Esterbrook which gives a thorough treatment of this topic.

An example, that resides in Webware, is MiddleKit.Core.ModelUser.py, which install mix-ins for SQL adapters. Search for MixIn(.

If makeAncestor is 1, then a different technique is employed: the mixInClass is made the first base class of the pyClass. You probably don't need to use this and if you do, be aware that your mix-in can no longer override attributes/methods in pyClass.

This function only exists if you are using Python 2.0 or later. Python 1.5.2 has a problem where functions (as in aMethod.im_func) are tied to their class, when in fact, they should be totally generic with only the methods being tied to their class. Apparently this was fixed in Py 2.0.

Generated by Epydoc 1.1 on Wed May 14 00:03:23 2003 http://epydoc.sf.net