diff --git a/app.yaml b/app.yaml index 9a1c13a..85b9d45 100644 --- a/app.yaml +++ b/app.yaml @@ -1,11 +1,12 @@ application: hdcpgen version: 1 -runtime: python +runtime: python27 api_version: 1 +threadsafe: true handlers: - url: /keys/.* - script: appengine.py + script: appengine.application - url: /(index\.html)? static_files: appengine_index.html diff --git a/appengine.py b/appengine.py index d04af68..5eb36b4 100644 --- a/appengine.py +++ b/appengine.py @@ -1,11 +1,11 @@ -from google.appengine.ext import webapp -from google.appengine.ext.webapp.util import run_wsgi_app -from django.utils import simplejson as json - +import json +import webapp2 from generate_key import * -class KeysHandler(webapp.RequestHandler): - def __init__(self): +class KeysHandler(webapp2.RequestHandler): + def __init__(self, request, response): + # Set self.request, self.response and self.app. + self.initialize(request, response) self._key_matrix = read_key_file(open('master-key.txt')) def _gen_json(self, ksv, key, is_sink): @@ -15,7 +15,6 @@ class KeysHandler(webapp.RequestHandler): 'type': 'sink' if is_sink else 'source' }, sort_keys=True, indent=False) - def get(self, key_type, ksv_string = None): self.response.headers['Content-Type'] = 'application/json' @@ -31,21 +30,15 @@ class KeysHandler(webapp.RequestHandler): else: raise RuntimeError('Unknown key type: %s' % key_type) - self.response.out.write(self._gen_json(ksv, key, True if key_type == 'sink' else False)) + self.response.write(self._gen_json(ksv, key, True if key_type == 'sink' else False)) -class KsvHandler(webapp.RequestHandler): +class KsvHandler(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' - self.response.out.write('%010x' % gen_ksv()) + self.response.write('%010x' % gen_ksv()) -application = webapp.WSGIApplication([ +application = webapp2.WSGIApplication([ ('/keys/(sink|source)/([0-9a-f]{10})', KeysHandler), ('/keys/(sink|source)', KeysHandler), ('/keys/random_ksv', KsvHandler), ], debug=True) - -def main(): - run_wsgi_app(application) - -if __name__ == "__main__": - main() diff --git a/appengine_index.html b/appengine_index.html index 2c2aeb5..ce7276e 100644 --- a/appengine_index.html +++ b/appengine_index.html @@ -10,18 +10,18 @@
-The following links generate a random HDCP source or sink key as a machine-readable JSON object.
Source code - available from github.
+Source code + available from github.