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

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: memcache fix 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 from future import Future
8
9 class FakeUrlFetcher(object):
not at google - send to devlin 2012/07/19 03:55:19 this isn't really a fake since it reads stuff off
10 def __init__(self, base_path):
11 self._base_path = base_path
12
13 def _ReadFile(self, filename):
14 with open(os.path.join(self._base_path, filename), 'r') as f:
15 return f.read()
16
17 def _ListDir(self, directory):
18 files = os.listdir(os.path.join(self._base_path, directory))
19 html = '<html><title>Revision: 00000</title>\n'
20 for filename in files:
21 if os.path.isdir(os.path.join(self._base_path, directory, filename)):
22 html += '<a>' + filename + '/</a>\n'
23 else:
24 html += '<a>' + filename + '</a>\n'
25 html += '</html>'
26 return html
27
28 class _Response(object):
29 def __init__(self):
30 self.content = ''
31 self.headers = { 'content-type': 'none' }
32 self.status_code = 200
not at google - send to devlin 2012/07/19 03:55:19 nit: can go outside the class at the top
cduvall 2012/07/19 17:18:28 Done.
33
34 def FetchAsync(self, url):
35 return Future(value=self.Fetch(url))
36
37 def Fetch(self, url):
38 result = self._Response()
39 if url.endswith('/'):
40 result.content = self._ListDir(url)
41 else:
42 result.content = self._ReadFile(url)
43 return result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698