ocarina/libsaria/server/pages/__init__.py

40 lines
648 B
Python

# Bryan Schumaker (5 / 15 / 2011)
import root
import rpc
docs = {}
docs.update(root.docs)
docs.update(rpc.docs)
types = {
"html":"text/html",
"js":"text/javascript",
"png":"image/png",
}
def lookup(file):
doc = docs
for i, cmp in enumerate(file):
doc = doc.get(cmp, None)
if doc == None:
break
elif len(doc) == 2:
break
return doc, i + 1
def has_file(file):
doc, index = lookup(file)
return doc != None
def file_type(file):
(func, type), index = lookup(file)
return type
def page_text(write, file):
(func, type), index = lookup(file)
if len(file) > index:
res = func(write, file[index:])
else:
res = func(write)