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

Side by Side Diff: chrome/common/extensions/docs/server2/fake_url_fetcher.py

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests Created 8 years, 5 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 (c) 2012 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 import os
6
7 class FakeUrlFetcher(object):
not at google - send to devlin 2012/07/18 10:39:15 See comment in appengine_url_fetcher; it would sim
cduvall 2012/07/18 21:26:10 Done.
8 def __init__(self, base_path):
9 self._base_path = base_path
10
11 def _ReadFile(self, filename):
12 with open(os.path.join(self._base_path, filename), 'r') as f:
13 return f.read()
14
15 def _ListDir(self, directory):
16 files = os.listdir(os.path.join(self._base_path, directory))
17 html = '<html><title>Revision: 00000</title>\n'
18 for filename in files:
19 if os.path.isdir(os.path.join(self._base_path, directory, filename)):
20 html += '<a>' + filename + '/</a>\n'
21 else:
22 html += '<a>' + filename + '</a>\n'
23 html += '</html>'
24 return html
25
26 class _Response(object):
27 def __init__(self):
28 self.content = ''
29 self.headers = { 'content-type': 'none' }
30 self.status_code = 200
31
32 class _RPC(object):
33 def __init__(self, fetcher):
34 self.callback = lambda x: x
35 self._url = ''
36 self._fetcher = fetcher
37
38 def get_result(self):
39 return self._fetcher.fetch(self._url)
40
41 def wait(self):
42 self.callback()
43
44 def create_rpc(self):
45 return self._RPC(self)
46
47 def make_fetch_call(self, rpc, url):
48 rpc._url = url
49
50 def fetch(self, url):
51 result = self._Response()
52 if url.endswith('/'):
53 result.content = self._ListDir(url)
54 else:
55 result.content = self._ReadFile(url)
56 return result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698