Dolda2000 GitWeb
/
wrw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Enable iterables to be passed as new SP nodes.
[wrw.git]
/
wrw
/
session.py
diff --git
a/wrw/session.py
b/wrw/session.py
index
43b9087
..
f9b4a3f
100644
(file)
--- a/
wrw/session.py
+++ b/
wrw/session.py
@@
-1,23
+1,14
@@
-import threading, time, pickle, random, os
-import cookie, env
+import threading, time, pickle, random, os
, binascii
+
from .
import cookie, env
__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 xrange(length):
- nonce += chr(random.randint(0, 255))
- return nonce
+ return os.urandom(length)
class session(object):
class session(object):
- def __init__(self, lock, expire
=
86400 * 7):
- self.id =
hexencode(gennonce(16)
)
+ def __init__(self, lock, expire
=
86400 * 7):
+ self.id =
binascii.b2a_hex(gennonce(16)).decode("us-ascii"
)
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())
@@
-39,7
+30,7
@@
class session(object):
def __getitem__(self, key):
return self.dict[key]
def __getitem__(self, key):
return self.dict[key]
- def get(self, key, default
=
None):
+ def get(self, key, default
=
None):
return self.dict.get(key, default)
def __setitem__(self, key, value):
return self.dict.get(key, default)
def __setitem__(self, key, value):
@@
-74,7
+65,7
@@
class session(object):
return "<session %s>" % self.id
class db(object):
return "<session %s>" % self.id
class db(object):
- def __init__(self, backdb
= None, cookiename = "wrwsess", path =
"/"):
+ def __init__(self, backdb
=None, cookiename="wrwsess", path=
"/"):
self.live = {}
self.cookiename = cookiename
self.path = path
self.live = {}
self.cookiename = cookiename
self.path = path
@@
-86,7
+77,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:
@@
-204,7
+195,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):
@@
-235,7
+226,7
@@
class dirback(object):
with open(os.path.join(self.path, key), "w") as out:
out.write(value)
with open(os.path.join(self.path, key), "w") as out:
out.write(value)
-default = env.var(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.val.get(req)
def get(req):
return default.val.get(req)