Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 xml.dom.minidom as xml | |
| 6 | |
| 7 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.
| |
| 8 def __init__(self, paths, fetcher): | |
| 9 self._fetches = [] | |
| 10 self._value = {} | |
| 11 self._error = None | |
| 12 for path in paths: | |
| 13 rpc = fetcher.create_rpc() | |
| 14 if path.endswith('/'): | |
| 15 rpc.callback = self._MakeCallback(self._ListDir, rpc, path) | |
| 16 else: | |
| 17 rpc.callback = self._MakeCallback(lambda file_: file_, rpc, path) | |
| 18 fetcher.make_fetch_call(rpc, path) | |
| 19 self._fetches.append(rpc) | |
| 20 | |
| 21 def _ListDir(self, directory): | |
| 22 dom = xml.parseString(directory) | |
| 23 files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')] | |
| 24 if '..' in files: | |
| 25 files.remove('..') | |
| 26 return files | |
| 27 | |
| 28 def _MakeCallback(self, f, rpc, path): | |
| 29 return lambda: self._Callback(rpc, path, f) | |
| 30 | |
| 31 def _Callback(self, rpc, key, f): | |
| 32 result = rpc.get_result() | |
| 33 self._value[key] = f(result.content) | |
| 34 | |
| 35 def Get(self): | |
| 36 for fetch in self._fetches: | |
| 37 fetch.wait() | |
| 38 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}}
| |
| 39 raise self._error | |
| 40 return self._value | |
| 41 | |
| OLD | NEW |