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

Unified 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 side-by-side diff with in-line comments
Download patch
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..2022b96c7a9393d7d82cf76cd0c8a01f6121bae5
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/fake_url_fetcher.py
@@ -0,0 +1,56 @@
+# 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
+
+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.
+ 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
+
+ class _RPC(object):
+ def __init__(self, fetcher):
+ self.callback = lambda x: x
+ self._url = ''
+ self._fetcher = fetcher
+
+ def get_result(self):
+ return self._fetcher.fetch(self._url)
+
+ def wait(self):
+ self.callback()
+
+ def create_rpc(self):
+ return self._RPC(self)
+
+ def make_fetch_call(self, rpc, url):
+ rpc._url = url
+
+ def fetch(self, url):
+ result = self._Response()
+ if url.endswith('/'):
+ result.content = self._ListDir(url)
+ else:
+ result.content = self._ReadFile(url)
+ return result

Powered by Google App Engine
This is Rietveld 408576698