c++11: Alphabetize c++11.html
[chromium-blink-merge.git] / styleguide / c++ / chromium-cpp / main.py
blobaef55ab4daaec9825b9429d1ccd11489d0984ace
1 #!/usr/bin/env python
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 from google.appengine.api import memcache
7 from google.appengine.api import urlfetch
8 import webapp2
10 import base64
12 """A simple appengine app that hosts .html files in src/styleguide/c++ from
13 chromium's git repo."""
16 class MainHandler(webapp2.RequestHandler):
17 def get(self):
18 handler = GitilesMirrorHandler()
19 handler.initialize(self.request, self.response)
20 return handler.get("c++11.html")
23 BASE = 'https://chromium.googlesource.com/chromium/src.git/' \
24 '+/master/styleguide/c++/%s?format=TEXT'
25 class GitilesMirrorHandler(webapp2.RequestHandler):
26 def get(self, resource):
27 if '..' in resource: # No path traversal.
28 self.response.write(':-(')
29 return
31 url = BASE % resource
32 contents = memcache.get(url)
33 if not contents or self.request.get('bust'):
34 result = urlfetch.fetch(url)
35 if result.status_code != 200:
36 self.response.set_status(result.status_code)
37 self.response.write('http error %d' % result.status_code)
38 return
39 contents = base64.b64decode(result.content)
40 memcache.set(url, contents, time=5*60) # seconds
42 if resource.endswith('.css'):
43 self.response.headers['Content-Type'] = 'text/css'
44 self.response.write(contents)
47 app = webapp2.WSGIApplication([
48 ('/', MainHandler),
49 ('/(\S+\.(?:css|html))', GitilesMirrorHandler),
50 ], debug=True)