On Aug 8, 2010, at 8:31 AM, Jonathan Lundell wrote:

> I've been advocating the use of doctests in routes.py to debug problems. 
> Here's another doctest you can use (I'll send a patch to Massimo that adds an 
> example).
> 
>>>> compile_re('.*http://otherdomain.com.* (?P<any>.*)', 
>>>> '/app/ctr\g<any>')[0].pattern
>    '^.*http://otherdomain.com.* (?P<any>.*)$'
>>>> compile_re('.*http://otherdomain.com.* (?P<any>.*)', '/app/ctr\g<any>')[1]
>    '/app/ctr\\\\g<any>'
>>>> compile_re('/$c/$f', '/init/$c/$f')[0].pattern
>    '^.*?:https?://[^:/]+:[a-z]+ /(?P<c>[\\\\w_]+)/(?P<f>[\\\\w_]+)$'
>>>> compile_re('/$c/$f', '/init/$c/$f')[1]
>    '/init/\\\\g<c>/\\\\g<f>'
> 
> For the trunk version, the import line needs to change to this:
> 
>    from gluon.rewrite import select, load, filter_url, filter_out, 
> filter_err, compile_re
> 
> Notice that the backslash escaping gets a little confusing. I can't figure 
> out how to use raw strings properly here; so it goes.

One more note. All the other doctests in routes.example.py use the patterns 
defined earlier in the file. The compile_re tests are entirely self-contained, 
so you can easily add them without any other editing. Just copy 
routes.example.py to, say, routes.test.py, and add some compile_re tests, and 
you're in business.

Reply via email to