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

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

Issue 68873003: Docserver: Serve docs out of src/ not src/chrome/common/extensions. This allows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix samples Created 7 years, 1 month 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 | Annotate | Revision Log
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 from file_system import FileSystem, FileNotFoundError, StatInfo 5 from file_system import FileSystem, FileNotFoundError, StatInfo
6 from future import Future 6 from future import Future
7 7
8 8
9 def _MoveTo(base, obj): 9 def MoveTo(base, obj):
10 '''Returns an object as |obj| moved to |base|. That is, 10 '''Returns an object as |obj| moved to |base|. That is,
11 _MoveTo('foo/bar', {'a': 'b'}) -> {'foo': {'bar': {'a': 'b'}}} 11 MoveTo('foo/bar', {'a': 'b'}) -> {'foo': {'bar': {'a': 'b'}}}
12 ''' 12 '''
13 result = {} 13 result = {}
14 leaf = result 14 leaf = result
15 for k in base.split('/'): 15 for k in base.split('/'):
16 leaf[k] = {} 16 leaf[k] = {}
17 leaf = leaf[k] 17 leaf = leaf[k]
18 leaf.update(obj) 18 leaf.update(obj)
19 return result 19 return result
20 20
21 21
22 def MoveAllTo(base, obj):
23 '''Moves every value in |obj| to |base|. See MoveTo.
24 '''
25 result = {}
26 for key, value in obj.iteritems():
27 result[key] = MoveTo(base, value)
28 return result
29
30
22 class TestFileSystem(FileSystem): 31 class TestFileSystem(FileSystem):
23 '''A FileSystem backed by an object. Create with an object representing file 32 '''A FileSystem backed by an object. Create with an object representing file
24 paths such that {'a': {'b': 'hello'}} will resolve Read('a/b') as 'hello', 33 paths such that {'a': {'b': 'hello'}} will resolve Read('a/b') as 'hello',
25 Read('a/') as ['b'], and Stat determined by a value incremented via 34 Read('a/') as ['b'], and Stat determined by a value incremented via
26 IncrementStat. 35 IncrementStat.
27 ''' 36 '''
28 37
29 def __init__(self, obj, relative_to=None, identity=None): 38 def __init__(self, obj, relative_to=None, identity=None):
30 assert obj is not None 39 assert obj is not None
31 self._obj = obj if relative_to is None else _MoveTo(relative_to, obj) 40 self._obj = obj if relative_to is None else MoveTo(relative_to, obj)
32 self._identity = identity or type(self).__name__ 41 self._identity = identity or type(self).__name__
33 self._path_stats = {} 42 self._path_stats = {}
34 self._global_stat = 0 43 self._global_stat = 0
35 44
36 # 45 #
37 # FileSystem implementation. 46 # FileSystem implementation.
38 # 47 #
39 48
40 def Read(self, paths, binary=False): 49 def Read(self, paths, binary=False):
41 test_fs = self 50 test_fs = self
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 # 120 #
112 121
113 def IncrementStat(self, path=None, by=1): 122 def IncrementStat(self, path=None, by=1):
114 if path is not None: 123 if path is not None:
115 self._path_stats[path] = self._path_stats.get(path, 0) + by 124 self._path_stats[path] = self._path_stats.get(path, 0) + by
116 else: 125 else:
117 self._global_stat += by 126 self._global_stat += by
118 127
119 def GetIdentity(self): 128 def GetIdentity(self):
120 return self._identity 129 return self._identity
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698