Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/chained_compiled_file_system.py |
| =================================================================== |
| --- chrome/common/extensions/docs/server2/chained_compiled_file_system.py (revision 0) |
| +++ chrome/common/extensions/docs/server2/chained_compiled_file_system.py (revision 0) |
| @@ -0,0 +1,49 @@ |
| +# Copyright 2013 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. |
| + |
| +from compiled_file_system import CompiledFileSystem |
| +from file_system import FileNotFoundError |
| + |
| +class ChainedCompiledFileSystem(CompiledFileSystem): |
|
not at google - send to devlin
2013/05/11 20:39:53
comment
not at google - send to devlin
2013/05/11 20:39:53
pls always use composition not inheritance - parti
方觉(Fang Jue)
2013/05/12 03:01:47
Done.
方觉(Fang Jue)
2013/05/12 03:01:47
Done.
|
| + class Factory(CompiledFileSystem.Factory): |
| + def __init__(self, |
| + file_system, |
| + object_store_creator, |
| + base_compiled_fs_factory=None): |
| + self._file_system = file_system |
| + self._object_store_creator = object_store_creator |
| + self._base_compiled_fs_factory = base_compiled_fs_factory |
| + |
| + def Create(self, populate_function, cls, category=None): |
| + fs = self._Create(populate_function, cls, category, |
| + ChainedCompiledFileSystem) |
| + fs._base_compiled_fs = self._base_compiled_fs_factory.Create( |
| + populate_function, cls, category) |
| + return fs |
| + |
|
not at google - send to devlin
2013/05/11 20:39:53
seems to me like this class could just as easily c
|
| + def GetFromFile(self, path, binary=False): |
| + # It's possible that a new file is added in this compiled file system |
| + # and it doesn't exist in base_compiled_fs. |
| + try: |
| + version = self._file_system.Stat(path).version |
| + cache_entry = self._base_compiled_fs._GetCacheEntryFromFile(path, |
| + binary) |
| + if version == cache_entry.version: |
| + return cache_entry.cache_data |
| + except FileNotFoundError: |
| + pass |
| + return CompiledFileSystem.GetFromFile(self, path, binary) |
| + |
| + def GetFromFileListing(self, path): |
| + if not path.endswith('/'): |
| + path += '/' |
| + try: |
| + version = self._file_system.Stat(path).version |
| + cache_entry = self._base_compiled_fs._GetCacheEntryFromFileListing( |
| + path) |
| + if version == cache_entry.version: |
| + return cache_entry.cache_data |
| + except FileNotFoundError: |
| + pass |
| + return CompiledFileSystem.GetFromFileListing(self, path) |
| Property changes on: chrome/common/extensions/docs/server2/chained_compiled_file_system.py |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |