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
77cdeaff
Commit
77cdeaff
authored
Jun 17, 2003
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modernize Lib/posixpath.py: Use startswith(), endswith(), rstrip(),
struct_passwd attributes and +=. From SF patch #755245.
parent
364ca40c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
15 deletions
+16
-15
Lib/posixpath.py
Lib/posixpath.py
+16
-15
No files found.
Lib/posixpath.py
View file @
77cdeaff
...
...
@@ -45,7 +45,7 @@ def normcase(s):
def
isabs
(
s
):
"""Test whether a path is absolute"""
return
s
[:
1
]
==
'/'
return
s
.
startswith
(
'/'
)
# Join pathnames.
...
...
@@ -56,12 +56,12 @@ def join(a, *p):
"""Join two or more pathname components, inserting '/' as needed"""
path
=
a
for
b
in
p
:
if
b
[:
1
]
==
'/'
:
if
b
.
startswith
(
'/'
)
:
path
=
b
elif
path
==
''
or
path
[
-
1
:]
==
'/'
:
path
=
path
+
b
elif
path
==
''
or
path
.
endswith
(
'/'
)
:
path
+=
b
else
:
path
=
path
+
'/'
+
b
path
+=
'/'
+
b
return
path
...
...
@@ -76,8 +76,7 @@ def split(p):
i
=
p
.
rfind
(
'/'
)
+
1
head
,
tail
=
p
[:
i
],
p
[
i
:]
if
head
and
head
!=
'/'
*
len
(
head
):
while
head
[
-
1
]
==
'/'
:
head
=
head
[:
-
1
]
head
=
head
.
rstrip
(
'/'
)
return
head
,
tail
...
...
@@ -129,7 +128,8 @@ def commonprefix(m):
for
i
in
range
(
len
(
prefix
)):
if
prefix
[:
i
+
1
]
!=
item
[:
i
+
1
]:
prefix
=
prefix
[:
i
]
if
i
==
0
:
return
''
if
i
==
0
:
return
''
break
return
prefix
...
...
@@ -301,15 +301,15 @@ def walk(top, func, arg):
def
expanduser
(
path
):
"""Expand ~ and ~user constructions. If user or $HOME is unknown,
do nothing."""
if
path
[:
1
]
!=
'~'
:
if
not
path
.
startswith
(
'~'
)
:
return
path
i
,
n
=
1
,
len
(
path
)
while
i
<
n
and
path
[
i
]
!=
'/'
:
i
=
i
+
1
i
+=
1
if
i
==
1
:
if
not
'HOME'
in
os
.
environ
:
import
pwd
userhome
=
pwd
.
getpwuid
(
os
.
getuid
())
[
5
]
userhome
=
pwd
.
getpwuid
(
os
.
getuid
())
.
pw_dir
else
:
userhome
=
os
.
environ
[
'HOME'
]
else
:
...
...
@@ -318,8 +318,9 @@ def expanduser(path):
pwent
=
pwd
.
getpwnam
(
path
[
1
:
i
])
except
KeyError
:
return
path
userhome
=
pwent
[
5
]
if
userhome
[
-
1
:]
==
'/'
:
i
=
i
+
1
userhome
=
pwent
.
pw_dir
if
userhome
.
endswith
(
'/'
):
i
+=
1
return
userhome
+
path
[
i
:]
...
...
@@ -345,13 +346,13 @@ def expandvars(path):
break
i
,
j
=
m
.
span
(
0
)
name
=
m
.
group
(
1
)
if
name
[:
1
]
==
'{'
and
name
[
-
1
:]
==
'}'
:
if
name
.
startswith
(
'{'
)
and
name
.
endswith
(
'}'
)
:
name
=
name
[
1
:
-
1
]
if
name
in
os
.
environ
:
tail
=
path
[
j
:]
path
=
path
[:
i
]
+
os
.
environ
[
name
]
i
=
len
(
path
)
path
=
path
+
tail
path
+=
tail
else
:
i
=
j
return
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