I'm doing something similar now - I've wrapped add_route, and the wrapper 
expands the {foo} into explicit non-greedy regexs:

def add_dot_route(config, name, pattern, *a, **kw):
    "Permit routes with dots like pylons, eg {entity}{.format}"
    dotnames = re.findall(r'{\.([^}]+)}', pattern)
    if dotnames:
        # Replace {field} with an explicit non-greedy version so {.format} 
works
        pattern = re.sub(r'\{([_a-zA-Z][_a-zA-Z0-9]*?)\}', 
r'{\1:(?:[^/]+?)}', pattern)
        pattern = re.sub(r'\{\.([_a-zA-Z][_a-zA-Z0-9]*?)\}', 
r'{\1:(?:\.[^/.]+)?}', pattern)
    config.add_route(name, pattern, *a, **kw)

I could probably simplify the regex subs (and collapse them into a single 
re.sub). The result doesn't work quite as well as pylons, though (the view 
sees the leading dot).

On Friday, 23 March 2018 05:34:36 UTC+11, Jonathan Vanasco wrote:
>
> There's also some pyramid docs on predicates and route factory under URL 
> dispatch.   I think that might be what you need - there are some threads in 
> this group on those topics.
>
> I also wrote a library `pyramid_route_7` (
> https://github.com/jvanasco/pyramid_route_7) that extends the config to 
> allow macros.  Instead of adding a route with `add_route` you use 
> `add_route_7`, which then expands the macro and calls `add_route` behind 
> the scenes.  That technique might help you a bit too.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/1196fe62-381e-40f1-b5ec-8ff01d148a24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to