Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import hashlib | |
| 6 import logging | |
| 7 import os | |
| 8 import sys | |
| 9 import webapp2 | |
| 10 | |
| 11 from google.appengine.ext import ndb | |
| 12 from webapp2_extras import jinja2 | |
| 13 | |
| 14 CONFIG_DATA_KEY = 'config_data_key' | |
| 15 | |
| 16 | |
| 17 def is_development_server(): | |
| 18 return os.environ.get('SERVER_SOFTWARE', '').startswith('Development') | |
| 19 | |
| 20 | |
| 21 class MonAcqData(ndb.Model): | |
| 22 """Store the sensitive endpoint data.""" | |
| 23 credentials = ndb.JsonProperty() | |
|
agable
2015/04/23 19:29:37
I still think it makes sense for the credentials j
Sergey Berezin (google)
2015/04/24 19:09:52
Acknowledged.
| |
| 24 url = ndb.StringProperty() | |
| 25 scopes = ndb.StringProperty(repeated=True) | |
| 26 headers = ndb.JsonProperty(default={}) | |
| 27 | |
| 28 | |
| 29 def payload_stats(data): | |
| 30 md5 = hashlib.md5() | |
| 31 md5.update(data) | |
| 32 md5hex = md5.hexdigest() | |
| 33 return 'type=%s, %d bytes, md5=%s' % (type(data), len(data), md5hex) | |
| 34 | |
| 35 | |
| 36 class BaseHandler(webapp2.RequestHandler): | |
| 37 """Provide a cached Jinja environment to each request.""" | |
| 38 | |
| 39 def __init__(self, *args, **kwargs): | |
| 40 webapp2.RequestHandler.__init__(self, *args, **kwargs) | |
| 41 | |
| 42 @staticmethod | |
| 43 def jinja2_factory(app): | |
| 44 template_dir = os.path.abspath( | |
| 45 os.path.join(os.path.dirname(__file__), 'templates')) | |
| 46 config = {'template_path': template_dir} | |
| 47 jinja = jinja2.Jinja2(app, config=config) | |
| 48 return jinja | |
| 49 | |
| 50 @webapp2.cached_property | |
| 51 def jinja2(self): | |
| 52 # Returns a Jinja2 renderer cached in the app registry. | |
| 53 return jinja2.get_jinja2( | |
| 54 app=self.app, factory=BaseHandler.jinja2_factory) | |
| 55 | |
| 56 def render_response(self, _template, **context): | |
| 57 # Renders a template and writes the result to the response. | |
| 58 rv = self.jinja2.render_template(_template, **context) | |
| 59 self.response.write(rv) | |
| OLD | NEW |