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.
7 from appengine_wrappers
import webapp2
8 from handler
import Handler
9 from servlet
import Request
12 class AppEngineHandler(webapp2
.RequestHandler
):
13 '''Top-level handler for AppEngine requests. Just converts them into our
14 internal Servlet architecture.
18 profile_mode
= self
.request
.get('profile')
20 import cProfile
, pstats
, StringIO
21 pr
= cProfile
.Profile()
26 request
= Request(self
.request
.path
,
27 self
.request
.url
[:-len(self
.request
.path
)],
29 response
= Handler(request
).Get()
30 except Exception as e
:
35 s
= StringIO
.StringIO()
36 pstats
.Stats(pr
, stream
=s
).sort_stats(profile_mode
).print_stats()
37 self
.response
.out
.write(s
.getvalue())
38 self
.response
.headers
['Content-Type'] = 'text/plain'
39 self
.response
.status
= 200
41 self
.response
.out
.write(response
.content
.ToString())
42 self
.response
.headers
.update(response
.headers
)
43 self
.response
.status
= response
.status
45 self
.response
.out
.write('Internal server error')
46 self
.response
.status
= 500