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 python2
[wrw.git]
/
wrw
/
session.py
diff --git
a/wrw/session.py
b/wrw/session.py
index
e7d8581
..
476113a
100644
(file)
--- a/
wrw/session.py
+++ b/
wrw/session.py
@@
-1,23
+1,18
@@
import threading, time, pickle, random, os
import threading, time, pickle, random, os
-from . import cookie, env
+<<<<<<< HEAD
+import cookie, env
+=======
+from . import cookie, env, proto
+>>>>>>> master
__all__ = ["db", "get"]
__all__ = ["db", "get"]
-def hexencode(str):
- ret = ""
- for byte in str:
- ret += "%02X" % (ord(byte),)
- return ret
-
def gennonce(length):
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):
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())
self.dict = {}
self.lock = lock
self.ctime = self.atime = self.mtime = int(time.time())
@@
-86,7
+81,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 =
list(self.live.keys()
)
+ clist =
self.live.keys(
)
for sessid in clist:
with self.lock:
try:
for sessid in clist:
with self.lock:
try:
@@
-204,7
+199,7
@@
class db(object):
data = self.backdb[sessid]
try:
return pickle.loads(data)
data = self.backdb[sessid]
try:
return pickle.loads(data)
- except:
+ except
Exception, e
:
raise KeyError()
def freeze(self, sess):
raise KeyError()
def freeze(self, sess):