OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
8 from render_servlet import RenderServlet | 8 from render_servlet import RenderServlet |
9 from server_instance import ServerInstance | 9 from server_instance import ServerInstance |
10 from servlet import Request | 10 from servlet import Request |
11 | 11 |
12 class _LocalRenderServletDelegate(object): | 12 class _LocalRenderServletDelegate(object): |
13 def CreateServerInstanceForChannel(self, channel): | 13 def CreateServerInstanceForChannel(self, channel): |
14 return ServerInstance.ForLocal() | 14 return ServerInstance.ForLocal() |
15 | 15 |
16 class LocalRenderer(object): | 16 class LocalRenderer(object): |
17 '''Renders pages fetched from the local file system. | 17 '''Renders pages fetched from the local file system. |
18 ''' | 18 ''' |
19 @staticmethod | 19 @staticmethod |
20 def Render(path): | 20 def Render(path): |
21 assert not path.contains('\\') | 21 assert not '\\' in path |
22 def render_path(path): | 22 def render_path(path): |
23 return RenderServlet(Request(path, 'http://localhost', {}), | 23 return RenderServlet(Request(path, 'http://localhost', {}), |
24 _LocalRenderServletDelegate(), | 24 _LocalRenderServletDelegate(), |
25 default_channel='trunk').Get() | 25 default_channel='trunk').Get() |
26 response = render_path(path) | 26 response = render_path(path) |
27 while response.status in [301, 302]: | 27 while response.status in [301, 302]: |
28 redirect = response.headers['Location'] | 28 redirect = response.headers['Location'] |
29 sys.stderr.write('<!-- Redirected %s to %s -->\n' % (path, redirect)) | 29 sys.stderr.write('<!-- Redirected %s to %s -->\n' % (path, redirect)) |
30 response = render_path(redirect) | 30 response = render_path(redirect) |
31 return response | 31 return response |
OLD | NEW |