Ejemplo n.º 1
0
		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))
		
	os.chdir(oldPath)
	return buf

def serveDefault(req):
	req['FILENAME'] = 'index.py'
	return servePyScripts(req)

config = pywese.config("CalendarConfig")

server = pywese.HttpServer(
	config['host'],
	config["port"],
	[
		["^\w+\.(jpg|png|ico)$", serveImages],
		["^\w+\.(htm|html|css)$", serveHtmlPages],
		["^\w+$", servePyScripts],
		["^$", serveDefault]
	],
	config['debug']
)
Ejemplo n.º 2
0
	global config
	try:
		f = open(os.path.join(config['basePath'], req['FILENAME']), "r")
		buf = pywese.response(200, "text/html", f.read())
		f.close()
	except:
		buf = pywese.response(404, req['Content-Type'], "Page not found")
	return buf

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

config = pywese.config("config")

server = pywese.HttpServer(
	config['host'],
	config["port"],
	{
		"^[\w\/]+?\.gif|jpg|png$": serveImages,
		"^[\w\/]+?\.htm|html$": serveHtmlPages,
		"^[\w\/]+?\.py$": servePyScripts
	},
	config['debug']
)