X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsession.py;h=02d1983fe18cb120e606db4e2e73a8915251f4fb;hb=3414365c207c42f3a2d26edac5b5a1d0bd782d7a;hp=76324494a9c19858b56070b66498909013378e4f;hpb=f84a3f10e332cd8e67230551e3146dd900a97c0a;p=wrw.git diff --git a/wrw/session.py b/wrw/session.py index 7632449..02d1983 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -1,5 +1,5 @@ import threading, time, pickle, random, os -import cookie +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 @@ -19,7 +19,7 @@ class session(object): def __init__(self, expire = 86400 * 7): self.id = hexencode(gennonce(16)) self.dict = {} - self.lock = threading.Lock() + self.lock = threading.RLock() self.ctime = self.atime = self.mtime = int(time.time()) self.expire = expire self.dctl = set() @@ -84,7 +84,7 @@ class db(object): now = int(time.time()) with self.lock: dlist = [] - for sess in self.live.itervalues(): + for sess in self.live.values(): if sess.atime + self.freezetime < now: try: if sess.dirty(): @@ -151,7 +151,7 @@ class db(object): data = self.backdb[sessid] try: return pickle.loads(data) - except Exception, e: + except: raise KeyError() def freeze(self, sess): @@ -180,7 +180,7 @@ class dirback(object): with open(os.path.join(self.path, key), "w") as out: out.write(value) -default = db(backdb = dirback(os.path.join("/tmp", "wrwsess-" + str(os.getuid())))) +default = env.var(db(backdb = dirback(os.path.join("/tmp", "wrwsess-" + str(os.getuid()))))) def get(req): - return default.get(req) + return default.val.get(req)