Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/fake_url_fetcher.py |
| diff --git a/chrome/common/extensions/docs/server2/fake_url_fetcher.py b/chrome/common/extensions/docs/server2/fake_url_fetcher.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f714eac6a9f00badc52cff0181fef25b862fa9a9 |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/fake_url_fetcher.py |
| @@ -0,0 +1,43 @@ |
| +# Copyright (c) 2012 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. |
| + |
| +import os |
| + |
| +from future import Future |
| + |
| +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
|
| + def __init__(self, base_path): |
| + self._base_path = base_path |
| + |
| + def _ReadFile(self, filename): |
| + with open(os.path.join(self._base_path, filename), 'r') as f: |
| + return f.read() |
| + |
| + def _ListDir(self, directory): |
| + files = os.listdir(os.path.join(self._base_path, directory)) |
| + html = '<html><title>Revision: 00000</title>\n' |
| + for filename in files: |
| + if os.path.isdir(os.path.join(self._base_path, directory, filename)): |
| + html += '<a>' + filename + '/</a>\n' |
| + else: |
| + html += '<a>' + filename + '</a>\n' |
| + html += '</html>' |
| + return html |
| + |
| + class _Response(object): |
| + def __init__(self): |
| + self.content = '' |
| + self.headers = { 'content-type': 'none' } |
| + 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.
|
| + |
| + def FetchAsync(self, url): |
| + return Future(value=self.Fetch(url)) |
| + |
| + def Fetch(self, url): |
| + result = self._Response() |
| + if url.endswith('/'): |
| + result.content = self._ListDir(url) |
| + else: |
| + result.content = self._ReadFile(url) |
| + return result |