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

Unified Diff: chrome/common/extensions/docs/server2/async_fetch_value.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/async_fetch_value.py
diff --git a/chrome/common/extensions/docs/server2/async_fetch_value.py b/chrome/common/extensions/docs/server2/async_fetch_value.py
new file mode 100644
index 0000000000000000000000000000000000000000..63ee99958eac97ddef6c78fb1b9148e0559c5b9f
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/async_fetch_value.py
@@ -0,0 +1,41 @@
+# 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 xml.dom.minidom as xml
+
+class AsyncFetchValue(object):
not at google - send to devlin 2012/07/18 10:39:15 Hm, sorry, this is pretty tied into the FileSystem
cduvall 2012/07/18 21:26:10 Done.
+ def __init__(self, paths, fetcher):
+ self._fetches = []
+ self._value = {}
+ self._error = None
+ for path in paths:
+ rpc = fetcher.create_rpc()
+ if path.endswith('/'):
+ rpc.callback = self._MakeCallback(self._ListDir, rpc, path)
+ else:
+ rpc.callback = self._MakeCallback(lambda file_: file_, rpc, path)
+ fetcher.make_fetch_call(rpc, path)
+ self._fetches.append(rpc)
+
+ def _ListDir(self, directory):
+ dom = xml.parseString(directory)
+ files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')]
+ if '..' in files:
+ files.remove('..')
+ return files
+
+ def _MakeCallback(self, f, rpc, path):
+ return lambda: self._Callback(rpc, path, f)
+
+ def _Callback(self, rpc, key, f):
+ result = rpc.get_result()
+ self._value[key] = f(result.content)
+
+ def Get(self):
+ for fetch in self._fetches:
+ fetch.wait()
+ if self._error is not None:
not at google - send to devlin 2012/07/18 10:39:15 what's wrong with !=
cduvall 2012/07/18 21:26:10 From PEP 8: "Comparisons to singletons like None s
not at google - send to devlin 2012/07/19 03:55:18 wtf python. "is not" is an operator? That could eq
cduvall 2012/07/19 17:18:28 haha {{/rant}}
+ raise self._error
+ return self._value
+

Powered by Google App Engine
This is Rietveld 408576698