def __setitem__(self, key, value): tmp_name, tmp_path = tempfile.mkstemp(dir=self.folder) tmp = os.fdopen(tmp_name, 'wb') try: pickle.dump((time.time(), value), tmp, pickle.HIGHEST_PROTOCOL) finally: tmp.close() fullfilename = os.path.join(self.folder, recfile.generate(key)) if not os.path.exists(os.path.dirname(fullfilename)): os.makedirs(os.path.dirname(fullfilename)) self.replace(tmp_path, fullfilename)
def get_session(request, other_application='admin'): """Checks that user is authorized to access other_application""" if request.application == other_application: raise KeyError try: session_id = request.cookies['session_id_' + other_application].value session_filename = os.path.join(up(request.folder), other_application, 'sessions', session_id) if not os.path.exists(session_filename): session_filename = generate(session_filename) osession = storage.load_storage(session_filename) except Exception as e: osession = storage.Storage() return osession
def get_session(request, other_application='admin'): """Checks that user is authorized to access other_application""" if request.application == other_application: raise KeyError try: session_id = request.cookies['session_id_' + other_application].value session_filename = os.path.join( up(request.folder), other_application, 'sessions', session_id) if not os.path.exists(session_filename): session_filename = generate(session_filename) osession = storage.load_storage(session_filename) except Exception as e: osession = storage.Storage() return osession
def clear(self): # see https://github.com/web2py/web2py/issues/735 response = current.response if response.session_storage_type == 'file': target = recfile.generate(response.session_filename) try: os.unlink(target) except: pass elif response.session_storage_type == 'db': table = response.session_db_table if response.session_id: (record_id, sep, unique_key) = response.session_id.partition(':') if record_id.isdigit() and long(record_id) > 0: table._db(table.id == record_id).delete() Storage.clear(self)