1# Copyright (c) 2012 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. 4 5from cron_servlet import CronServlet 6from instance_servlet import InstanceServlet 7from patch_servlet import PatchServlet 8from servlet import Servlet, Request, Response 9from test_servlet import TestServlet 10 11_DEFAULT_SERVLET = InstanceServlet.GetConstructor() 12_SERVLETS = { 13 'cron': CronServlet, 14 'patch': PatchServlet, 15 'test': TestServlet, 16} 17 18class Handler(Servlet): 19 def Get(self): 20 path = self._request.path 21 22 if path.startswith('_'): 23 servlet_path = path[1:] 24 if not '/' in servlet_path: 25 servlet_path += '/' 26 servlet_name, servlet_path = servlet_path.split('/', 1) 27 servlet = _SERVLETS.get(servlet_name) 28 if servlet is None: 29 return Response.NotFound('"%s" servlet not found' % servlet_path) 30 else: 31 servlet_path = path 32 servlet = _DEFAULT_SERVLET 33 34 return servlet( 35 Request(servlet_path, self._request.host, self._request.headers)).Get() 36