import threading, time, pickle, random, os
-import cookie, env
+from . import cookie, env, proto
__all__ = ["db", "get"]
-def hexencode(str):
- ret = ""
- for byte in str:
- ret += "%02X" % (ord(byte),)
- return ret
-
def gennonce(length):
- nonce = ""
- for i in xrange(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 = proto.enhex(gennonce(16))
self.dict = {}
self.lock = lock
self.ctime = self.atime = self.mtime = int(time.time())
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:
data = self.backdb[sessid]
try:
return pickle.loads(data)
- except Exception, e:
+ except:
raise KeyError()
def freeze(self, sess):