Automatically create a Traverser instance if Application is given a root object
parent
f5f7e76dae
commit
d635e83431
|
@ -24,7 +24,7 @@ Please give me a docstring!
|
||||||
from milla.controllers import FaviconController
|
from milla.controllers import FaviconController
|
||||||
from milla.util import asbool
|
from milla.util import asbool
|
||||||
from webob.exc import HTTPNotFound, WSGIHTTPException, HTTPMethodNotAllowed
|
from webob.exc import HTTPNotFound, WSGIHTTPException, HTTPMethodNotAllowed
|
||||||
import milla.dispatch
|
import milla.dispatch.traversal
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
__all__ = ['Application']
|
__all__ = ['Application']
|
||||||
|
@ -36,9 +36,8 @@ class Application(object):
|
||||||
alternatively, a root object that will be passed to a new
|
alternatively, a root object that will be passed to a new
|
||||||
:py:class:`milla.dispatch.traversal.Traverser`.
|
:py:class:`milla.dispatch.traversal.Traverser`.
|
||||||
|
|
||||||
:param root: A root object, passed to a traverser, which is
|
:param obj: An object implementing the dispatcher protocol, or an
|
||||||
automatically created if a root is given
|
object to be used as the root for a Traverser
|
||||||
:param dispatcher: An object implementing the dispatcher protocol
|
|
||||||
|
|
||||||
``Application`` instances are WSGI applications.
|
``Application`` instances are WSGI applications.
|
||||||
|
|
||||||
|
@ -50,8 +49,11 @@ class Application(object):
|
||||||
|
|
||||||
DEFAULT_ALLOWED_METHODS = ['GET', 'HEAD']
|
DEFAULT_ALLOWED_METHODS = ['GET', 'HEAD']
|
||||||
|
|
||||||
def __init__(self, dispatcher):
|
def __init__(self, obj):
|
||||||
self.dispatcher = dispatcher
|
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}
|
self.config = {'milla.favicon': True}
|
||||||
|
|
||||||
def __call__(self, environ, start_response):
|
def __call__(self, environ, start_response):
|
||||||
|
|
Loading…
Reference in New Issue