supplemental data factory

sndive at gmail.com sndive at gmail.com
Mon Nov 5 22:39:47 EST 2007


i'm trying to import a module
typeinfo that looks like so:
import xml.dom import minidom

var mapper =
{
    minidom.Element.__class__ : "Element",
    minidom.Node.__class__ : "Node"
};

then i'd write a factory method that's look roughly like this:
addBaggage(PyObject *victim)
{
PyObject *typeinfo = PyImport_ImportModule("typeInfo");
PyObject *dict = PyObject_GetAttrString(pModule, "mapper");
   PyObject *pclass = PyObject_GetAttrString( victim, "__class__");

PyObject *baggagename = PyDict_GetItem(dict, pclass);

then i'll convert baggagename into a char * and key
into a dictionary mapping char * to factory methods
or painstakingly if PyObject_IsInstance() else PyObject_IsInstance()
the whole thing (i'll have more than two entries in the mapper
and, possibly, beyond the minidom module)

for my classes. Is there a simpler way to accomplish what i'm trying
to do, for example leverage the existing metadata for minidom module?
I'm thinking maybe i can just specify a tuple of modules in
typeinfo instead and iterate on all classes in those modules.
lookups in the dictionary seem quicker though... thoughts?




More information about the Python-list mailing list