Mercurial > cpython-lru_cache-weakref
diff Lib/importlib/_bootstrap.py @ 76428:a32be109bd86
Issue #14581: Windows users are allowed to import modules w/o taking
the file suffix's case into account, even when doing a case-sensitive
import.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Fri, 20 Apr 2012 12:53:14 -0400 |
| parents | 052732bd3c10 |
| children | c820aa9c0c00 |
line wrap: on
line diff
--- a/Lib/importlib/_bootstrap.py Fri Apr 20 12:51:44 2012 -0400 +++ b/Lib/importlib/_bootstrap.py Fri Apr 20 12:53:14 2012 -0400 @@ -841,7 +841,23 @@ contents = _os.listdir(path) # We store two cached versions, to handle runtime changes of the # PYTHONCASEOK environment variable. - self._path_cache = set(contents) + if not sys.platform.startswith('win'): + self._path_cache = set(contents) + else: + # Windows users can import modules with case-insensitive file + # suffixes (for legacy reasons). Make the suffix lowercase here + # so it's done once instead of for every import. This is safe as + # the specified suffixes to check against are always specified in a + # case-sensitive manner. + lower_suffix_contents = set() + for item in contents: + name, dot, suffix = item.partition('.') + if dot: + new_name = '{}.{}'.format(name, suffix.lower()) + else: + new_name = name + lower_suffix_contents.add(new_name) + self._path_cache = lower_suffix_contents if sys.platform.startswith(CASE_INSENSITIVE_PLATFORMS): self._relaxed_path_cache = set(fn.lower() for fn in contents)
