Dolda2000 GitWeb
/
wrw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into python3
[wrw.git]
/
wrw
/
session.py
diff --git
a/wrw/session.py
b/wrw/session.py
index
3b2b2b2
..
90d460b
100644
(file)
--- a/
wrw/session.py
+++ b/
wrw/session.py
@@
-1,5
+1,5
@@
import threading, time, pickle, random, os
import threading, time, pickle, random, os
-import cookie, env
+
from .
import cookie, env
__all__ = ["db", "get"]
__all__ = ["db", "get"]
@@
-11,7
+11,7
@@
def hexencode(str):
def gennonce(length):
nonce = ""
def gennonce(length):
nonce = ""
- for i in
x
range(length):
+ for i in range(length):
nonce += chr(random.randint(0, 255))
return nonce
nonce += chr(random.randint(0, 255))
return nonce
@@
-86,7
+86,7
@@
class db(object):
def clean(self):
now = int(time.time())
with self.lock:
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:
for sessid in clist:
with self.lock:
try:
@@
-157,15
+157,17
@@
class db(object):
else:
raise Exception("Illegal session entry: " + repr(entry[1]))
else:
raise Exception("Illegal session entry: " + repr(entry[1]))
- def fetch(self, req):
- now = int(time.time())
- sessid = cookie.get(req, self.cookiename)
- new = False
+ def checkclean(self):
with self.lock:
if self.cthread is None:
self.cthread = threading.Thread(target = self.cleanloop)
self.cthread.setDaemon(True)
self.cthread.start()
with self.lock:
if self.cthread is None:
self.cthread = threading.Thread(target = self.cleanloop)
self.cthread.setDaemon(True)
self.cthread.start()
+
+ def fetch(self, req):
+ now = int(time.time())
+ sessid = cookie.get(req, self.cookiename)
+ new = False
try:
if sessid is None:
raise KeyError()
try:
if sessid is None:
raise KeyError()
@@
-184,6
+186,7
@@
class db(object):
self.freeze(sess)
except:
pass
self.freeze(sess)
except:
pass
+ self.checkclean()
req.oncommit(ckfreeze)
return sess
req.oncommit(ckfreeze)
return sess
@@
-193,7
+196,7
@@
class db(object):
data = self.backdb[sessid]
try:
return pickle.loads(data)
data = self.backdb[sessid]
try:
return pickle.loads(data)
- except
Exception, e
:
+ except:
raise KeyError()
def freeze(self, sess):
raise KeyError()
def freeze(self, sess):