Python style question

Lalo Martins lalo at exoweb.net
Tue Jun 7 03:14:34 BST 2005


And so says John A Meinel on 06/06/2005 10:53 PM...
> The problem is that really you want a branch hierarchy. You can argue
> that you want a standard Branch object and a BranchStorage hierarchy. It
> doesn't really matter, but to me, that is just one more layer of
> indirection that you don't really need.

Actually, I think I like this idea.  Seems cleaner to me.  You don't
really need separate Branch classes.

Also I would put the check for "is this the right type" in the constructor.

class DeclineStorageArgs(Exception):
    pass

class Branch(object):
    # docstring and stuff...
    storage_registry = [LocalStorage]

    def __init__(self, *args, **kw):
        # ...
        for storage_class in self.storage_registry:
            try:
                self.storage = storage_class(*args, **kw)
                break
            except DeclineStorageArgs:
                pass
        # ...

    def register_storage(cls, storage_class, pos=0):
        if pos is None:
            cls.storage_registry.append(storage_class)
        else:
            cls.storage_registry.insert(pos, storage_class)


best,
                                               Lalo Martins
--
      So many of our dreams at first seem impossible,
       then they seem improbable, and then, when we
       summon the will, they soon become inevitable.
--
http://www.exoweb.net/                  mailto:lalo at exoweb.net
GNU: never give up freedom                 http://www.gnu.org/





More information about the bazaar mailing list