root/livinglogic.googleappengine.ul4/main.py @ 11:8f47428560c6

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

Decode request parameters.

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