Skip to content

Instantly share code, notes, and snippets.

@luhn
Created April 12, 2017 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luhn/f56873c758ae07e59d7b50db197d1751 to your computer and use it in GitHub Desktop.
Save luhn/f56873c758ae07e59d7b50db197d1751 to your computer and use it in GitHub Desktop.
URL traversal sitemap
"""
Inspect a Pyramid app using URL traversal and construct URLs for all the views.
"""
def get_resources(self, root):
resources = {
type(root): root,
}
for resource in root.values():
resources.update(self.get_resources(resource))
return resources
root_factory = config.introspector.get('root factories', None)['factory']
root = root_factory(None)
resources = self.get_resources(root)
views = config.introspector.get_category('views')
for view in views:
introspectable = view['introspectable']
context = introspectable['context']
resource = resources.get(context)
callable = introspectable['callable']
path = resource_path(resource, introspectable['name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment