Marcel Hellkamp [recently added a small feature] to Bottle that makes it easy to inspect an application’s routes and determine if a particular route is actually for a mounted sub-application.
([Bottle is a small module written in Python for making websites].)
Route objects (items in the `app.routes` list) now have extra information when the route was created by mounting one app on another, in the form of a new key `mountpoint` in `route.config`.
Here’s a trivial app with another app mounted on it:
app1 = bottle.Bottle()
def app1_home(): return “Hello World from App1”
app2 = bottle.Bottle()
def app2_home(): return “Hello World from App2”
And a utility function that returns a generator of prefixes and routes:
for route in app.routes:
if ‘mountpoint’ in route.config:
prefix = route.config[‘mountpoint’][‘prefix’]
subapp = route.config[‘mountpoint’][‘target’]
for prefixes, route in inspect_routes(subapp):
yield [prefix] + prefixes, route
yield , route
Finally, inspecting all the routes (including mounted sub-apps) for the root Bottle object:
for prefixes, route in inspect_routes(app1):
abs_prefix = ‘/’.join(part for p in prefixes for part in p.split(‘/’))
print abs_prefix, route.rule, route.method, route.callback
This new feature is sure to revolutionise everything.