[Grok-dev] New base class in Grok

Souheil CHELFOUH trollfot at gmail.com
Sun Oct 25 12:22:31 EDT 2009


Hello Grokkers,

There's something I use a lot in zope in general : the namespace traverser.
Out of the box, Grok proposes traversers, but no namespace traversers.
What do you think, if we add it there ? I can do it, of course, just
asking to be sure people want it there.

Code would be :

class NamespaceTraverser(grok.MultiAdapter):
    grok.baseclass()
    grok.adapts(Interface, IHTTPRequest)
    grok.provides(ITraversable)

    def __init__(self, context, request):
        self.context = context
        self.request = request


    def traverse(self, name, stack):
        raise NotImplementedError('You have to implement your own method')


Actually, it would be much better to use a grok.layer and grok.context
directives, on that component.
It would make it much more pluggable.For that, we'd need to use a
grokker very similar to "TraverserGrokker" which is not reusable in
this case.
I don't know if you, guys, use a lot of Namespace Traversers, but,
it's a very convenient component and I'm definitly willing to see that
in Grok.

code with dedicated grokker, would be:

class NamespaceTraverser(grok.MultiAdapter):
    grok.baseclass()
    grok.context(Interface)
    grok.layer(IHTTPRequest)
    grok.provides(ITraversable)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    def traverse(self, name, stack):
        raise NotImplementedError('You have to implement your own method')


Cheers
- Souheil


More information about the Grok-dev mailing list