summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2000-07-12 16:55:57 (GMT)
committerSkip Montanaro <skip@pobox.com>2000-07-12 16:55:57 (GMT)
commit97bc98aea784c64a74b6656f950ab2dffe84f228 (patch)
treecd39bcdb671a52e918ce9b893fa380ac23af6e51 /Lib/posixpath.py
parent03657cfdb056dbd36db12cc3db12a6b58a962e20 (diff)
downloadcpython-97bc98aea784c64a74b6656f950ab2dffe84f228.zip
cpython-97bc98aea784c64a74b6656f950ab2dffe84f228.tar.gz
cpython-97bc98aea784c64a74b6656f950ab2dffe84f228.tar.bz2
fixed semantics of commonprefix to work by path elements instead of
characters.
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 14b9270..1be5d29 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -118,14 +118,21 @@ def dirname(p):
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
- prefix = m[0]
- for item in m:
+ n = m[:]
+ for i in range(len(n)):
+ n[i] = n[i].split(os.sep)
+ # if os.sep didn't have any effect, try os.altsep
+ if os.altsep and len(n[i]) == 1:
+ n[i] = n[i].split(os.altsep)
+
+ prefix = n[0]
+ for item in n:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
- return prefix
+ return os.sep.join(prefix)
# Get size, mtime, atime of files.