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