diff options
author | Barry Warsaw <barry@python.org> | 1997-02-18 21:53:25 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1997-02-18 21:53:25 (GMT) |
commit | 384d249006b786b7d1eed21795a83a5ab703cb96 (patch) | |
tree | 06c3626a8e9239e23f6edc7771821e9b550bb4e1 /Lib/macpath.py | |
parent | 736bb0659fba85392e5b2034ed492a9e8bfad8d9 (diff) | |
download | cpython-384d249006b786b7d1eed21795a83a5ab703cb96.zip cpython-384d249006b786b7d1eed21795a83a5ab703cb96.tar.gz cpython-384d249006b786b7d1eed21795a83a5ab703cb96.tar.bz2 |
join(): join one or more path components
Diffstat (limited to 'Lib/macpath.py')
-rw-r--r-- | Lib/macpath.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py index c45ecbf..a6cf66b 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -20,18 +20,24 @@ def isabs(s): return ':' in s and s[0] <> ':' -# Join two pathnames. -# The result is equivalent to what the second pathname would refer to -# if the first pathname were the current directory. - -def join(s, t): - if (not s) or isabs(t): return t - if t[:1] == ':': t = t[1:] - if ':' not in s: - s = ':' + s - if s[-1:] <> ':': - s = s + ':' - return s + t +# Join pathnames. +# Ignore the previous parts if a part is absolute. +# Insert a '/' unless the first part is empty or already ends in '/'. + +def join(s, *p): + path = s + for t in p: + if (not s) or isabs(t): + path = t + continue + if t[:1] == ':': + t = t[1:] + if ':' not in path: + path = ':' + path + if path[-1:] <> ':': + path = path + ':' + path = path + t + return path # Split a pathname in two parts: the directory leading up to the final bit, |