def __init__(self, config, environ): """ Sets configuration and environment. Creates the Backwall object. @param config: A dict containing the configuration variables. @type config: dict @param environ: A dict containing the environment variables. @type environ: dict """ super(BackWall, self).__init__() # self._config = "" # self._form = None; self._config = config self._env = environ self._session_man = SessionMan( database_dir=self._config["session_objs_dir"] ) self._template_man = TemplateMan() self._context_args = dict( os.environ, heads = "" )
class BackWall(TCGITools.TCGI): """ BackWall main class. """ def __init__(self, config, environ): """ Sets configuration and environment. Creates the Backwall object. @param config: A dict containing the configuration variables. @type config: dict @param environ: A dict containing the environment variables. @type environ: dict """ super(BackWall, self).__init__() # self._config = "" # self._form = None; self._config = config self._env = environ self._session_man = SessionMan( database_dir=self._config["session_objs_dir"] ) self._template_man = TemplateMan() self._context_args = dict( os.environ, heads = "" ) def get_config(self, key, default=""): return self._config.get( key, default ) def add_template(self, key, template): self._template_man.add_template( key, template ) def get_template(self, strTemplate): return self._template_man.get_template(strTemplate) def parse_template(self, strTemplate, dictMap): args = dict( self._context_args ) args.update( dictMap ) try: return self._template_man.get_template(strTemplate).safe_substitute(args) except AttributeError: return "" def add_template(self, key, template): self._template_man.add_template(key, template) def get_context_args(self): return self._context_args def set_py_cfg(self, py_cfg): self._py_cfg = py_cfg def get_py_cfg(self, key, default=""): return self._py_cfg.get(key, default) def session(self): """ return current session. """ try: return self._session except AttributeError: self._session = self.get_session() return self._session def get_session(self): """ get session from HTTP_COOKIE. """ if self._env["HTTP_COOKIE"] != "" : ck = Cookie.SimpleCookie(self._env['HTTP_COOKIE'] ) if ck.has_key("fsmsid"): session = self.get_session_man().get_session_from_id(ck["fsmsid"].value) return session return None # getter/setter def get_session_man(self): """ return SessionMan object. """ return self._session_man