session information in cgi scripts

James Gregory james at anchor.net.au
Thu Mar 27 06:10:26 EST 2003


On Wed, 2003-03-26 at 09:35, Dale Strickland-Clark wrote:
> James Gregory <james at anchor.net.au> wrote:
> 
> >Hi all,
> >
> >I'm relatively new to python, and this is the first time I've tried to
> >use it for web stuff.
> >
> >Simple qn: Is there a module that implements session data? Or rather,
> >what is the module that implements session data? I'm using python as a
> >CGI so storing stuff in my own webserver isn't really an option. I
> >looked on http://python.org/doc/current/modindex.html and nothing leapt
> >out at me.
> >
> >Thanks,
> >
> >James.
> >
> >
> 
> There's two main ways to maintain session data. 1: Store it at the
> server and identify it with a unique session id in a cookie. 2: store
> it all in cookies and hidden form fields. You can mix the two
> approaches too. Each has advantages and disadvantages.
> 
> Either way, I'm not really sure how a module could help you in this
> one respect without dictating the wider architecture of your
> application.

What I had in mind was something like the following:

a module which contained a class that inherited from dict. This
quasi-dict's constructor would read in the appropriate cookie containing
a session id and unpickle the session info from a file in /tmp or
something. The destructor (I am assuming that python lets you define a
destructor even though it is garbage collected) for said dict would
simply pickle its contents and write it to disk. As I understand it the
dict would be destroyed at the end of the program's execution - ie after
any changes to this session data had been performed.

So then after the class definition it would just instantiate one of
these things and make it global.

Is something like this possible? Would the garbage collector do things
in the appropriate order? How do I define a destructor? And most
importantly: has someone already done this?

Thanks,

James.







More information about the Python-list mailing list