Hi, Wyatt.

Wyatt said:
> I want to get access to the "root" WSGI middleware, the one that is
> hit first when a request is made. In this example:
>
>     [pipeline:main]
>     pipeline = somefilter auth urlmap
>
> ...I want access to `somefilter`. I couldn't find a reference to the
> root app anywhere in the environ. Does anyone know how to access this?

You can't, because it works like this:
"""
class Middleware1(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # ... do something ...
        return self.app(environ, start_response)

class Middleware2(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # ... do something ...
        return self.app(environ, start_response)

class Middleware3(object):
    foo = "some value"
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # ... do something ...
        return self.app(environ, start_response)

pylonsapp = make_app(...)
pylonsapp = Middleware1(pylonsapp)
pylonsapp = Middleware2(pylonsapp)
pylonsapp = Middleware3(pylonsapp)
"""

So in Middleware1, for example, you cannot access Middleware3 and vice versa. 


> For now, I created a wrapper app that saves a reference to itself in
> the environ.

If you really want it, the standard way to do it is to put in the environ 
whatever you need from that middleware, not the whole middleware.

For example, if what you need is the "foo" argument of Middleware3 in 
Middleware1, you can use this:
"""
class Middleware1(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # ... do something ...
        if "middleware3.foo" in environ:
            # here it is!
        return self.app(environ, start_response)

class Middleware2(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # ... do something ...
        return self.app(environ, start_response)

class Middleware3(object):
    foo = "some value"
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # ... do something ...
        environ["middleware3.foo"] = self.foo
        return self.app(environ, start_response)

pylonsapp = make_app(...)
pylonsapp = Middleware1(pylonsapp)
pylonsapp = Middleware2(pylonsapp)
pylonsapp = Middleware3(pylonsapp)
"""

Then this value will be available in any middleware* and the application 
itself.

HTH,

PS: Not exactly "any middleware"; it will be available for any middleware 
under it... So if we had a fourth middleware, it wouldn't be able to access 
environ["middleware3.foo"].
-- 
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to