durusmail: quixote-users: _q_traverse suggestion
_q_traverse suggestion
2005-04-09
2005-04-09
2005-04-09
_q_traverse suggestion
mso@oz.net
2005-04-09
Michael Davidson wrote:
> 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.

That requirement was dropped in Quixote 2.0a5.  Now the attribute can be
anything with a ._q_traverse method/function.

> 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()

If the ._q_lookup strategy works, why not use it?

Another possibility:

      subdir = MyDirSubclass()

The only disadvantage with this is the subclass is imported for the entire
application, whether anyone uses it or not.

But as David said, the supplied ._q_traverse is just a convenient default.
 It's perfectly all right to override it if you want to do something
different.

-- Mike Orr 


reply