import os,string,time import marshal import App.FindHomes tmpStorageDir=os.path.join(INSTANCE_HOME,'var','tmpStorage') def tmpStore(self,data,RESPONSE,ex=os.path.exists,jn=os.path.join): '''Marshals and stores data on a regular file given by unique id''' # Create UID tm=time ip=self.REQUEST['REMOTE_ADDR'] t=tm.gmtime(tm.time()) uid='%s%s'%(tm.strftime('%j%I%M%S',t),ip[-5:]) day=jn(tmpStorageDir,uid[:3]) hour=jn(day,uid[3:5]) minute=jn(hour,uid[5:7]) if not ex(day): os.mkdir(day) if not ex(hour): os.mkdir(hour) if not ex(minute): os.mkdir(minute) f=open(jn(minute,uid),'w') marshal.dump(data,f) f.close() RESPONSE.setCookie('tmpStorageUID',uid) return uid def tmpRetrieve(self,tmpStorageUID=None,jn=os.path.join): '''Retrieves data stored in temporary file. ''' if tmpStorageUID==None: if self.REQUEST.has_key('tmpStorageUID'): tmpStorageUID=self.REQUEST['tmpStorageUID'] else: return None uid=tmpStorageUID day=jn(tmpStorageDir,uid[:3]) hour=jn(day,uid[3:5]) minute=jn(hour,uid[5:7]) f=open(jn(minute,uid),'r') data=marshal.load(f) f.close() return data