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

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

Issue 14218004: Devserver: only populate data during cron jobs, meaning all data from instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integration test 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
new file mode 100644
index 0000000000000000000000000000000000000000..6d1714c9add89af922dc11cda594a9f064cd294c
--- /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, 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
+
+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, headers={}, 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, 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

Powered by Google App Engine
This is Rietveld 408576698