Examples

Path

Path provides a matching method based upon the technique of Werkzeug. The idea however was toextract this awesome matching (and sorting) technique and use it wherever and however you want, without the extra layers Werkzeug puts around it.. We use it in Avenue (routing) and Laborer (auto-parameter-providing) for example.

>>> from pandora import Path
>>> # build a simple path with a name
... blog_view = Path('blog/<name|str>')
>>> print(blog_view)
<Path (^blog\/(?P<name>[^/]+)$)>
>>> print(blog_view('blog/my-awesome-blog-post'))
{'name': 'my-awesome-blog-post'}
>>> print(blog_view('blog/this/will/not/match'))
None
>>> # another path, but with an id
... blog_by_id = Path('blog/<id|int>')
>>> print(blog_by_id('blog/45'))
{'id': 45}
>>> # a subpage of blog_view
... blog_edit = Path('blog/<name|str>/edit')
>>> # build a map of the various paths and sort them
... mapping = [blog_view, blog_by_id, blog_edit]
>>> assert sorted(mapping) == [blog_edit, blog_by_id, blog_view]