X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=blobdiff_plain;f=wrw%2Fsession.py;h=814182759d584e30e5aff52df6c7781815e74458;hp=e7d85817700e755c4869b654526fc349f75cc139;hb=HEAD;hpb=919b8a4ff35da1fce73f238754ef376705c52e18 diff --git a/wrw/session.py b/wrw/session.py index e7d8581..8141827 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -1,23 +1,14 @@ import threading, time, pickle, random, os -from . import cookie, env +from . import cookie, env, proto __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 = proto.enhex(gennonce(16)) self.dict = {} self.lock = lock self.ctime = self.atime = self.mtime = int(time.time())