def POST(self): message = simplejson.loads(web.data()) print message doc_type = message.get("type") if doc_type in ("notebook", "bibliography", "arxiv"): exec ("obj = %s(nothon_resource, render)" % (doc_type.title())) result = obj.handler(message) if message.get("aux"): aux = message.get("aux") if aux.get("command") in ("new_notebook"): nb = Notebook(nothon_resource, render) nb.new_notebook(aux.get("file"), aux=aux) result["aux"] = aux return simplejson.dumps(result) if message["command"] in ( "text", "paragraph", "savehtml", "docmain_render", "image", "paste_cell", "remove_cell", ): exec ("result = %s_handler(message, nothon_resource)" % (message["command"])) return result else: return simplejson.dumps({"success": "Could not parse command"})
def GET(self): aside = {"tree": unwrap_tree(dir_tree(".", nothon_resource.listed), ".", nothon_resource.dirlisting_style)} link = web.input(keyword=[], includeonly=[]) if "file" in link: return get_file_from_disc(link.file) if "arxiv" in link: arxiv = Arxiv(nothon_resource, render) if len(link.arxiv) == 0: return render.arxiv_all(nothon_resource.server, aside) return render.arxiv( "arxiv", aside, arxiv.parse(link.arxiv, keyword=link.keyword, includeonly=link.includeonly) ) if "bibnote" in link: bib = Bibliography(nothon_resource, render) bibnote = link.bibnote if len(bibnote) > 0: return render.bibliography( bibnote, bibnote, aside, bib.parse_bibliography(bibnote), list_handler_functions(), list_create_functions(), ) else: return render.welcome(None) if link.name == "": return render.welcome(None) if link.name.endswith(".html"): with open(link.name, "r") as fin: html = fin.read() return html if link.name == "__timeline": return render.timeline(link.name, aside, make_timeline()) elif link.name == "__toc": return render.toc(link.name, aside, make_toc()) elif link.name == "__bibliography": return render.bib_list(link.name, aside, make_bibliography()) elif link.name.endswith(".note"): nb = Notebook(nothon_resource, render) sp = link.name.split("#") link.name = sp[0] if not os.path.exists(link.name): nb.new_notebook(link.name) aside = { "tree": unwrap_tree(dir_tree(".", nothon_resource.listed), ".", nothon_resource.dirlisting_style) } return render.notebook( link.name, link.name, aside, nb.parse_note(link.name), list_handler_functions(), list_create_functions() ) else: return render.welcome("Could not process requested URL!")