Hi everyone, 

I'm beginning to use web.py framework which is a little bit tricky when it 
comes to play with session. 
First, the official documentation <http://webpy.org/cookbook/sessions> is 
clearly outdated when talking about session. (I made a pull request to 
update the "counter" example).
The counter is easy as i manipulate a primitive type.
But when i want to store an object into session i'm stuck.   It seems that 
each call to different function manipulate a different instance.

So i wanted to know if a session can store object ?
My objective is to share the same object "foo" between function calls.

For more clarity here the code i use: 

import web
import shelve

from Elevator import elevator
        

urls = (
    '/call', 'call',
    '/go', 'go', 
    '/userHasEntered', 'userHasEntered', 
    '/userHasExited', 'userHasExited', 
    '/reset', 'reset', 
    '/nextCommand', 'nextCommand', 
)

sessionObject = shelve.open('session')
shelfStore = web.session.ShelfStore(sessionObject)
app = web.application(urls, globals())

class call:        
    def GET(self):
        session = web.session.Session(app, shelfStore)
        atFloor = web.input().get('atFloor')
        print atFloor
        try:
            elevator = session.store.shelf["elevator"]
        except Exception:
            session.store.shelf["elevator"] = elevator()
            elevator = session.store.shelf["elevator"]
        print "First elevator instance: ", elevator
        elevator.call(atFloor)
        return web.http.web.OK

class go:
    def GET(self):
        session = web.session.Session(app, shelfStore)
        elevator = session.store.shelf["elevator"]
        elevator.go()
        return web.http.web.OK

class userHasEntered:
    def GET(self):
        session = web.session.Session(app, shelfStore)
        elevator = session.store.shelf["elevator"]
        elevator.userHasEntered()
        return web.http.web.OK

class userHasExited:
    def GET(self):
        session = web.session.Session(app, shelfStore)
        elevator = session.store.shelf["elevator"]
        elevator.userHasExited()
        return web.http.web.OK

class nextCommand:
    def GET(self):
        session = web.session.Session(app, shelfStore)
        elevator = session.store.shelf["elevator"]
        print "second elevator instance: ", elevator
        return elevator.getNextMove()

class reset:
    def GET(self): 
        print "reset"
        return web.http.web.OK

if __name__ == "__main__":
    app.run()



What is the purpose of the elevator? Doesn't matter. My problem is that i 
can't share the same elevator instance between each methods (call, go, ...)

Thx for your answers.

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to