Pyramid and namespaces

69 views
Skip to first unread message

Thierry Florac

unread,
Oct 15, 2014, 8:35:19 AM10/15/14
to pylons-...@googlegroups.com
Hi,

Always on the road to adapting a Zope 3 application to Pyramid...

Another of my problems is that Zope3 is handling "namespace" traversers; for example, you can use URLs like "/++skin++MySkin/...", "/++etc++site/...", or anything else by defining custom namespaces.
In my use case, the goal of such namespaces is generally to get a resource throught an adapter. For example: "myimage/++display++500x500.png" will use an adapter to get a thumbnail of 500x500 px of an image.

My question is simple: what is the best way with Pyramid to handle such case? Should I have to write a custom traverser? Use a router ??
Maybe it looks like an hybrid URL, but where traversing should be used before routing...?

Thanks for any advise,
Thierry

Chris McDonough

unread,
Oct 15, 2014, 12:18:37 PM10/15/14
to pylons-...@googlegroups.com
On 10/15/2014 08:35 AM, Thierry Florac wrote:
> Hi,
>
> Always on the road to adapting a Zope 3 application to Pyramid...
>
> Another of my problems is that Zope3 is handling "namespace" traversers;
> for example, you can use URLs like "/++skin++MySkin/...",
> "/++etc++site/...", or anything else by defining custom namespaces.
> In my use case, the goal of such namespaces is generally to get a
> resource throught an adapter. For example:
> "myimage/++display++500x500.png" will use an adapter to get a thumbnail
> of 500x500 px of an image.
>
> My question is simple: what is the best way with Pyramid to handle such
> case? Should I have to write a custom traverser? Use a router ??
> Maybe it looks like an hybrid URL, but where traversing should be used
> before routing...?

Custom traverser would probably make sense for this.

>
> Thanks for any advise,
> Thierry
> --
> http://www.imagesdusport.com -- http://www.ztfy.org
>
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pylons-discus...@googlegroups.com
> <mailto:pylons-discus...@googlegroups.com>.
> To post to this group, send email to pylons-...@googlegroups.com
> <mailto:pylons-...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

Laurence Rowe

unread,
Oct 16, 2014, 1:42:28 AM10/16/14
to pylons-...@googlegroups.com


On Wednesday, 15 October 2014 05:35:19 UTC-7, Thierry Florac wrote:
Hi,

Always on the road to adapting a Zope 3 application to Pyramid...

Another of my problems is that Zope3 is handling "namespace" traversers; for example, you can use URLs like "/++skin++MySkin/...", "/++etc++site/...", or anything else by defining custom namespaces.
In my use case, the goal of such namespaces is generally to get a resource throught an adapter. For example: "myimage/++display++500x500.png" will use an adapter to get a thumbnail of 500x500 px of an image.

My question is simple: what is the best way with Pyramid to handle such case? Should I have to write a custom traverser? Use a router ??
Maybe it looks like an hybrid URL, but where traversing should be used before routing...?

If you are only using namespace traversers at the end of the url, consider replacing them with a view addressed like "myimage/@@display/500x500.png"

In that view you can access the request.subpath == ['500x500.png']

Laurence

Thierry Florac

unread,
Oct 16, 2014, 7:40:18 AM10/16/14
to pylons-...@googlegroups.com
Hi,

That looks quite elegant!
But the namespace has sometimes been recorded into resources "__name__" attribute, so is actually present into their URLs, and I'll probably have to keep it for compatibility reasons... :-/
I've already implemented a first version of a custom enhanced traverser based on default Pyramid traverser and it seems to work quite well.
But your solution may be more elegant for future use cases...

Best regards,
Thierry


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.

Jason Madden

unread,
Oct 16, 2014, 8:38:09 AM10/16/14
to pylons-...@googlegroups.com
Our application also uses a custom traverser to get namespace support. In our case, it turned out that we wanted all the additional traversing flexibility provided by `zope.traversing` so we simply used that in the traverser (this also made it easier to work with persistent registries via the subscribers in `zope.site`). This may be overkill for many use cases, but for anyone interested I've posted a hastily extracted copy at https://gist.github.com/jamadden/c11ef9cb6be8f6794261#file-traversal-py

Jason
Reply all
Reply to author
Forward
0 new messages