r58262 - sandbox/trunk/import_in_py/Py3K/_importlib.py sandbox/trunk/import_in_py/Py3K/importlib.py
Author: brett.cannon Date: Wed Sep 26 22:50:49 2007 New Revision: 58262 Modified: sandbox/trunk/import_in_py/Py3K/_importlib.py sandbox/trunk/import_in_py/Py3K/importlib.py Log: Move over to using imp._case_ok() from branches/py3k-importlib. This means that this is now dependent on the branch work for testing purposes. Modified: sandbox/trunk/import_in_py/Py3K/_importlib.py ============================================================================== --- sandbox/trunk/import_in_py/Py3K/_importlib.py (original) +++ sandbox/trunk/import_in_py/Py3K/_importlib.py Wed Sep 26 22:50:49 2007 @@ -62,7 +62,7 @@ # Injected modules are 'warnings', 'imp', 'sys', 'marshal', 'errno', and '_os' # (a.k.a. 'posix', 'nt' or 'os2'). # Injected attribute is path_sep. -# XXX Temporarily injected functions are _r_long, _w_long, and _case_ok. +# XXX Temporarily injected functions are _r_long, _w_long. # XXX Could also expose Modules/getpath.c:joinpath() @@ -116,6 +116,23 @@ else: return _path_join(_os.getcwd(), path) +def _case_ok(module_name, path, ext=''): + """Wrapper for imp._case_ok() and its crazy call signature: + + Arguments: + + - buf + String containing the path to test. + - len + Length of bug minus file extension. + - name + Module name. + + """ + trimmed_path_len = len(path) - len(ext) + print('_case_ok:', path, trimmed_path_len, module_name) + return imp._case_ok(path, trimmed_path_len, module_name) + class _BuiltinFrozenBaseImporter(object): @@ -578,20 +595,21 @@ init_filename = '__init__' + ext package_init = _path_join(package_directory, init_filename) if (_path_isfile(package_init) and - _case_ok(self._path_entry, tail_module) and - _case_ok(package_directory, init_filename)): + _case_ok(tail_module, package_directory) and + _case_ok('__init__', package_init, ext)): return self._loader(fullname, package_init, True) for ext in self._suffixes: file_name = tail_module + ext file_path = _path_join(self._path_entry, file_name) if (_path_isfile(file_path) and - _case_ok(self._path_entry, file_name)): + _case_ok(tail_module, file_path, ext)): return self._loader(fullname, file_path, False) else: # Raise a warning if it matches a directory w/o an __init__ file. if (package_directory is not None and _path_isdir(package_directory) and - _case_ok(self._path_entry, tail_module)): + _case_ok(tail_module, + _path_join(self._path_entry, tail_module))): warnings.warn("Not importing directory %s: missing __init__" % package_directory, ImportWarning) Modified: sandbox/trunk/import_in_py/Py3K/importlib.py ============================================================================== --- sandbox/trunk/import_in_py/Py3K/importlib.py (original) +++ sandbox/trunk/import_in_py/Py3K/importlib.py Wed Sep 26 22:50:49 2007 @@ -74,32 +74,6 @@ return x -def _case_ok(directory, file_name): - """Verify that file_name (as found in 'directory') has the proper case. - - The path is assumed to already exist. - - XXX Temporary until imp's case_ok function can be exposed. - - XXX Better to roll this into a single function some how so that existence - check can be part of case check and thus cut down on stat calls? - - """ - # If platform is not case-sensitive *or* the environment variable - # PYTHONCASEOK is defined, then os.path.exists already handled the case by - # either doing a case-sensitive check or from the user saying he does not - # want case-sensitivity, respectively. - if sys.platform not in ('win32', 'mac', 'riscos', 'darwin', 'cygwin', - 'os2emx') or os.environ.get('PYTHONCASEOK'): - return True - directory_contents = os.listdir(directory) - if file_name in directory_contents: - return True - else: - return False - - - # Required built-in modules. try: import posix as _os @@ -125,7 +99,6 @@ from os import sep _importlib._r_long = _r_long #XXX Expose original from marshal. _importlib._w_long = _w_long #XXX Expose original from marshal. -_importlib._case_ok = _case_ok #XXX Expose original from imp. # For os.path.join replacement; pull from Include/osdefs.h:SEP . _importlib.path_sep = sep
participants (1)
-
brett.cannon