X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsession.py;h=d9907ccada0c83d349af01e82113f6123206a29e;hb=5218a0fd274ad9167d47b9c9929b089766cd2584;hp=19bdb6b6195e805d5506060604a3fb6a4ba4be03;hpb=d99a17a601c0680a325338189e6eeac0eb7d7bce;p=wrw.git diff --git a/wrw/session.py b/wrw/session.py index 19bdb6b..d9907cc 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -1,5 +1,5 @@ import threading, time, pickle, random, os -import cookie, env +from . import cookie, env __all__ = ["db", "get"] @@ -11,7 +11,7 @@ def hexencode(str): def gennonce(length): nonce = "" - for i in xrange(length): + for i in range(length): nonce += chr(random.randint(0, 255)) return nonce @@ -86,7 +86,7 @@ class db(object): def clean(self): now = int(time.time()) with self.lock: - clist = self.live.keys() + clist = list(self.live.keys()) for sessid in clist: with self.lock: try: @@ -164,6 +164,12 @@ class db(object): self.cthread.setDaemon(True) self.cthread.start() + def mksession(self, req): + return session(threading.RLock()) + + def mkcookie(self, req, sess): + cookie.add(req, self.cookiename, sess.id, path=self.path) + def fetch(self, req): now = int(time.time()) sessid = cookie.get(req, self.cookiename) @@ -173,13 +179,13 @@ class db(object): raise KeyError() sess = self._fetch(sessid) except KeyError: - sess = session(threading.RLock()) + sess = self.mksession(req) new = True def ckfreeze(req): if sess.dirty(): if new: - cookie.add(req, self.cookiename, sess.id, path=self.path) + self.mkcookie(req, sess) with self.lock: self.live[sess.id] = [sess.lock, sess] try: @@ -196,7 +202,7 @@ class db(object): data = self.backdb[sessid] try: return pickle.loads(data) - except Exception, e: + except: raise KeyError() def freeze(self, sess):