[Python-checkins] cpython: Relocate importlib._case_ok to importlib._bootstrap.
brett.cannon
python-checkins at python.org
Fri Jan 27 01:09:51 CET 2012
http://hg.python.org/cpython/rev/ecf4a7bb8807
changeset: 74643:ecf4a7bb8807
parent: 74638:dc3de15b43db
user: Brett Cannon <brett at python.org>
date: Thu Jan 26 19:03:52 2012 -0500
summary:
Relocate importlib._case_ok to importlib._bootstrap.
This required updating the code to use posix instead of os. This is
all being done to make bootstrapping easier to removing dependencies
that are kept in importlib.__init__ and thus outside of the single
file to bootstrap from.
files:
Lib/importlib/__init__.py | 19 -----------------
Lib/importlib/_bootstrap.py | 27 +++++++++++++++++++++++++
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -33,25 +33,6 @@
# Bootstrap help #####################################################
-# TODO: Expose from import.c, else handle encode/decode as _os.environ returns
-# bytes.
-def _case_ok(directory, check):
- """Check if the directory contains something matching 'check'.
-
- No check is done if the file/directory exists or not.
-
- """
- if 'PYTHONCASEOK' in os.environ:
- return True
- if not directory:
- directory = os.getcwd()
- if check in os.listdir(directory):
- return True
- return False
-
-_bootstrap._case_ok = _case_ok
-
-
# Required built-in modules.
try:
import posix as _os
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -18,6 +18,33 @@
# Bootstrap-related code ######################################################
+# TODO: when not on any of these platforms, replace _case_ok() w/
+# ``lambda x,y: True``.
+CASE_OK_PLATFORMS = 'win', 'cygwin', 'darwin'
+
+def _case_ok(directory, check):
+ """Check if the directory contains something matching 'check'
+ case-sensitively when running on Windows or OS X.
+
+ If running on Window or OS X and PYTHONCASEOK is a defined environment
+ variable then no case-sensitive check is performed. No check is done to see
+ if what is being checked for exists, so if the platform is not Windows or
+ OS X then assume the case is fine.
+
+ """
+ if (any(map(sys.platform.startswith, CASE_OK_PLATFORMS)) and
+ b'PYTHONCASEOK' not in _os.environ):
+ if not directory:
+ directory = '.'
+ if check in _os.listdir(directory):
+ return True
+ else:
+ return False
+ else:
+ return True
+
+
+
# TODO: Expose from marshal
def _w_long(x):
"""Convert a 32-bit integer to little-endian.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list