Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2684738

Browse files
committed
Renamed to posixpath; changed def'n of split().
1 parent 627efd9 commit 2684738

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

Lib/posixpath.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Module 'path' -- common operations on POSIX pathnames
1+
# Module 'posixpath' -- common operations on POSIX pathnames
22

33
import posix
44
import stat
@@ -31,20 +31,24 @@ def join(a, b):
3131
return a + '/' + b
3232

3333

34-
# Split a path in head (empty or ending in '/') and tail (no '/').
35-
# The tail will be empty if the path ends in '/'.
36-
# It is always true that head + tail == p; also join(head, tail) == p.
37-
# Note that because head ends in '/', if you want to find all components
38-
# of a path by repeatedly getting the head, you will have to strip off
39-
# the trailing '/' yourself (another function should be defined to
40-
# split an entire path into components.)
34+
# Split a path in head (everything up to the last '/') and tail (the
35+
# rest). If the original path ends in '/' but is not the root, this
36+
# '/' is stripped. After the trailing '/' is stripped, the invariant
37+
# join(head, tail) == p holds.
38+
# The resulting head won't end in '/' unless it is the root.
4139

4240
def split(p):
41+
if p[-1:] == '/' and p <> '/'*len(p):
42+
while p[-1] == '/':
43+
p = p[:-1]
4344
head, tail = '', ''
4445
for c in p:
4546
tail = tail + c
4647
if c == '/':
4748
head, tail = head + tail, ''
49+
if head[-1:] == '/' and head <> '/'*len(head):
50+
while head[-1] == '/':
51+
head = head[:-1]
4852
return head, tail
4953

5054

@@ -119,7 +123,7 @@ def isdir(path):
119123
return stat.S_ISDIR(st[stat.ST_MODE])
120124

121125

122-
# Is a path a regulat file?
126+
# Is a path a regular file?
123127
# This follows symbolic links, so both islink() and isdir() can be true
124128
# for the same path.
125129

0 commit comments

Comments
 (0)