Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / app_engine_handler.py
blob7c45ac0e7a07d0e8b9e45040f9c93f3dfba199ce
1 # Copyright 2013 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.
5 from appengine_wrappers import webapp2
6 from handler import Handler
7 from servlet import Request
9 class AppEngineHandler(webapp2.RequestHandler):
10 '''Top-level handler for AppEngine requests. Just converts them into our
11 internal Servlet architecture.
12 '''
14 def get(self):
15 profile_mode = self.request.get('profile')
16 if profile_mode:
17 import cProfile, pstats, StringIO
18 pr = cProfile.Profile()
19 pr.enable()
21 try:
22 request = Request(self.request.path,
23 self.request.url[:-len(self.request.path)],
24 self.request.headers)
25 response = Handler(request).Get()
26 finally:
27 if profile_mode:
28 pr.disable()
29 s = StringIO.StringIO()
30 pstats.Stats(pr, stream=s).sort_stats(profile_mode).print_stats()
31 self.response.out.write(s.getvalue())
32 self.response.headers['Content-Type'] = 'text/plain'
33 self.response.status = 200
34 else:
35 self.response.out.write(response.content.ToString())
36 self.response.headers.update(response.headers)
37 self.response.status = response.status