Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2cddc31a
Commit
2cddc31a
authored
Mar 31, 1992
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed to posixpath; changed def'n of split().
parent
3930abf4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
Lib/posixpath.py
Lib/posixpath.py
+13
-9
No files found.
Lib/posixpath.py
View file @
2cddc31a
# Module 'path' -- common operations on POSIX pathnames
# Module 'p
osixp
ath' -- common operations on POSIX pathnames
import
posix
import
posix
import
stat
import
stat
...
@@ -31,20 +31,24 @@ def join(a, b):
...
@@ -31,20 +31,24 @@ def join(a, b):
return
a
+
'/'
+
b
return
a
+
'/'
+
b
# Split a path in head (empty or ending in '/') and tail (no '/').
# Split a path in head (everything up to the last '/') and tail (the
# The tail will be empty if the path ends in '/'.
# rest). If the original path ends in '/' but is not the root, this
# It is always true that head + tail == p; also join(head, tail) == p.
# '/' is stripped. After the trailing '/' is stripped, the invariant
# Note that because head ends in '/', if you want to find all components
# join(head, tail) == p holds.
# of a path by repeatedly getting the head, you will have to strip off
# The resulting head won't end in '/' unless it is the root.
# the trailing '/' yourself (another function should be defined to
# split an entire path into components.)
def
split
(
p
):
def
split
(
p
):
if
p
[
-
1
:]
==
'/'
and
p
<>
'/'
*
len
(
p
):
while
p
[
-
1
]
==
'/'
:
p
=
p
[:
-
1
]
head
,
tail
=
''
,
''
head
,
tail
=
''
,
''
for
c
in
p
:
for
c
in
p
:
tail
=
tail
+
c
tail
=
tail
+
c
if
c
==
'/'
:
if
c
==
'/'
:
head
,
tail
=
head
+
tail
,
''
head
,
tail
=
head
+
tail
,
''
if
head
[
-
1
:]
==
'/'
and
head
<>
'/'
*
len
(
head
):
while
head
[
-
1
]
==
'/'
:
head
=
head
[:
-
1
]
return
head
,
tail
return
head
,
tail
...
@@ -119,7 +123,7 @@ def isdir(path):
...
@@ -119,7 +123,7 @@ def isdir(path):
return
stat
.
S_ISDIR
(
st
[
stat
.
ST_MODE
])
return
stat
.
S_ISDIR
(
st
[
stat
.
ST_MODE
])
# Is a path a regula
t
file?
# Is a path a regula
r
file?
# This follows symbolic links, so both islink() and isdir() can be true
# This follows symbolic links, so both islink() and isdir() can be true
# for the same path.
# for the same path.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment