From d635e83431e643cf52093b7088fc543e921d43c8 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Fri, 30 Nov 2012 22:47:06 -0600 Subject: [PATCH] Automatically create a Traverser instance if Application is given a root object --- src/milla/app.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/milla/app.py b/src/milla/app.py index 740057f..3250a90 100644 --- a/src/milla/app.py +++ b/src/milla/app.py @@ -24,7 +24,7 @@ Please give me a docstring! from milla.controllers import FaviconController from milla.util import asbool from webob.exc import HTTPNotFound, WSGIHTTPException, HTTPMethodNotAllowed -import milla.dispatch +import milla.dispatch.traversal import webob __all__ = ['Application'] @@ -36,9 +36,8 @@ class Application(object): alternatively, a root object that will be passed to a new :py:class:`milla.dispatch.traversal.Traverser`. - :param root: A root object, passed to a traverser, which is - automatically created if a root is given - :param dispatcher: An object implementing the dispatcher protocol + :param obj: An object implementing the dispatcher protocol, or an + object to be used as the root for a Traverser ``Application`` instances are WSGI applications. @@ -50,8 +49,11 @@ class Application(object): DEFAULT_ALLOWED_METHODS = ['GET', 'HEAD'] - def __init__(self, dispatcher): - self.dispatcher = dispatcher + def __init__(self, obj): + if not hasattr(obj, 'resolve'): + # Object is not a dispatcher, but the root object for traversal + obj = milla.dispatch.traversal.Traverser(obj) + self.dispatcher = obj self.config = {'milla.favicon': True} def __call__(self, environ, start_response):