aboutsummaryrefslogtreecommitdiffstats
path: root/src/acit/web.py
blob: e09c94b03b480bd7f01ae1531c9421b3d4379a52 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cherrypy

from .db import DBPoolManager

class Server():
	def __init__(self,dbpool:DBPoolManager):
		cherrypy.engine.subscribe("newpage",self.registerpage)
		self.pages={}
		self.dbpool=dbpool
	
	def registerpage(self,path,content):
		self.pages[path]=content

	@cherrypy.expose
	def index(self,quote="nothing"):
		return "Index"
	
	@cherrypy.expose(["style.css"])
	def style(self):
		from .html import style_css
		return style_css

	@cherrypy.expose
	def default(self,*pathlist,**kwargs):
		from os.path import normpath
		path=normpath("/".join(pathlist))
		if path in self.pages:
			return self.pages[path]
		else:
			from .html import notfound
			cherrypy.response.status=404
			return notfound.format(path=path)