Some time ago, I wrote to the list to ask for help with StackedObjectProxy:

  [ Groups doesn't seem to have it in search results, but my message was on
Sept. 14 ]

I was never able to grok the instructions in the context of my app, so I
started with a naked pylons app and tried to figure it out. I made a
pylons_minimal app called "sop" and inside of sop there is a module called "
mymodule.py":

    # mymodule.py
    from paste.registry import StackedObjectProxy

    real_container = {'val' : 'DEFAULT'}
    sop_container = StackedObjectProxy(name="my container")

Then, I made a controller named "ack.py":

    #ack.py
    import logging
    from sop.controllers import *
    log = logging.getLogger(__name__)

    from sop.mymodule import sop_container

    class AckController(BaseController):

        def __call__(self, environ, start_response):
            from sop.mymodule import sop_container, real_container
            environ['paste.registry'].register(sop_container,
real_container)
            return BaseController.__call__(self, environ, start_response)

        def index(self):
            return "sop_container val is '%s'" % sop_container['val']

        def push(self):
            sop_container['val'] = "PUSHED"
            return "pushed it: '%s'" % sop_container['val']

Running this app and hitting http://localhost:5000/ack, I get the expected
result:

    sop_container val is 'DEFAULT'

Then I hit http://localhost:5000/ack/push, I get:

    pushed it: 'PUSHED'

Then when I hit index again, I get:

    sop_container val is 'PUSHED'

...

So obviously I'm still misunderstanding something here. If sop_container is
a wrapper to "real_container" that exists per-request, why does val stay
"PUSHED" on another request? I was expecting the modified container (the one
that has "PUSHED") to disappear after the request that set it that way was
done, leaving the container value as "DEFAULT" for other requests.

This trivial example begs the question: why would you want to do that? In my
real application, the container object is much more complex, is the answer.
I have some objects I want to use in a request-specific manner that I don't
want to re-instantiate for each request.

I have tried moving the register command out of the __call__ and into the
module level, and into the action itself, etc. No dice -- I get a thread
error.

Sorry if I'm being dense; I have really tried to grok the
StackedObjectProxy.__doc__ and also the email referenced above, but I just
don't seem to get it: I think I have a fundamental misunderstanding of the
nature of SOP. Can I get another nudge in the right direction?

Thanks!

--~--~---------~--~----~------------~-------~--~----~
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