def __init__(self, cookie_dict=None, cookie_object=None): self.aes_chipher = None if cookie_object is not None: CookieDealer.__init__(self, cookie_object) elif cookie_dict is not None: CookieDealer.__init__(self, self.create_cookie_object(cookie_dict), cookie_dict["ttl"]) else: CookieDealer.__init__(self, None)
class SessionSqllite3(object): def __init__(self, environ, cookie_name, dict_path): self.environ = environ self.cookie_dealer = CookieDealer() self.cookie_name = cookie_name self.session_dict = Sqllite3Dict(dict_path) def get_current_session(self, environ): session_key = self.cookie_dealer.get_cookie_value(self.get_cookie(), self.cookie_name) if session_key is None: session_key = uuid4().urn self.cookie_dealer.create_cookie(session_key, "session", self.cookie_name) self.session_dict[session_key] = {} self.session_key = session_key return self def get_cookie(self): return self.environ["HTTP_COOKIE"] def clear_session(self): for key in self.session_dict[self.session_key]: del self.session_dict[self.session_key][key] def __setitem__(self, item, val): self.session_dict[self.session_key][item] = val def __getitem__(self, key): return self.session_dict[self.session_key][key] def __contains__(self, item): return item in self.session_dict[self.session_key] def __delitem__(self, key): del self.session_dict[self.session_key][key] def keys(self): return self.session_dict[self.session_key].keys()
def __init__(self, environ, cookie_name, dict_path): self.environ = environ self.cookie_dealer = CookieDealer() self.cookie_name = cookie_name self.session_dict = Sqllite3Dict(dict_path)