Skip to content

Commit

Permalink
add mechanism for binding converters to application
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhmather committed Jun 27, 2015
1 parent 19e2022 commit b86c31c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions verktyg/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def _default_redirect_handler(app, req, exc_type, exc_value, exc_traceback):

class BaseApplication(object):
def __init__(
self, *, routes, bindings, handlers,
self, *, routes, converters, bindings, handlers,
middleware, request_class
):
self._url_map = URLMap(routes)
self._url_map = URLMap(routes, converters=converters)
self._dispatcher = Dispatcher(bindings)
self._exception_dispatcher = ExceptionDispatcher(handlers)

Expand Down Expand Up @@ -117,6 +117,7 @@ def __init__(
self._middleware = []

self._routes = []
self._converters = {}
self._bindings = []
self._handlers = []

Expand All @@ -143,6 +144,9 @@ def add_request_mixins(self, *mixins):
if mixin not in self._request_bases:
self._request_bases.append(mixin)

def add_converters(self, **converters):
self._converters.update(**converters)

def add_routes(self, *routes):
self._routes.extend(routes)

Expand Down Expand Up @@ -212,7 +216,9 @@ class Request(*self._request_bases):
pass

return Application(
routes=iter(self._routes), bindings=iter(self._bindings),
routes=iter(self._routes),
converters=dict(self._converters.items()),
bindings=iter(self._bindings),
handlers=iter(self._handlers),
middleware=iter(self._middleware),
request_class=Request,
Expand Down

0 comments on commit b86c31c

Please sign in to comment.