gargant.dispatch, a flexible dispatcher for wsgi

15
gargant.dispatch a flexible dispatcher for WSGI @hirokiky

Upload: hirokiky

Post on 12-Jun-2015

294 views

Category:

Entertainment & Humor


0 download

DESCRIPTION

Talking about gargant.dispatch, dispatcher library for WSGI applications. https://pypi.python.org/pypi/gargant.dispatch

TRANSCRIPT

Page 1: gargant.dispatch, a flexible dispatcher for WSGI

gargant.dispatcha flexible dispatcher for WSGI

@hirokiky

Page 2: gargant.dispatch, a flexible dispatcher for WSGI

@hirokiky

Contributing to Django, django-localflavor

Admin of djangoproject.jp

BePROUD Inc

Page 3: gargant.dispatch, a flexible dispatcher for WSGI

Talk about pure WSGI libraryNot Django

Page 5: gargant.dispatch, a flexible dispatcher for WSGI

gargant.dispatchA dispatcher for WSGI application.

now available on PyPI

2.7, 3.3 support

Page 6: gargant.dispatch, a flexible dispatcher for WSGI

Basic usageCreating tree

>>> from gargant.dispatch import Node, path_matching

>>> from path.to.yours import wsgi_app

>>> tree = Node((path_matching(['']),),...             case=wsgi_app,...             name='first')            

Base setting (a.k.a Routing)

path.to.yours.wsgi_app will be called when PATH_INFO='/'

Page 7: gargant.dispatch, a flexible dispatcher for WSGI

Basic usageAnd 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()            

Page 8: gargant.dispatch, a flexible dispatcher for WSGI

Nodegargant.dispatch.Node is not just for creating a WSGI application.

>>> tree = Node((path_matching(['']),),...             case='dolls')

>>> node = tree({'PATH_INFO': '/'})>>> node.case  # 'dolls'            

Page 9: gargant.dispatch, a flexible dispatcher for WSGI

Hierarchy

>>> tree = Node((path_matching(['']),),...             case='dolls',...             children=(...                 Node((path_matching['fifth']),...                      case='shinku'),...             ))>>>>>> node = tree({'PATH_INFO': '/fifth'})>>> node.case  # 'shinku'

>>> node = tree({'PATH_INFO': '/'})>>> node.case  # 'dolls'            

Page 10: gargant.dispatch, a flexible dispatcher for WSGI

Matchingmatchings 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 bematched

Page 11: gargant.dispatch, a flexible dispatcher for WSGI

URL argsnode.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'            

Page 12: gargant.dispatch, a flexible dispatcher for WSGI

and more...Adaptation of each pathiteration leaf node to root nodeGetting URL from node.name (future)

Page 13: gargant.dispatch, a flexible dispatcher for WSGI

Let's write dispatchergargant.dispach is experimental/for education project

please give me your feedback

Page 14: gargant.dispatch, a flexible dispatcher for WSGI