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

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: . 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..7c58e3df22bed5983076dde8a2119a06b7f2b056 100644
--- a/chrome/common/extensions/docs/server2/local_renderer.py
+++ b/chrome/common/extensions/docs/server2/local_renderer.py
@@ -2,26 +2,13 @@
# 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 appengine_wrappers import FakeRequest, FakeResponse
+from handler import Handler
+from render_servlet import RenderServlet
+from fake_fetchers import ConfigureFakeFetchers
class LocalRenderer(object):
'''Renders pages fetched from the local file system.
@@ -29,20 +16,15 @@ 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={}):
'''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()
- 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
+ response = FakeResponse()
+ url_path = urlparse.urlparse(path.replace(os.sep, '/')).path
+ Handler(FakeRequest(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)

Powered by Google App Engine
This is Rietveld 408576698