Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active August 29, 2015 14:04
Show Gist options
  • Save kezabelle/3f29dc1851588554b9bb to your computer and use it in GitHub Desktop.
Save kezabelle/3f29dc1851588554b9bb to your computer and use it in GitHub Desktop.
wsgi api idea
# could sit on top of Werkzeug or Falcon ...
class MyHandler(object):
def __init__(self, request, app, parents=(), route=None):
...
def convert_id(rself, equest, value, parents=()):
# parents is always iterable; also () is a safe default parameter ...
return int(value)
def convert_something(self, request, value, parents=()):
# can proxy back to a parent's converter if necessary ...
# parents is only filled with those that try to handle it ...?
# too much boilerplate here ...
for p in parents:
parent = p(request=request, ...)
result = parent.convert_something(request=request, value=value, parents=...)
if result is not None:
return result
def allow(self, request, app, parents, ...):
# allow a view to decide if it wants to handle this at all...
return request.is_xhr
def before(self, request):
return ...
def GET(self, request, ...):
return ...
def POST(self, request, ...):
return ...
def after(self, request, response):
return response
class App(...):
def __init__(self, config, ...):
self.router = Router()
...
def __call__(self, environ, start_response):
# find best match route in self.router, probably by length
# then attempt dispatching that and any other matching routes.
return ...
app = App(config={...})
# order for parenting doesn't matter until actually routed.
app.router.add('a/{id}/b/{something}', MyHandler, name='child', parent='root')
# uri template parts end up as (?P<name>[a-zA-Z0-9_]+) and call convert_<name>
# on any route matches.
app.router.add('a/{id}/b/{something}/else', MyHandler, name='root')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment