routes.py improvement

3 views
Skip to first unread message

Álvaro Justen [Turicas]

unread,
Apr 10, 2009, 4:13:15 AM4/10/09
to web...@googlegroups.com
Hi,
I want a manner to get full GET URL from client, but using a rewrite
in routes_in I can get only a half of. An example:

routes_in = (
('/(?P<all>.+)', '/myapp/default/padrao?\g<all>'),
)

In this case I can get 'full' URL (I say 'full' because I don't get
"http://127.0.0.1:800") with request.env.query_string. But in cases
that I have:

routes_in = (
('/(A|B)(?P<all>.+)', '/myapp/default/padrao?\g<all>'),
)

I can't get "A" or "B", only the expression matched by "(?P<all>.+)".
Is there an way to get "full" URL that I like - am I missing something?
If there isn't, can it be implemented to future versions?

Thanks.

--
Álvaro Justen
Peta5 - Telecomunicações e Software Livre
21 3021-6001 / 9898-0141
http://www.peta5.com.br/

mdipierro

unread,
Apr 10, 2009, 9:28:22 AM4/10/09
to web2py Web Framework
Good point! I can add this.

Massimo

On Apr 10, 3:13 am, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
wrote:

Álvaro Justen [Turicas]

unread,
Apr 10, 2009, 7:57:44 PM4/10/09
to web...@googlegroups.com
On Fri, Apr 10, 2009 at 10:28 AM, mdipierro <mdip...@cs.depaul.edu> wrote:
> Good point! I can add this.

Thanks. :-)

Another improvement: if routes_out is not defined, I think web2py can
create it directly based on routes_in, like:

routes_out = map(lambda x:(x[1], x[0]), routes_in)

If you do not want this to be default, just add as a comment in
routes.py - it can save time of many developers to don't
copy-paste-and-invert-tuples.

In fact, it won't work if you use regexes to rewrite URLs, but works
for all static cases.

mdipierro

unread,
Apr 10, 2009, 11:14:02 PM4/10/09
to web2py Web Framework
You can put this
routes_out = map(lambda x:(x[1], x[0]), routes_in)

yourself in routes. It should not be the default because if people use
regex in routes, this way of doing reversed mapping would not work.


On Apr 10, 6:57 pm, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
wrote:

Álvaro Justen [Turicas]

unread,
Apr 10, 2009, 11:58:15 PM4/10/09
to web...@googlegroups.com
On Sat, Apr 11, 2009 at 12:14 AM, mdipierro <mdip...@cs.depaul.edu> wrote:
> You can put this
> routes_out = map(lambda x:(x[1], x[0]), routes_in)
>
> yourself in routes. It should not be the default because if people use
> regex in routes, this way of doing reversed mapping would not work.

Yes, I have this code in apps that doesn't use regex. But my last
email I suggest to add it in routes.py like a *comment*, emphazising
that it can be used only in non-regex casees (and then developer only
have to uncomment the line, like other web2py code (auth, crud etc.)
to use that functionality).

Álvaro Justen [Turicas]

unread,
Apr 24, 2009, 2:51:55 AM4/24/09
to web...@googlegroups.com
On Fri, Apr 10, 2009 at 10:28 AM, mdipierro <mdip...@cs.depaul.edu> wrote:
> Good point! I can add this.
>
> Massimo
>
> On Apr 10, 3:13 am, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
> wrote:
>> Hi,
>> I want a manner to get full GET URL from client, but using a rewrite
>> in routes_in I can get only a half of. An example:
>>
>> routes_in = (
>>     ('/(?P<all>.+)', '/myapp/default/padrao?\g<all>'),
>> )
>>
>> In this case I can get 'full' URL (I say 'full' because I don't get
>> "http://127.0.0.1:800") with request.env.query_string. But in cases
>> that I have:
>>
>> routes_in = (
>>     ('/(A|B)(?P<all>.+)', '/myapp/default/padrao?\g<all>'),
>> )
>>
>> I can't get "A" or "B", only the expression matched by "(?P<all>.+)".
>> Is there an way to get "full" URL that I like - am I missing something?
>> If there isn't, can it be implemented to future versions?
>>
>> Thanks.

Will this be added?

mdipierro

unread,
Apr 24, 2009, 3:57:34 PM4/24/09
to web2py Web Framework
No. This code is dangerous because does not always work. It only work
for simple mappings that do not use regex and domainname.

On Apr 24, 1:51 am, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
wrote:

Álvaro Justen [Turicas]

unread,
Apr 24, 2009, 6:33:10 PM4/24/09
to web...@googlegroups.com
On Fri, Apr 24, 2009 at 4:57 PM, mdipierro <mdip...@cs.depaul.edu> wrote:
> No. This code is dangerous because does not always work. It only work
> for simple mappings that do not use regex and domainname.

I was talking about get full URL in request...
Even if I have a rewrite, I want to know what URL user requested:

> >> I want a manner to get full GET URL from client, but using a rewrite
> >> in routes_in I can get only a half of. An example:

> >> routes_in = (
> >> ('/(?P<all>.+)', '/myapp/default/padrao?\g<all>'),
> >> )

> >> In this case I can get 'full' URL (I say 'full' because I don't get
> >> "http://127.0.0.1:800") with request.env.query_string. But in cases
> >> that I have:

> >> routes_in = (
> >> ('/(A|B)(?P<all>.+)', '/myapp/default/padrao?\g<all>'),
> >> )

> >> I can't get "A" or "B", only the expression matched by "(?P<all>.+)".
> >> Is there an way to get "full" URL that I like - am I missing something?
> >> If there isn't, can it be implemented to future versions?

--

Reply all
Reply to author
Forward
0 new messages