On Sun, Jun 3, 2012 at 2:04 AM, Jonathan Lundell <[email protected]> wrote:
> On Jun 2, 2012, at 5:55 PM, Ricardo Pedroso wrote:
>>
>> On Sat, Jun 2, 2012 at 4:08 PM, Bruce Wade <[email protected]> wrote:
>>> Yeah that fixed that one problem
>>>
>>> I found IF there is a space in the file name it will not work, and if it
>>> doesn't use ascii characters as LighDot said it wont work. Do you know which
>>> part of web2py code handles this or if it is possible to make it work with
>>> Chinese Characters?
>>>
>>
>> It's in gluon/rewrite.py the following regex:
>>
>> regex_static = re.compile(r'''
>> (^ # static pages
>> /(?P<b> \w+) # b=app
>> /static # /b/static
>> /(?P<x> (\w[\-\=\./]?)* ) # x=file <--- HERE
>> $)
>> ''', re.X)
>>
>> If you change the line marked with "HERE" to:
>> /(?P<x> (.*) ) # x=file
>>
>> it should work. Be aware that could be some implications with this
>> change, I'm not a regex expert.
>
> FWIW, the parametric router lets you override the regex pattern that's used
> for path validation. The default pattern is:
>
> file_match = r'(\w+[-=./]?)+$', # legal file (path) name
I didn't now about this one, thanks Jonathan.
In fact the router mechanism is still a little bit obscure to me.
I notice now that file_match is documented in router.example.py.
So I copy router.example.py to routes.py and defined the routers dict like this:
routers = dict(
# base router
BASE = dict(
default_application = 'welcome',
file_match = r'(.*)$', # legal file (path) name
),
)
and it worked woth chinese chars in a filename.
Is this the correct place to use file_match?
Ricardo