diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2000-08-23 09:13:40 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2000-08-23 09:13:40 (GMT) |
commit | 03c06ee7fc62512c4b2af0ed3c57a09128f4b2ce (patch) | |
tree | 8409b3096b9dcea31ada4fcb6194567c8583cb13 | |
parent | a48b5267456bbc7cd252c4a88f8785495fdbf586 (diff) | |
download | cpython-03c06ee7fc62512c4b2af0ed3c57a09128f4b2ce.zip cpython-03c06ee7fc62512c4b2af0ed3c57a09128f4b2ce.tar.gz cpython-03c06ee7fc62512c4b2af0ed3c57a09128f4b2ce.tar.bz2 |
Restored commonprefix() semantics.
-rw-r--r-- | Lib/macpath.py | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py index 7634f8e..15f42f2 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -89,29 +89,6 @@ def dirname(s): return split(s)[0] def basename(s): return split(s)[1] -# Return the longest prefix of all list elements. -# XXX completely untested on Mac!!! - -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(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 os.sep.join(prefix) - - def isdir(s): """Return true if the pathname refers to an existing directory.""" @@ -166,6 +143,19 @@ def exists(s): return 0 return 1 +# Return the longest prefix of all list elements. + +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: + for i in range(len(prefix)): + if prefix[:i+1] <> item[:i+1]: + prefix = prefix[:i] + if i == 0: return '' + break + return prefix def expandvars(path): """Dummy to retain interface-compatibility with other operating systems.""" |