root/livinglogic.googleappengine.ul4/main.py @ 12:adfd78cbd893

Revision 12:adfd78cbd893, 1.2 KB (checked in by Walter Doerwald <walter@…>, 11 years ago)

Remove unused import.

  • Property exe set to *
Line 
1#!/usr/bin/env python
2# -*- encoding: utf-8 -*-
3
4import wsgiref.handlers
5
6from google.appengine.ext import webapp
7
8from ll import misc, ul4c
9
10
11class CompileHandler(webapp.RequestHandler):
12    def post(self):
13        source = self.request.get("source").decode("utf-8")
14        startdelim = self.request.get("startdelim", "<?").decode("utf-8")
15        enddelim = self.request.get("enddelim", "?>").decode("utf-8")
16        format = self.request.get("format", "bytecode").decode("utf-8")
17
18        try:
19            template = ul4c.compile(source, startdelim, enddelim)
20        except Exception, exc:
21            output = str(exc)
22            self.response.set_status(400)
23        else:
24            if format == "python":
25                output = template.pythonsource("template")
26            elif format == "bytecode":
27                output = template.dumps()
28            elif format == "reprbytecode":
29                output = repr(template.dumps())
30            else: # fall back to bytecode output
31                output = template.dumps()
32        self.response.headers["Content-Type"] = "text/plain; charset=utf-8"
33        self.response.out.write(output)
34
35    def get(self):
36        return self.post()
37
38
39def main():
40    application = webapp.WSGIApplication([('/compile', CompileHandler)], debug=False)
41    wsgiref.handlers.CGIHandler().run(application)
42
43
44if __name__ == '__main__':
45    main()
Note: See TracBrowser for help on using the browser.