9 """Understand how filenames work.""" |
9 """Understand how filenames work.""" |
10 |
10 |
11 def __init__(self): |
11 def __init__(self): |
12 # The absolute path to our current directory. |
12 # The absolute path to our current directory. |
13 self.relative_dir = os.path.normcase(abs_file(os.curdir) + os.sep) |
13 self.relative_dir = os.path.normcase(abs_file(os.curdir) + os.sep) |
|
14 if isinstance(self.relative_dir, str): |
|
15 self.relative_dir = self.relative_dir.decode(sys.getfilesystemencoding()) |
14 |
16 |
15 # Cache of results of calling the canonical_filename() method, to |
17 # Cache of results of calling the canonical_filename() method, to |
16 # avoid duplicating work. |
18 # avoid duplicating work. |
17 self.canonical_filename_cache = {} |
19 self.canonical_filename_cache = {} |
18 |
20 |
21 |
23 |
22 The filename will be relative to the current directory when the |
24 The filename will be relative to the current directory when the |
23 `FileLocator` was constructed. |
25 `FileLocator` was constructed. |
24 |
26 |
25 """ |
27 """ |
|
28 if isinstance(filename, str): |
|
29 filename = filename.decode(sys.getfilesystemencoding()) |
26 fnorm = os.path.normcase(filename) |
30 fnorm = os.path.normcase(filename) |
27 if fnorm.startswith(self.relative_dir): |
31 if fnorm.startswith(self.relative_dir): |
28 filename = filename[len(self.relative_dir):] |
32 filename = filename[len(self.relative_dir):] |
29 return filename |
33 return filename |
30 |
34 |