Пример #1
0
	def setcookie(self,env,config):
		#if config[1]["action"].lower()=="set":
		d={"name":replaceVars(env,config["name"],fn=str), "value":replaceVars(env,config["value"])}
		if config.has_key("path"):
			d["path"]=replaceVars(env,config["path"])
		HTTP.setCookie(env,d)
		return {}
Пример #2
0
def application(env,start_response):
	#for i in env:
	#	print i+": "+str(env[i])
	t=time.time()
	response=[]
	D=acconfig.debug
	path=env["HTTP_HOST"]
	if APP_CACHE.has_key(path):
		app=APP_CACHE[path]
		# if application config file changes, reload whole app
		#D=app.dbg.get("enabled",False)
		if not app.deploymentMode and not app.isUpToDate():
			app=Application(path)
	else:
		app=Application(path)
		APP_CACHE[path]=app
	acenv=Environment(app)
	D=acenv.doDebug
	acenv.env["clientIP"]=env.get("REMOTE_ADDR","unknown")
	acenv.mime=map(str.strip, env.get("HTTP_ACCEPT","application/xml").split(";",1)[0].split(","))
	acenv.UA=acenv.env["UA"]=env.get("HTTP_USER_AGENT")
	if D:
		acenv.debug("MIME is: %s",acenv.mime)
		acenv.debug("UA is: %s",acenv.UA)
	acenv.output["format"]=computeMIME(acenv.mime,acenv.UA)
	if D: acenv.debug("Computed output format is: %s",acenv.output["format"])
	if env.get('HTTP_COOKIE'):
		acenv.cookies=acenv.env["cookies"]=HTTP.parseCookies(acenv,env['HTTP_COOKIE'])
	acenv.setLang(str(env.get("HTTP_ACCEPT_LANGUAGE","").split(",",1)[0].split("-",1)[0]))
	post=None
	if env.get('REQUEST_METHOD',"").lower()=="post":
		post=HTTP.computePOST(env)
	acenv.posts=post
	strisspace=str.isspace
	acenv.URLpath=filter(lambda x: len(x)!=0 or strisspace(x), env['PATH_INFO'].split("/"))
	output=app.generate(acenv)
	headers=acenv.outputHeaders
	headers.append(("Content-Type",acenv.output["format"]))
	status='200 OK'
	if acenv.doRedirect:
		status="303 See other"
	start_response(status, headers)
	if acenv.doRedirect:
		response.append("")
	else:
		response.append(output)
	if acenv.doProfiling:
		whole=round((time.time()-t)*1000,2)
		headerstime=whole-acenv.profiler["alltime"]
		print("Time spent on parsing HTTP headers and building objects: %sms"%(headerstime))
		print("Time spent on Python and waitings: %sms"%(headerstime+acenv.profiler["pytime"]))
		print "Request satisfied in %sms"%whole
		print "WARNING! Python time includes some waitings related to one-threaded nature of WSGIRef. These waitings are not existent in deployment instalations due to multiprocessing/threading/asynchrony, but are stable through multiple runs. Use above timings to optimize your views. Measure time of 'HelloWorld!' app and substract the values from the results.\nRun the tests multiple times and get the mean to get best results!"
	#h = hpy()
	#print h.heap()
	return response
Пример #3
0
	def deleteCookie(self):
		#log.info("Deleting session cookie")
		t=time.time()-10000
		#log.debug("Session cookie deleted by setting date to %s",t)
		HTTP.setCookie(self.env,{"name":"SESS", "value":"", "date":t})
		return
Пример #4
0
	def create(self):
		#print("executed, function with no parameters")
		self.sessID=self.generateID()
		HTTP.setCookie(self.env,{"name":"SESS", "value":self.sessID, "path":"/"})