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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from handler import Handler
6 from fake_fetchers import ConfigureFakeFetchers
7 import os
8 from StringIO import StringIO
9 import urlparse
10
11 class _Request(object):
12 def __init__(self, path, headers):
13 self.path = path
14 self.url = 'http://localhost/%s' % path
15 self.headers = headers
16
17 class _Response(object):
18 def __init__(self):
19 self.status = 200
20 self.out = StringIO()
21 self.headers = {}
22
23 def set_status(self, status):
24 self.status = status
25
26 class LocalRenderer(object):
27 '''Renders pages fetched from the local file system.
28 '''
29 def __init__(self, base_dir):
30 self._base_dir = base_dir.rstrip(os.path.sep)
31
32 def Render(self, path, headers={}, always_online=False):
33 '''Renders |path|, returning a tuple of (status, contents, headers).
34 '''
35 # TODO(kalman): do this via a LocalFileSystem not this fake AppEngine stuff.
36 ConfigureFakeFetchers(os.path.join(self._base_dir, 'docs'))
37 handler_was_always_online = Handler.ALWAYS_ONLINE
38 Handler.ALWAYS_ONLINE = always_online
39 try:
40 response = _Response()
41 Handler(_Request(urlparse.urlparse(path).path, headers), response).get()
42 content = response.out.getvalue()
43 if isinstance(content, unicode):
44 content = content.encode('utf-8', 'replace')
45 return (content, response.status, response.headers)
46 finally:
47 Handler.ALWAYS_ONLINE = handler_was_always_online
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698