7. Basic usage
And creating WSGI app
>>> from wsgiref.simple_server import make_server
>>> from gargant.dispatch import make_wsgi_app
>>> app = make_wsgi_app(tree)
>>> httpd = make_server('', 8000, app)
>>> httpb.serve_forever()
8. Node
gargant.dispatch.Node is not just for creating a WSGI application.
>>> tree = Node((path_matching(['']),),
... case='dolls')
>>> node = tree({'PATH_INFO': '/'})
>>> node.case # 'dolls'
10. Matching
matchings is not only path_matching
>>> tree = Node((path_matching(['']),
... method_matching('get'),
... lambda environ: True),
... case='dolls',
... )
>>>
>>> node = tree({'PATH_INFO': '/',
... 'REQUEST_METHOD': 'GET'})
>>> node.case # 'dolls'
matchings return function handling environ
All of matchings return values (as bool True), the node will be
matched
11. URL args
node.metched is values returned by matchings
>>> tree = Node((path_matching(['']),),
... case='doll_list',
... children=(
... Node((path_matching(['{doll}']),),
... case='doll_detail',
... ),
... ))
>>>
>>> node = tree({'PATH_INFO': '/first'})
>>> node.case # 'doll_detail'
>>> node.matched[0]['doll'] # 'first'
12. and more...
Adaptation of each path
iteration leaf node to root node
Getting URL from node.name (future)