-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschema.py
48 lines (41 loc) · 1.36 KB
/
schema.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import wsgiref.handlers
import os
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
def throwNotFound(self):
self.error(404)
template_values = {
'foo': 'bar',
}
path = os.path.join(os.path.dirname(__file__), 'templates/404.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(template.render(path, template_values))
class schemaHandler(webapp.RequestHandler):
def get(self, ver, name):
filestring = 'schema/'+ver+'/'+name+'.html'
if os.path.isfile(filestring):
filepath = os.path.join(os.path.dirname(__file__), filestring)
template_values = {
'ver': ver,
'name': name,
'incpath': filepath,
}
path = os.path.join(os.path.dirname(__file__), 'templates/schema.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(template.render(path, template_values))
else:
throwNotFound(self)
class notfoundHandler(webapp.RequestHandler):
def get(self):
throwNotFound(self)
application = webapp.WSGIApplication([
(r'/schema/(.*)/(.*)/', schemaHandler),
(r'/schema/(.*)/(.*)', schemaHandler),
('/.*', notfoundHandler)
], debug=True)
def main():
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()