Exposing methods that aren't Python identifiers

141 views
Skip to first unread message

Barry Warsaw

unread,
Dec 10, 2013, 9:27:12 PM12/10/13
to pytho...@googlegroups.com
I'm investigating whether wsme+pecan will be a good Python 3 compatible replacement for restish.  My urls all start with the API number as the first path component, e.g.:


The problem seems to be that I can't @expose (or @wsexpose) the '3.0' path component on my root object (a subclass of WSRoot) because '3.0' isn't a Python identifier and thus not a valid method name.  Is there some hack I can add to make this work?

Christophe de Vienne

unread,
Dec 11, 2013, 4:12:16 AM12/11/13
to pytho...@googlegroups.com
Hello Barry,

First, if you use wsme with pecan, you do not have to use WSRoot as wsme
integrates tighly in the pecan RestController (see the doc [1]).

If you do use pecan RestController, then the routing will be done by
pecan, so you should look first into the pecan API to see how to expose
a function under a different name.
If it is possible (probably by adding a parameter to the pecan expose
decorator), then you can try and hack the wsme.pecan adapter so you can
provide this option to the wsmeext.pecan.expose decorator.

If you have a patch (with a unittest [2]), please push it to gerrit, it
will be happilly merged.

An alternative is of course to simply change the url scheme by using
"v30" instead of "3.0", which is, IIRC, what the ceilometer api does.

Hope this will help,

Christophe

[1] https://wsme.readthedocs.org/en/latest/integrate.html#pecan
[2] see tests/pecantest/test/tests/test_ws.py and
tests/pecantest/test/controllers/ws.py

Le 11/12/2013 03:27, Barry Warsaw a �crit :
> --
> You received this message because you are subscribed to the Google
> Groups "python-wsme" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to python-wsme...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Barry Warsaw

unread,
Dec 12, 2013, 12:55:20 PM12/12/13
to pytho...@googlegroups.com
I haven't quite wrapped my head around RestController, so I'm not sure if it will work for me (I might have to drop down to lower level pecan), but thanks, I will definitely investigate that.

Unfortunately I cannot change my URL scheme.  We use this in Mailman 3 and since we're in beta, we don't want to change our urls in backward incompatible ways.

I'll keep hacking at it though... :)


On Wednesday, December 11, 2013 4:12:16 AM UTC-5, Christophe de Vienne wrote:
Hello Barry,

First, if you use wsme with pecan, you do not have to use WSRoot as wsme
integrates tighly in the pecan RestController (see the doc [1]).

If you do use pecan RestController, then the routing will be done by
pecan, so you should look first into the pecan API to see how to expose
a function under a different name.
If it is possible (probably by adding a parameter to the pecan expose
decorator), then you can try and hack the wsme.pecan adapter so you can
provide this option to the wsmeext.pecan.expose decorator.

If you have a patch (with a unittest [2]), please push it to gerrit, it
will be happilly merged.

An alternative is of course to simply change the url scheme by using
"v30" instead of "3.0", which is, IIRC, what the ceilometer api does.

Hope this will help,

Christophe

[1] https://wsme.readthedocs.org/en/latest/integrate.html#pecan
[2] see tests/pecantest/test/tests/test_ws.py and
tests/pecantest/test/controllers/ws.py

Le 11/12/2013 03:27, Barry Warsaw a �crit :

Doug Hellmann

unread,
Dec 13, 2013, 11:58:23 AM12/13/13
to pytho...@googlegroups.com, Ryan Petrello
Hi, Barry,

I asked Ryan Petrello, the main Pecan maintainer, and he put together a simple example at https://gist.github.com/ryanpetrello/7935031 using the _lookup() feature of Pecan's controller class.

I think we'll need something similar in OpenStack, so it's very likely that we'll add a feature to Pecan to handle this sort of routing directly using some sort of alias in the expose decorator, as Christophe suggested. I'd love to have your input on a good API for that.

Doug
Reply all
Reply to author
Forward
0 new messages