turning off new-style classes

John Lenton <[email protected]> Fri, 2 Jul 2004 10:50:52 -0300
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
is there an easy way to revert to 0.9-pre-16 behaviour of creating
"old-style" classes? zope's security seems to choke on new-style---or
is there a way to make it work with new-style classes?

attached is the __init__.py I use in zope... maybe somebody can
enlighten me on a better way to do it?

/me is in total newbie mode

-- 
John Lenton ([email protected]) -- Random fortune:
bash: fortune: command not found
__init__.py (text/x-python, 1.1 KB)
# Load the model

from Modeling import ModelSet, Model
from Modeling.EditingContext import EditingContext
import os, os.path, glob

model_name = __name__.split('.')[-1]

if ModelSet.defaultModelSet().modelNamed(model_name) is None:
    mydir = os.path.abspath(os.path.dirname(__file__))
    model=Model.searchModel(model_name, mydir, verbose=0)

    if not model:
        import warnings
        warnings.warn("Couldn't load model "+model_name)
    else:
        ModelSet.defaultModelSet().addModel(model)

try:
    from Products.PythonScripts.Utility import allow_module, allow_class
    import zLOG

    os.chdir(os.path.dirname(os.path.dirname(__file__)))

    allow_class(EditingContext)
    allow_module('Modeling.Qualifier')
    for i in glob.glob(os.path.join(model_name, '[A-Z]*.py')):
        k = i[len(model_name)+1:-3]
        module = __import__("%s.%s" % (model_name, k), globals(), locals(), k)
        allow_module(module.__name__)
        allow_class(getattr(module, k))

    zLOG.LOG(model_name, zLOG.INFO, 'loaded', model_name+' has loaded successfully')
except ImportError:
    pass