[Z3-sqlos] Re-organizing SQLOS code.

Brian Sutherland jinty at web.de
Sat Nov 26 13:02:47 CET 2005


Hi,

There are a few proposed re-orginzations I would like to do to the sqlos code.
Comments appreciated...

1. get rid of getFactory.

    in sqlos.__init__.py we have this:

    def getFactory(name, context=None, default=None):
        return zapi.queryUtility(IISQLObject, name, default=default, context=context)

    I think this is misleading, getFactory doesn't return a factory (i.e.
    something implementing IFactory). It gets registered SQLOS sub-classes.
    I propose to depreciate this and replace the few calls. This makes it
    absolutely clear to the code reader that they are querying a utility
    and not getting a factory.

    Also I propose that getUtility is called as most of the time
    returning None will result in a failure later. An immediate
    ComponentLookupError will make it clearer where bugs are.

2. Replace this:
    
    def allowedFactories(self):
        items = zapi.getFactoriesFor(ISQLObject, context=self)
        names = [name for name, factory in items]
        f = lambda name: (name, zapi.getUtility(IFactory, name))
        factories = map(f, names)
        a = lambda f, container=self: (checkFactory(container, None, f[1])
                                       and f[0] or None)
        return filter(None, map(a, factories))

    with this:

    def allowedFactories(self):
        for name, factory in zapi.getFactoriesFor(ISQLObject, context=self):
            if checkFactory(self, None, factory):
                yield name

    I am pretty sure they do the same thing, except the second is more
    efficient (one less utility lookup per factory) and clearer.

3. In quite a few package we have the form container/__init__.py where
   __init__.py is the only file and is quite small. I want to move these
   to the form container.py. It is not likely that these modules will
   grow too much in the near future.

-- 
Brian Sutherland

Metropolis - "it's the first movie with a robot. And she's a woman.
              And she's EVIL!!"



More information about the z3-sqlos mailing list