X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsession.py;h=0c585a37bdd97d00551614a7c7590b58d7d76f59;hb=0d4c1b8b8da9e20c4bc9fb41ff1136283821b98e;hp=e7d85817700e755c4869b654526fc349f75cc139;hpb=03f970ca2c0e9b7f8de42c81df758081bcfd5567;p=wrw.git diff --git a/wrw/session.py b/wrw/session.py index e7d8581..0c585a3 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -1,23 +1,14 @@ import threading, time, pickle, random, os -from . import cookie, env +import cookie, env __all__ = ["db", "get"] -def hexencode(str): - ret = "" - for byte in str: - ret += "%02X" % (ord(byte),) - return ret - def gennonce(length): - nonce = "" - for i in range(length): - nonce += chr(random.randint(0, 255)) - return nonce + return os.urandom(length) class session(object): def __init__(self, lock, expire=86400 * 7): - self.id = hexencode(gennonce(16)) + self.id = gennonce(16).encode("hex") self.dict = {} self.lock = lock self.ctime = self.atime = self.mtime = int(time.time()) @@ -86,7 +77,7 @@ class db(object): def clean(self): now = int(time.time()) with self.lock: - clist = list(self.live.keys()) + clist = self.live.keys() for sessid in clist: with self.lock: try: @@ -204,7 +195,7 @@ class db(object): data = self.backdb[sessid] try: return pickle.loads(data) - except: + except Exception, e: raise KeyError() def freeze(self, sess):