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

Side by Side Diff: chrome/common/extensions/docs/server2/chroot_file_system.py

Issue 417163004: Docserver: Update Future.Then() to be more Promise-like (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import posixpath 5 import posixpath
6 6
7 from docs_server_utils import StringIdentity 7 from docs_server_utils import StringIdentity
8 from file_system import FileSystem 8 from file_system import FileSystem
9 from future import Future 9 from future import Future
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 def Read(self, paths, skip_not_found=False): 26 def Read(self, paths, skip_not_found=False):
27 # Maintain reverse mapping so the result can be mapped to the original 27 # Maintain reverse mapping so the result can be mapped to the original
28 # paths given (the result from |file_system| will include |root| in the 28 # paths given (the result from |file_system| will include |root| in the
29 # result, which would be wrong). 29 # result, which would be wrong).
30 prefixed_paths = {} 30 prefixed_paths = {}
31 def prefix(path): 31 def prefix(path):
32 prefixed = posixpath.join(self._root, path) 32 prefixed = posixpath.join(self._root, path)
33 prefixed_paths[prefixed] = path 33 prefixed_paths[prefixed] = path
34 return prefixed 34 return prefixed
35 future_result = self._file_system.Read( 35 def next(results):
36 tuple(prefix(path) for path in paths),
37 skip_not_found=skip_not_found)
38 def resolve():
39 return dict((prefixed_paths[path], content) 36 return dict((prefixed_paths[path], content)
40 for path, content in future_result.Get().iteritems()) 37 for path, content in results.iteritems())
41 return Future(callback=resolve) 38 return self._file_system.Read(tuple(prefix(path) for path in paths),
39 skip_not_found-skip_not_found).Then(next)
42 40
43 def Refresh(self): 41 def Refresh(self):
44 return self._file_system.Refresh() 42 return self._file_system.Refresh()
45 43
46 def Stat(self, path): 44 def Stat(self, path):
47 return self._file_system.Stat(posixpath.join(self._root, path)) 45 return self._file_system.Stat(posixpath.join(self._root, path))
48 46
49 def GetIdentity(self): 47 def GetIdentity(self):
50 return StringIdentity( 48 return StringIdentity(
51 '%s/%s' % (self._file_system.GetIdentity(), self._root)) 49 '%s/%s' % (self._file_system.GetIdentity(), self._root))
52 50
53 def __repr__(self): 51 def __repr__(self):
54 return 'ChrootFileSystem(%s, %s)' % ( 52 return 'ChrootFileSystem(%s, %s)' % (
55 self._root, repr(self._file_system)) 53 self._root, repr(self._file_system))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698