durusmail: quixote-users: _q_traverse suggestion
_q_traverse suggestion
2005-04-09
2005-04-09
2005-04-09
_q_traverse suggestion
Michael Davidson
2005-04-09
I'm working on my first Quixote app, and the behavior of _q_traverse bit
me. I don't know if this has confused anyone else, so I thought I'd throw
a suggestion out there and see what happens.

Right now, if there is anything left on the path, whatever is returned by
_q_traverse must be an instance of Dictionary, or an exception is thrown.
This means that attributes exposed in _q_exports must be Directory
subclasses if they are called with path remaining.

Would other people find it logical if the attribute exposed in _q_exports
could be a function that gets called that returns a Directory? Right now,
_q_lookup can return a directory, and I was mistakenly trying to copy code
from _q_lookup into custom functions:

class RootDirectory(Directory):
    _q_exports = ['', 'subdir']
    def _q_lookup(self,component):
        #this works
        if component == 'subdir':
            return MyDirSubclass()

    def subdir(self):
        #this does not work, but should it?
        return MyDirSubclass()


I think that would be more logical, and would make it easier to construct
directory subclasses on the fly if that were required.

In _q_traverse, I would change the if path line to be something like this:

if path:
    if not isinstance(obj,Dictionary):
        return obj()._q_traverse(path)
    else
        return obj._q_traverse(path)


Just wondering if I'm the only one who would find that more intuitive...

Thanks,
Michael

reply