You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2003/08/21 20:22:22 UTC

cvs commit: httpd-python/lib/python/mod_python Session.py

grisha      2003/08/21 11:22:22

  Modified:    Doc      modpython4.tex
               lib/python/mod_python Session.py
  Log:
  Change session so that there are no reserved dictionary keys.
  
  Submitted by:	Barry Pederson
  
  Revision  Changes    Path
  1.54      +1 -4      httpd-python/Doc/modpython4.tex
  
  Index: modpython4.tex
  ===================================================================
  RCS file: /home/cvs/httpd-python/Doc/modpython4.tex,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- modpython4.tex	18 Aug 2003 20:51:23 -0000	1.53
  +++ modpython4.tex	21 Aug 2003 18:22:22 -0000	1.54
  @@ -1825,10 +1825,7 @@
   
     \class{BaseSession} is a subclass of \class{dict}. Data can be
     stored and retrieved from the session by using it as a
  -  dictionary. (A few key names are used by the \class{BaseSession}
  -  class itself for storing session metadata, they are preceeded with
  -  an underscore, so if you stay away from key names beginning with an
  -  underscore, you should be safe.)
  +  dictionary. 
   
     \var{sid} is an optional session id; if provided, such a session
     must already exist, otherwise it is ignored and a new session with a
  
  
  
  1.7       +26 -37    httpd-python/lib/python/mod_python/Session.py
  
  Index: Session.py
  ===================================================================
  RCS file: /home/cvs/httpd-python/lib/python/mod_python/Session.py,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Session.py	19 Aug 2003 14:41:39 -0000	1.6
  +++ Session.py	21 Aug 2003 18:22:22 -0000	1.7
  @@ -161,11 +161,7 @@
               # attempt to load ourselves
               self.lock()
               if self.load():
  -                if (time.time() - self._accessed) > self._timeout:
  -                    # we expired
  -                    self.delete()
  -                else:
  -                    self._new = 0
  +                self._new = 0
   
           if self._new:
               # make a new session
  @@ -211,30 +207,27 @@
           self.delete()
           self._invalid = 1
   
  -    def _load_internal(self):
  -        self._created = self["_created"]
  -        del self["_created"]
  -        self._accessed = self["_accessed"]
  -        del self["_accessed"]
  -        self._timeout = self["_timeout"]
  -        del self["_timeout"]
  -
       def load(self):
  -        if self.do_load():
  -            self._load_internal()
  -            return 1
  -        else:
  +        dict = self.do_load()
  +        if dict == None:
               return 0
   
  -    def _save_internal(self):
  -        self["_created"] = self._created
  -        self["_accessed"] = self._accessed
  -        self["_timeout"] = self._timeout
  +        if (time.time() - dict["_accessed"]) > dict["_timeout"]:
  +            return 0
  +
  +        self._created  = dict["_created"]
  +        self._accessed = dict["_accessed"]
  +        self._timeout  = dict["_timeout"]
  +        self.update(dict["_data"])
  +        return 1
   
       def save(self):
           if not self._invalid:
  -            self._save_internal()
  -            self.do_save()
  +            dict = {"_data"    : self.copy(), 
  +                    "_created" : self._created, 
  +                    "_accessed": self._accessed, 
  +                    "_timeout" : self._timeout}
  +            self.do_save(dict)
   
       def delete(self):
           self.do_delete()
  @@ -344,20 +337,18 @@
           dbm = self._get_dbm()
           try:
               if dbm.has_key(self._sid):
  -                dict = cPickle.loads(dbm[self._sid])
  -                self.clear()
  -                self.update(dict)
  -                return 1
  -            return 0
  +                return cPickle.loads(dbm[self._sid])
  +            else:
  +                return None
           finally:
               dbm.close()
               _apache._global_unlock(self._req.server, None, 0)
   
  -    def do_save(self):
  +    def do_save(self, dict):
           _apache._global_lock(self._req.server, None, 0)
           dbm = self._get_dbm()
           try:
  -            dbm[self._sid] = cPickle.dumps(self.copy())
  +            dbm[self._sid] = cPickle.dumps(dict)
           finally:
               dbm.close()
               _apache._global_unlock(self._req.server, None, 0)
  @@ -395,13 +386,11 @@
   
       def do_load(self):
           if MemorySession.sdict.has_key(self._sid):
  -            self.clear()
  -            self.update(MemorySession.sdict[self._sid])
  -            return 1
  -        return 0
  +            return MemorySession.sdict[self._sid]
  +        return None
   
  -    def do_save(self):
  -        MemorySession.sdict[self._sid] = self.copy()
  +    def do_save(self, dict):
  +        MemorySession.sdict[self._sid] = dict
   
       def do_delete(self):
           try: