| Index: chrome/common/extensions/docs/server2/local_renderer.py
|
| diff --git a/chrome/common/extensions/docs/server2/local_renderer.py b/chrome/common/extensions/docs/server2/local_renderer.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b4f374d15b800032bc9effead1f23eaec8c1dd82
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/docs/server2/local_renderer.py
|
| @@ -0,0 +1,47 @@
|
| +# 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.
|
| +
|
| +from handler import Handler
|
| +from fake_fetchers import ConfigureFakeFetchers
|
| +import os
|
| +from StringIO import StringIO
|
| +import urlparse
|
| +
|
| +class _Request(object):
|
| + def __init__(self, path):
|
| + self.headers = {}
|
| + self.path = path
|
| + self.url = 'http://localhost/%s' % path
|
| +
|
| +class _Response(object):
|
| + def __init__(self):
|
| + self.status = 200
|
| + self.out = StringIO()
|
| + self.headers = {}
|
| +
|
| + def set_status(self, status):
|
| + self.status = status
|
| +
|
| +class LocalRenderer(object):
|
| + '''Renders pages fetched from the local file system.
|
| + '''
|
| + def __init__(self, base_dir):
|
| + self._base_dir = base_dir.rstrip(os.path.sep)
|
| +
|
| + def Render(self, path, always_online=False):
|
| + '''Renders |path|, returning a tuple of (status, contents, headers).
|
| + '''
|
| + # TODO(kalman): do this via a LocalFileSystem not this fake AppEngine stuff.
|
| + ConfigureFakeFetchers(os.path.join(self._base_dir, 'docs'))
|
| + handler_was_always_online = Handler.ALWAYS_ONLINE
|
| + Handler.ALWAYS_ONLINE = always_online
|
| + try:
|
| + response = _Response()
|
| + Handler(_Request(urlparse.urlparse(path).path), response).get()
|
| + content = response.out.getvalue()
|
| + if isinstance(content, unicode):
|
| + content = content.encode('utf-8', 'replace')
|
| + return (content, response.status, response.headers)
|
| + finally:
|
| + Handler.ALWAYS_ONLINE = handler_was_always_online
|
|
|