Example #1
0
def servePyScripts(req):
	global config
	try:
		script = reload(os.path.join(config['basePath'], req['FILENAME']))
		buf = pywese.response(200, req['Content-Type'], script.run(req))
	except:
		buf = pywese.response(404, req['Content-Type'], "Script not found")
	return buf
Example #2
0
def serveImages(req):
	global config
	try:
		f = open(os.path.join(config['basePath'], req['FILENAME']), "r")
		buf = pywese.response(200, req['Content-Type'], f.read())
		f.close()
	except:
		buf = pywese.response(404, req['Content-Type'], "Image not found")
	return buf
Example #3
0
def serveImages(req):
	print('serveImages')
	global config
	try:
		contentType = pywese.getContentTypeByExt(req['FILENAME'].split('.')[-1])
		f = open(os.path.join(config['basePath'], req['FILENAME']), "r")
		buf = pywese.response(200, contentType, f.read())
		f.close()
	except:
		buf = pywese.response(404, contentType, "Image not found")
	return buf
Example #4
0
def serveHtmlPages(req):
	print('serveHtmlPages')
	global config
	try:
		ext = req['FILENAME'].split('.')[-1]
		f = open(os.path.join(config['basePath'], req['FILENAME']), "r")
		buf = pywese.response(200, "text/"+ext, f.read())
		f.close()
	except:
		buf = pywese.response(404, "text/html", "Page not found")
	return buf
Example #5
0
def servePyScripts(req):
	print('servePyScripts')
	global config
	oldPath = os.getcwd()
	
	try:
		os.chdir(os.path.dirname(os.path.join(config['basePath'], req['FILENAME'])))
		script = {}
		execfile(req['FILENAME'], script)
		script['template'] = __import__('template')
		output = script['run'](req)
		if type(output) == types.ListType:
			buf = pywese.responseWithCookies(200, "text/html", output[0], output[1])
		else:
			buf = pywese.response(200, "text/html", output)
	except Exception, info:
		buf = pywese.response(404, "text/html", str(info))