| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 errno | 5 import errno |
| 6 import fnmatch |
| 6 import os | 7 import os |
| 7 import re | 8 import re |
| 8 import StringIO | 9 import StringIO |
| 9 | 10 |
| 10 | 11 |
| 11 def _RaiseNotFound(path): | 12 def _RaiseNotFound(path): |
| 12 raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT)) | 13 raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT)) |
| 13 | 14 |
| 14 | 15 |
| 15 class MockFileSystem(object): | 16 class MockFileSystem(object): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 # to a different thread and potentially modifying the dict in | 59 # to a different thread and potentially modifying the dict in |
| 59 # mid-iteration. | 60 # mid-iteration. |
| 60 files = self.files.keys()[:] | 61 files = self.files.keys()[:] |
| 61 return any(f.startswith(path) for f in files) | 62 return any(f.startswith(path) for f in files) |
| 62 | 63 |
| 63 def join(self, *comps): | 64 def join(self, *comps): |
| 64 # TODO: Might want tests for this and/or a better comment about how | 65 # TODO: Might want tests for this and/or a better comment about how |
| 65 # it works. | 66 # it works. |
| 66 return re.sub(re.escape(os.path.sep), self.sep, os.path.join(*comps)) | 67 return re.sub(re.escape(os.path.sep), self.sep, os.path.join(*comps)) |
| 67 | 68 |
| 69 def glob(self, path): |
| 70 return fnmatch.filter(self.files.keys(), path) |
| 71 |
| 68 def open_for_reading(self, path): | 72 def open_for_reading(self, path): |
| 69 return StringIO.StringIO(self.read_binary_file(path)) | 73 return StringIO.StringIO(self.read_binary_file(path)) |
| 70 | 74 |
| 71 def read_binary_file(self, path): | 75 def read_binary_file(self, path): |
| 72 # Intentionally raises KeyError if we don't recognize the path. | 76 # Intentionally raises KeyError if we don't recognize the path. |
| 73 if self.files[path] is None: | 77 if self.files[path] is None: |
| 74 _RaiseNotFound(path) | 78 _RaiseNotFound(path) |
| 75 return self.files[path] | 79 return self.files[path] |
| 80 |
| 81 @staticmethod |
| 82 def relpath(base, path): |
| 83 if path.startswith(base): |
| 84 return path[len(base):] |
| 85 return path |
| OLD | NEW |