On Jul 9, 3:24 am, SergeyPo <[email protected]> wrote:
> If I put old (v 1.75) regex there (line 75), version 1.65.1 stops
> working - says invalid on any request like 127.0.0.1:8000 , admin/
> default/index etc:
>
> OLD REGEX:
> regex_url = \
> re.compile('(?:^$)|(?:^\w+/?$)|(?:^\w+/[\w\-]+/?$)|(?:^\w+/[\w\-]
> +/
> \w+/?$)|(?:^\w+/[\w\-]+/\w+(/[\w\-]+(\.[\w\-\=]+)*)+/?$)|(?:^(\w+)/
> static(/[\w\-\=]+(\.[\w\-]+)*)+$)'
> )
>
> NEW REGEX:
> regex_url = \
> re.compile('(^/(?P<b>\w+)/static/(?P<x>(\w[\-\=\./]?)*)$)|(^(/(?
> P<a>\w+)(/(?P<c>\w+)(/(?P<f>\w+)(\.(?P<e>\w+))?(/(?P<s>(\w[\-\=\./]?)
> +))?)?)?)?/?$)')
>
> They are so different that it would take me ages to understand...
> Don't have time right now to find in versions when it changed but if
> anybody has idea please help.
There's a lot to be said for using re.X when writing expressions like
this. Here's a quick hack as the current one.
It's not tested, and I'm not all that great at making them readable,
but at least you can work out in a straightforward way what's going on.
One thing that jumps out at me (assuming I've done it right) is that
the handling of 'sub' and 'ext' doesn't match the documenting comment;
they're in reverse order.
A small point: you don't need to escape dot in character classes, nor
minus if you put it first, nor (I think) equals ever. So [\w\-][\=\./]
could be [-\w][=./]. I think. (I find that pattern a little puzzling,
btw.)
# pattern to find valid paths in url /application/controller/...
# this could be:
# for static pages:
# /<b:application>/static/<x:file>
# for dynamic pages:
# /<a:application>[/<c:controller>[/<f:function>[/<s:sub>]]]
[.<e:ext>]
# application, controller, function and ext may only contain [a-zA-
Z0-9_]
# file and sub may also contain '-', '=', '.' and '/'
regex_url = \
re.compile('(^/(?P<b>\w+)/static/(?P<x>(\w[\-\=\./]?)*)$)|(^(/(?
P<a>\w+)(/(?P<c>\w+)(/(?P<f>\w+)(\.(?P<e>\w+))?(/(?P<s>([\w\-][\=\./]?)
+))?)?)?)?/?$)', re.X)
regex_url = re.compile(r'''
(^ # static pages
/(?P<b> \w+) # b=app
/static # /b/static
/(?P<x> (\w[\-\=\./]?)* ) # x=file
$)
| # dynamic pages
(^( # (/a/c/f.e/s)
/(?P<a> \w+ ) # /a=app
( # (/c.f.e/s)
/(?P<c> \w+ ) # /a/c=controller
( # (/f.e/s)
/(?P<f> \w+ ) # /a/c/f=function
( # (.e)
\.(?P<e> \w+ ) # /a/c/f.e=extension
)?
( # (/s)
/(?P<s> # /a/c/f.e/s=sub
( [\w\-][\=\./]? )+
)
)?
)?
)?
)?
/?$) # trailing slash
''', re.X)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---