On Fri, 2010-11-19 at 15:20 -0800, Ben Bangert wrote: > On Nov 19, 2010, at 2:26 PM, Alexandre Conrad wrote: > > > I don't feel I'd use that very much. It's like having globals set in > > your app, you don't really know what's happening (even though the > > context manager helps in readability). I'd rather have explicitly > > {id:int} so I am sure it is casted to whatever the "int" named > > converter returns. You know what each route does just by looking at > > it. > > The context manager would be required both to declare what converters are > valid for the scope, but also because this functionality comes from another > package in addition to pyramid you need to do something to get a different > object with add_route/add_handler. > > For non-context use, it'd be something like: > > r = routehelper(config, converters=dict(int=converter.Integer(), > month=converter.Integer(min=1, max=12)) > r.add_handler('articles', '/articles/{action}/{id:int}', handler=....) > r.add_handler('month_archives', '/archives/{month:month}'...) > > That last line is where people's custom converter names vs the marker names > might get a little odd, which is why I was thinking one could assign a > converter that would be used if the marker name was the same. Otherwise for > clarity you'd prolly have this instead: > > r = routehelper(config, converters=dict(int=converter.Integer(), > month_conv=converter.Integer(min=1, max=12)) > r.add_handler('month_archives', '/archives/{month:month_conv}'...)
If there are both regexes and converters, I'd suggest they remain separate, e.g.: {month:\d+:month_conv} Regexes are about matching, converters are about converting. - C -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-de...@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.