diff options
author | Guido van Rossum <guido@python.org> | 1991-08-16 13:27:58 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-08-16 13:27:58 (GMT) |
commit | 4d0fdc34d1b09d0ff68359f1949bde6c7db9e338 (patch) | |
tree | a56ef139b2d161c8489a428f7f3fb7b66c6aebca /Lib | |
parent | fbe0a8e0901e145017db0d52fed156869df4d5ea (diff) | |
download | cpython-4d0fdc34d1b09d0ff68359f1949bde6c7db9e338.zip cpython-4d0fdc34d1b09d0ff68359f1949bde6c7db9e338.tar.gz cpython-4d0fdc34d1b09d0ff68359f1949bde6c7db9e338.tar.bz2 |
path.cat --> join
Added splitext
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/posixpath.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 0c0d09f..456743c 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -4,19 +4,24 @@ import posix import stat -# Intelligent pathname concatenation. -# Inserts a '/' unless the first part is empty or already ends in '/'. -# Ignores the first part altogether if the second part is absolute +# Join two pathnames. +# Insert a '/' unless the first part is empty or already ends in '/'. +# Ignore the first part altogether if the second part is absolute # (begins with '/'). # -def cat(a, b): +def join(a, b): if b[:1] = '/': return b if a = '' or a[-1:] = '/': return a + b + # Note: join('x', '') returns 'x/'; is this what we want? return a + '/' + b +cat = join # For compatibility + + # Split a path in head (empty or ending in '/') and tail (no '/'). # The tail will be empty if the path ends in '/'. +# It is always true that head+tail = p. # def split(p): head, tail = '', '' @@ -27,6 +32,23 @@ def split(p): return head, tail +# Split a path in root and extension. +# The extension is everything starting at the first dot in the last +# pathname component; the root is everything before that. +# It is always true that root+ext = p. +# +def splitext(p): + root, ext = '', '' + for c in p: + if c = '/': + root, ext = root + ext + c, '' + elif c = '.' or ext: + ext = ext + c + else: + root = root + c + return root, ext + + # Return the tail (basename) part of a path. # def basename(p): @@ -120,6 +142,6 @@ def walk(top, func, arg): exceptions = ('.', '..') for name in names: if name not in exceptions: - name = cat(top, name) + name = join(top, name) if isdir(name): walk(name, func, arg) |