diff options
author | Skip Montanaro <skip@pobox.com> | 2000-08-22 13:01:53 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2000-08-22 13:01:53 (GMT) |
commit | 623583165e9250e6288dcdaa119148257c4a25e2 (patch) | |
tree | 19c3f196fae609ed19dd4bfb2c9193d3f5e59ff3 | |
parent | 6424524fbe6a6a68289ca70a6d3387ac84f88fa9 (diff) | |
download | cpython-623583165e9250e6288dcdaa119148257c4a25e2.zip cpython-623583165e9250e6288dcdaa119148257c4a25e2.tar.gz cpython-623583165e9250e6288dcdaa119148257c4a25e2.tar.bz2 |
revert semantics of commonprefix to work character-by-character
-rw-r--r-- | Lib/dospath.py | 16 | ||||
-rw-r--r-- | Lib/ntpath.py | 11 | ||||
-rw-r--r-- | Lib/posixpath.py | 10 |
3 files changed, 11 insertions, 26 deletions
diff --git a/Lib/dospath.py b/Lib/dospath.py index 55123a1..98efe67 100644 --- a/Lib/dospath.py +++ b/Lib/dospath.py @@ -3,7 +3,6 @@ import os import stat import string -import re def normcase(s): @@ -103,23 +102,18 @@ def dirname(p): return split(p)[0] -# Return the longest prefix of all list elements. - def commonprefix(m): - "Given a list of pathnames, returns the longest common leading component" + """Return the longest prefix of all list elements.""" + if not m: return '' - n = map(string.lower, m) - for i in range(len(n)): - n[i] = re.split(r"[/\\]", n[i]) - - prefix = n[0] - for item in n: + prefix = m[0] + for item in m: for i in range(len(prefix)): if prefix[:i+1] <> item[:i+1]: prefix = prefix[:i] if i == 0: return '' break - return "\\".join(prefix) + return prefix # Get size, mtime, atime of files. diff --git a/Lib/ntpath.py b/Lib/ntpath.py index f8334e5..aa441bd 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -8,7 +8,6 @@ module as os.path. import os import stat import string -import re # Normalize the case of a pathname and map slashes to backslashes. @@ -159,18 +158,14 @@ def dirname(p): def commonprefix(m): "Given a list of pathnames, returns the longest common leading component" if not m: return '' - n = map(string.lower, m) - for i in range(len(n)): - n[i] = re.split(r"[/\\]", n[i]) - - prefix = n[0] - for item in n: + prefix = m[0] + for item in m: for i in range(len(prefix)): if prefix[:i+1] <> item[:i+1]: prefix = prefix[:i] if i == 0: return '' break - return "\\".join(prefix) + return prefix # Get size, mtime, atime of files. diff --git a/Lib/posixpath.py b/Lib/posixpath.py index d8da4ef..f7e0161 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -118,18 +118,14 @@ def dirname(p): def commonprefix(m): "Given a list of pathnames, returns the longest common leading component" if not m: return '' - n = m[:] - for i in range(len(n)): - n[i] = n[i].split("/") - - prefix = n[0] - for item in n: + prefix = m[0] + for item in m: for i in range(len(prefix)): if prefix[:i+1] <> item[:i+1]: prefix = prefix[:i] if i == 0: return '' break - return "/".join(prefix) + return prefix # Get size, mtime, atime of files. |