Small change proposal to pyramid.config.routes

71 views
Skip to first unread message

abrinner

unread,
Jun 27, 2012, 5:26:28 AM6/27/12
to pylons...@googlegroups.com
Hello,

I propose the following changes to pyramid/config/routes.py:
372c372,375
<             pattern = self.route_prefix.rstrip('/') + '/' + pattern.lstrip('/')
---
>             if pattern:
>                 pattern = self.route_prefix.rstrip('/') + '/' + pattern.lstrip('/')
>             else:
>                 pattern = self.route_prefix

Reasoning:
Take the following example:
from pyramid.config import Configurator

# maybe defined in some included application 
def routes(config):
    config.add_route('example', '')

# maybe the configuration of an including application 
if __name__ == '__main__':
    config = Configurator()
    config.include(routes, route_prefix="/prefix")

This will always generate the following route: 
Notice the trailing "/" in the route, although I haven't specified it in my configuration.
With the change I posted above it would be possible to define, whether the final route should have a trailing "/" or not.

It would still have a bias towards having a trailing "/" as both the including and the included application can specify one:
# included application:
def routes(config):
    config.add_route('example', '/')

# including application:
if __name__ == '__main__':
    config = Configurator()
    config.include(routes, route_prefix="/prefix/")

This would both result in the following route:
but the first example would have this route:
An existing trailing slash in either of the configurations wouldn't be removed and if there is none defined, it wouldn't be added. I think, that this would be the expected behavior.

Cheers,

   Andreas


Chris McDonough

unread,
Jun 27, 2012, 9:25:02 AM6/27/12
to pylons...@googlegroups.com
You'll want to look-at/participate-in
https://github.com/Pylons/pyramid/issues/406

- C
Reply all
Reply to author
Forward
0 new messages