def SiteRun(self, site): newtemplatefilename = "temp_siterun" + str(random.randint( 0, 65535)) + ".spt" #this is SPIKE Proxy specific code right here myRandR = requestandresponse.RequestAndResponse( spkproxy.header(), spkproxy.body(), spkproxy.header(), spkproxy.body()) myRandR.clientheader.URL = "/" myRandR.clientbody.body = [] myRandR.clientheader.setSiteTuple(site) myRandR.serverheader = None myRandR.serverbody = None #now write this as a pickle to our file #this is not SPIKE Proxy specific openfile = open(newtemplatefilename, "wb") binary = 1 cPickle.dump(myRandR, openfile, binary) openfile.close() #mark what test we are doing so we match correctly self.dositetest = 1 results = self.doTemplateRun(newtemplatefilename) #now delete our temporary file os.unlink(newtemplatefilename) return results
def SiteRun(self,site): newtemplatefilename="temp_siterun"+str(random.randint(0,65535))+".spt" #this is SPIKE Proxy specific code right here myRandR=requestandresponse.RequestAndResponse(spkproxy.header(),spkproxy.body(),spkproxy.header(),spkproxy.body()) myRandR.clientheader.URL="/" myRandR.clientbody.body=[] myRandR.clientheader.setSiteTuple(site) myRandR.serverheader=None myRandR.serverbody=None #now write this as a pickle to our file #this is not SPIKE Proxy specific openfile=open(newtemplatefilename,"wb") binary=1 cPickle.dump(myRandR,openfile,binary) openfile.close() #mark what test we are doing so we match correctly self.dositetest=1 results=self.doTemplateRun(newtemplatefilename) #now delete our temporary file os.unlink(newtemplatefilename) return results
#!/usr/bin/python #testpickle.py - tests the pickle routines for a RequestAndResponse #global imports import os import dircache import pickle #my imports from spkproxy import header, body from requestandresponse import RequestAndResponse import daveutil clientheader = header() clientbody = body() serverheader = header() serverbody = body() filename = "testpickle.pickle" obj = RequestAndResponse(clientheader, clientbody, serverheader, serverbody) openfile = open(filename, "w") print "openfile=" + str(openfile) + " object: " + str(obj) pickle.dump(obj, openfile) openfile.close() print "Done!"
usage() dorequest=0 doresponse=0 target="" for o,a in opts: if o in ["-f"]: target=a if o in ["-r"]: dorequest=1 if o in ["-R"]: doresponse=1 if target=="": usage() clientheader=header() clientbody=body() serverheader=header() serverbody=body() filename=target fd=open(filename) if fd==None: print "Bad Filename: %s"%filename sys.exit(1) obj=cPickle.load(fd) fd.close() if dorequest: print daveutil.constructRequest(obj.clientheader,obj.clientbody) if doresponse: print daveutil.constructResponse(obj.serverheader,obj.serverbody)