X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsession.py;h=f9b4a3f446b9f7fd704834672b8b465f69f1c44a;hb=e4ccd996d1e123d57d8b03a42d8ca71479458f12;hp=e7d85817700e755c4869b654526fc349f75cc139;hpb=d38b200493b3ed263dbf10581d6d204462ed68c4;p=wrw.git diff --git a/wrw/session.py b/wrw/session.py index e7d8581..f9b4a3f 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -1,23 +1,14 @@ -import threading, time, pickle, random, os +import threading, time, pickle, random, os, binascii from . import cookie, env __all__ = ["db", "get"] -def hexencode(str): - ret = "" - for byte in str: - ret += "%02X" % (ord(byte),) - return ret - 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): - self.id = hexencode(gennonce(16)) + self.id = binascii.b2a_hex(gennonce(16)).decode("us-ascii") self.dict = {} self.lock = lock self.ctime = self.atime = self.mtime = int(time.time())