| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 from appengine_wrappers import IsDevServer |
| 6 from object_store_creator import ObjectStoreCreator |
| 7 from render_servlet import RenderServlet |
| 8 from server_instance import ServerInstance |
| 9 from servlet import Request, Response, Servlet |
| 10 |
| 11 class PatchServlet(Servlet): |
| 12 '''Servlet which renders patched docs. |
| 13 ''' |
| 14 |
| 15 def Get(self): |
| 16 path_with_issue = self._request.path |
| 17 if '/' in path_with_issue: |
| 18 issue, real_path = path_with_issue.split('/', 1) |
| 19 else: |
| 20 issue, real_path = path_with_issue, '' |
| 21 |
| 22 constructor = (ServerInstance.CreateOnline if IsDevServer() else |
| 23 ServerInstance.GetOrCreateOffline) |
| 24 server_instance = constructor('trunk', |
| 25 '/_patch/%s/static' % issue, |
| 26 issue) |
| 27 fake_path = '/trunk/%s' % real_path |
| 28 |
| 29 response = RenderServlet(Request( |
| 30 fake_path, |
| 31 self._request.headers)).Get(server_instance) |
| 32 |
| 33 if response.IsRedirect(): |
| 34 url = response.headers['Location'] |
| 35 if url.startswith('/trunk/'): |
| 36 url = url.split('/trunk', 1)[1] |
| 37 response.headers['Location'] = '/_patch/%s%s' % (issue, url) |
| 38 return response |
| OLD | NEW |