Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8254)

Unified Diff: chrome/common/extensions/docs/server2/local_renderer.py

Issue 14273035: Docserver: refactor the Handler/ServerInstance relationship into a servlet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index dedf5e73e9547046a89f5cf1ab9919b8fd5cdad7..53ac33f0d61aca788bfc6269a31b5050ff98a948 100644
--- a/chrome/common/extensions/docs/server2/local_renderer.py
+++ b/chrome/common/extensions/docs/server2/local_renderer.py
@@ -2,26 +2,12 @@
# 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, headers):
- self.path = path
- self.url = 'http://localhost/%s' % path
- self.headers = headers
-
-class _Response(object):
- def __init__(self):
- self.status = 200
- self.out = StringIO()
- self.headers = {}
-
- def set_status(self, status):
- self.status = status
+from render_servlet import RenderServlet
+from fake_fetchers import ConfigureFakeFetchers
+from servlet import Request
class LocalRenderer(object):
'''Renders pages fetched from the local file system.
@@ -29,20 +15,11 @@ class LocalRenderer(object):
def __init__(self, base_dir):
self._base_dir = base_dir.replace(os.sep, '/').rstrip('/')
- def Render(self, path, headers={}, always_online=False):
+ def Render(self, path, headers=None, servlet=RenderServlet):
'''Renders |path|, returning a tuple of (status, contents, headers).
'''
+ headers = headers or {}
# 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()
- url_path = urlparse.urlparse(path.replace(os.sep, '/')).path
- Handler(_Request(url_path, headers), 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
+ url_path = urlparse.urlparse(path.replace(os.sep, '/')).path
+ return servlet(Request(url_path, headers)).Get()
« no previous file with comments | « chrome/common/extensions/docs/server2/integration_test.py ('k') | chrome/common/extensions/docs/server2/preview.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698