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.
15 profile_mode
= self
.request
.get('profile')
17 import cProfile
, pstats
, StringIO
18 pr
= cProfile
.Profile()
22 request
= Request(self
.request
.path
,
23 self
.request
.url
[:-len(self
.request
.path
)],
25 response
= Handler(request
).Get()
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
35 self
.response
.out
.write(response
.content
.ToString())
36 self
.response
.headers
.update(response
.headers
)
37 self
.response
.status
= response
.status