Kaydet (Commit) 1fb5ce03 authored tarafından Fred Drake's avatar Fred Drake

Avoid using os.path.normcase() on sys.path elements; doing so causes paths

to be presented in an unfamiliar case on case-preserving filesystems.

This closes SF patch #436173.
üst b0f05bdf
...@@ -66,22 +66,23 @@ else: ...@@ -66,22 +66,23 @@ else:
def makepath(*paths): def makepath(*paths):
dir = os.path.join(*paths) dir = os.path.abspath(os.path.join(*paths))
return os.path.normcase(os.path.abspath(dir)) return dir, os.path.normcase(dir)
L = sys.modules.values() for m in sys.modules.values():
for m in L:
if hasattr(m, "__file__") and m.__file__: if hasattr(m, "__file__") and m.__file__:
m.__file__ = makepath(m.__file__) m.__file__ = os.path.abspath(m.__file__)
del m, L del m
# This ensures that the initial path provided by the interpreter contains # This ensures that the initial path provided by the interpreter contains
# only absolute pathnames, even if we're running from the build directory. # only absolute pathnames, even if we're running from the build directory.
L = [] L = []
dirs_in_sys_path = {}
for dir in sys.path: for dir in sys.path:
dir = makepath(dir) dir, dircase = makepath(dir)
if dir not in L: if not dirs_in_sys_path.has_key(dircase):
L.append(dir) L.append(dir)
dirs_in_sys_path[dircase] = 1
sys.path[:] = L sys.path[:] = L
del dir, L del dir, L
...@@ -95,14 +96,13 @@ if os.name == "posix" and os.path.basename(sys.path[-1]) == "Modules": ...@@ -95,14 +96,13 @@ if os.name == "posix" and os.path.basename(sys.path[-1]) == "Modules":
del get_platform, s del get_platform, s
def addsitedir(sitedir): def addsitedir(sitedir):
sitedir = makepath(sitedir) sitedir, sitedircase = makepath(sitedir)
if sitedir not in sys.path: if not dirs_in_sys_path.has_key(sitedircase):
sys.path.append(sitedir) # Add path component sys.path.append(sitedir) # Add path component
try: try:
names = os.listdir(sitedir) names = os.listdir(sitedir)
except os.error: except os.error:
return return
names = map(os.path.normcase, names)
names.sort() names.sort()
for name in names: for name in names:
if name[-4:] == endsep + "pth": if name[-4:] == endsep + "pth":
...@@ -125,9 +125,10 @@ def addpackage(sitedir, name): ...@@ -125,9 +125,10 @@ def addpackage(sitedir, name):
continue continue
if dir[-1] == '\n': if dir[-1] == '\n':
dir = dir[:-1] dir = dir[:-1]
dir = makepath(sitedir, dir) dir, dircase = makepath(sitedir, dir)
if dir not in sys.path and os.path.exists(dir): if not dirs_in_sys_path.has_key(dircase) and os.path.exists(dir):
sys.path.append(dir) sys.path.append(dir)
dirs_in_sys_path[dircase] = 1
prefixes = [sys.prefix] prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix: if sys.exec_prefix != sys.prefix:
...@@ -135,19 +136,21 @@ if sys.exec_prefix != sys.prefix: ...@@ -135,19 +136,21 @@ if sys.exec_prefix != sys.prefix:
for prefix in prefixes: for prefix in prefixes:
if prefix: if prefix:
if os.sep == '/': if os.sep == '/':
sitedirs = [makepath(prefix, sitedirs = [os.path.join(prefix,
"lib", "lib",
"python" + sys.version[:3], "python" + sys.version[:3],
"site-packages"), "site-packages"),
makepath(prefix, "lib", "site-python")] os.path.join(prefix, "lib", "site-python")]
elif os.sep == ':': elif os.sep == ':':
sitedirs = [makepath(prefix, "lib", "site-packages")] sitedirs = [os.path.join(prefix, "lib", "site-packages")]
else: else:
sitedirs = [prefix] sitedirs = [prefix]
for sitedir in sitedirs: for sitedir in sitedirs:
if os.path.isdir(sitedir): if os.path.isdir(sitedir):
addsitedir(sitedir) addsitedir(sitedir)
del dirs_in_sys_path
# Define new built-ins 'quit' and 'exit'. # Define new built-ins 'quit' and 'exit'.
# These are simply strings that display a hint on how to exit. # These are simply strings that display a hint on how to exit.
if os.sep == ':': if os.sep == ':':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment