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.
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.
23 def _HandleRequest(self
):
24 profile_mode
= self
.request
.get('profile')
26 import cProfile
, pstats
, StringIO
27 pr
= cProfile
.Profile()
33 for argument
in self
.request
.arguments():
34 arguments
[argument
] = self
.request
.get(argument
)
35 request
= Request(self
.request
.path
,
39 response
= Handler(request
).Get()
40 except Exception as e
:
45 s
= StringIO
.StringIO()
46 pstats
.Stats(pr
, stream
=s
).sort_stats(profile_mode
).print_stats()
47 self
.response
.out
.write(s
.getvalue())
48 self
.response
.headers
['Content-Type'] = 'text/plain'
49 self
.response
.status
= 200
51 self
.response
.out
.write(response
.content
.ToString())
52 self
.response
.headers
.update(response
.headers
)
53 self
.response
.status
= response
.status
55 self
.response
.out
.write('Internal server error')
56 self
.response
.status
= 500