[Grok-dev] New base class in Grok

Jan-Wijbrand Kolman janwijbrand at gmail.com
Sun Nov 1 07:50:14 EST 2009


Hi Souheil,

Souheil CHELFOUH wrote:
> 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')

Interesting idea: this namespace traverser component is intended to have 
semantics similar to the ++skin++, ++language++, ++resource++ etc. 
namespaces, right?

I guess we could have a close look at zope.traversing and see if we can 
provided some sub types of the namespace traverse component: one that 
does shiftNameToApplication() - like "skin" and "vh", and one that 
doesn't and thus effectively can be used anywhere in the traverse path?

BTW, in your applications, are you generally using your "custom" 
namespace traversal in URLs or rather in path traversal in for example 
page templates?


If it wasn't clear, I'm +1 on putting this in Grok (to what extend does 
a new package grokcore.traversing make any sense?)

Some more thoughts:

* Is there anything useful for us here: 
http://pypi.python.org/pypi/z3c.traverser/0.2.5#additional-namespaces ?

* The namespaces in zope.traversing seem to not really differentiate on 
context nor layer basis; is that accidentally or are there reasons to 
think of why namespace traversers shouldn't really try to only work for 
certain context types or request types?

HTH
regards,
jw


regards,
jw



More information about the Grok-dev mailing list