Merge branch 'master' into python3
[wrw.git] / wrw / session.py
index 0c585a3..3185b0b 100644 (file)
@@ -1,5 +1,5 @@
-import threading, time, pickle, random, os
-import cookie, env
+import threading, time, pickle, random, os, binascii
+from . import cookie, env
 
 __all__ = ["db", "get"]
 
@@ -8,7 +8,7 @@ def gennonce(length):
 
 class session(object):
     def __init__(self, lock, expire=86400 * 7):
-        self.id = gennonce(16).encode("hex")
+        self.id = binascii.b2a_hex(gennonce(16))
         self.dict = {}
         self.lock = lock
         self.ctime = self.atime = self.mtime = int(time.time())
@@ -77,7 +77,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:
@@ -195,7 +195,7 @@ class db(object):
         data = self.backdb[sessid]
         try:
             return pickle.loads(data)
-        except Exception, e:
+        except:
             raise KeyError()
 
     def freeze(self, sess):