| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 os | 5 import os |
| 6 | 6 |
| 7 class FileNotFoundError(Exception): | 7 class FileNotFoundError(Exception): |
| 8 def __init__(self, filename): | 8 def __init__(self, filename): |
| 9 Exception.__init__(self, filename) | 9 Exception.__init__(self, filename) |
| 10 | 10 |
| 11 def _ProcessFileData(data, path): | 11 def _ProcessFileData(data, path): |
| 12 if os.path.splitext(path)[-1] not in ['.js', '.html', '.json']: | 12 if os.path.splitext(path)[-1] not in ['.js', '.html', '.json']: |
| 13 return data | 13 return data |
| 14 try: | 14 try: |
| 15 return unicode(data, 'utf-8') | 15 return unicode(data, 'utf-8') |
| 16 except: | 16 except: |
| 17 return unicode(data, 'latin-1') | 17 return unicode(data, 'latin-1') |
| 18 | 18 |
| 19 class FileSystem(object): | 19 class FileSystem(object): |
| 20 """A FileSystem interface that can read files and directories. | 20 """A FileSystem interface that can read files and directories. |
| 21 """ | 21 """ |
| 22 class StatInfo(object): | 22 class StatInfo(object): |
| 23 """The result of calling Stat on a FileSystem. | 23 """The result of calling Stat on a FileSystem. |
| 24 """ | 24 """ |
| 25 def __init__(self, version): | 25 def __init__(self, version, child_versions): |
| 26 self.version = version | 26 self.version = version |
| 27 self.child_versions = child_versions |
| 27 | 28 |
| 28 def Read(self, paths, binary=False): | 29 def Read(self, paths, binary=False): |
| 29 """Reads each file in paths and returns a dictionary mapping the path to the | 30 """Reads each file in paths and returns a dictionary mapping the path to the |
| 30 contents. If a path in paths ends with a '/', it is assumed to be a | 31 contents. If a path in paths ends with a '/', it is assumed to be a |
| 31 directory, and a list of files in the directory is mapped to the path. | 32 directory, and a list of files in the directory is mapped to the path. |
| 32 | 33 |
| 33 If binary=False, the contents of each file will be unicode parsed as utf-8, | 34 If binary=False, the contents of each file will be unicode parsed as utf-8, |
| 34 and failing that as latin-1 (some extension docs use latin-1). If | 35 and failing that as latin-1 (some extension docs use latin-1). If |
| 35 binary=True then the contents will be a str. | 36 binary=True then the contents will be a str. |
| 36 """ | 37 """ |
| 37 raise NotImplementedError() | 38 raise NotImplementedError() |
| 38 | 39 |
| 39 def ReadSingle(self, path): | 40 def ReadSingle(self, path): |
| 40 """Reads a single file from the FileSystem. | 41 """Reads a single file from the FileSystem. |
| 41 """ | 42 """ |
| 42 return self.Read([path]).Get()[path] | 43 return self.Read([path]).Get()[path] |
| 43 | 44 |
| 44 def Stat(self, path): | 45 def Stat(self, path): |
| 45 """Gets the version number of |path| if it is a directory, or the parent | 46 """Returns a |StatInfo| object containing the version of |path|. If |path| |
| 46 directory if it is a file. | 47 is a directory, |StatInfo| will have the versions of all the children of |
| 48 the directory in |StatInfo.child_versions|. |
| 47 """ | 49 """ |
| 48 raise NotImplementedError() | 50 raise NotImplementedError() |
| OLD | NEW |