summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-20 16:53:14 (GMT)
committerBrett Cannon <brett@python.org>2012-04-20 16:53:14 (GMT)
commit8ff6baf25b0eac32bf3009bc383b25b687a1ec0d (patch)
tree56627a31bd98d3f12b54b3d92e054a38fb97d3da /Lib/importlib/_bootstrap.py
parent91900eaf96a55e7be0f6c445269c1a3a2a1e1b39 (diff)
downloadcpython-8ff6baf25b0eac32bf3009bc383b25b687a1ec0d.zip
cpython-8ff6baf25b0eac32bf3009bc383b25b687a1ec0d.tar.gz
cpython-8ff6baf25b0eac32bf3009bc383b25b687a1ec0d.tar.bz2
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.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 6478db5..914d853 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -841,7 +841,23 @@ class _FileFinder:
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)