import threading, time, pickle, random, os
-import cookie
+from . import cookie, env
__all__ = ["db", "get"]
def gennonce(length):
nonce = ""
- for i in xrange(length):
+ for i in range(length):
nonce += chr(random.randint(0, 255))
return nonce
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()
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():
data = self.backdb[sessid]
try:
return pickle.loads(data)
- except Exception, e:
+ except:
raise KeyError()
def freeze(self, sess):
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)