Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cpython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
Cpython
Commits
a9da5ae0
Commit
a9da5ae0
authored
Jun 19, 2003
by
Walter Dörwald
Browse files
Options
Downloads
Patches
Plain Diff
Use find() instead of looping over the string in expanduser().
From SF patch #757058.
parent
76ca1d42
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Lib/posixpath.py
+4
-4
4 additions, 4 deletions
Lib/posixpath.py
Lib/test/test_posixpath.py
+5
-1
5 additions, 1 deletion
Lib/test/test_posixpath.py
with
9 additions
and
5 deletions
Lib/posixpath.py
+
4
−
4
View file @
a9da5ae0
...
...
@@ -303,11 +303,11 @@ def expanduser(path):
do nothing.
"""
if
not
path
.
startswith
(
'
~
'
):
return
path
i
,
n
=
1
,
len
(
path
)
while
i
<
n
and
path
[
i
]
!=
'
/
'
:
i
+
=
1
i
=
path
.
find
(
'
/
'
,
1
)
if
i
<
0
:
i
=
len
(
path
)
if
i
==
1
:
if
not
'
HOME
'
in
os
.
environ
:
if
'
HOME
'
not
in
os
.
environ
:
import
pwd
userhome
=
pwd
.
getpwuid
(
os
.
getuid
()).
pw_dir
else
:
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_posixpath.py
+
5
−
1
View file @
a9da5ae0
...
...
@@ -332,12 +332,16 @@ def test_ismount(self):
def
test_expanduser
(
self
):
self
.
assertEqual
(
posixpath
.
expanduser
(
"
foo
"
),
"
foo
"
)
self
.
assert_
(
isinstance
(
posixpath
.
expanduser
(
"
~/
"
),
basestring
))
try
:
import
pwd
except
ImportError
:
pass
else
:
self
.
assert_
(
isinstance
(
posixpath
.
expanduser
(
"
~/
"
),
basestring
))
self
.
assertEqual
(
posixpath
.
expanduser
(
"
~
"
)
+
"
/
"
,
posixpath
.
expanduser
(
"
~/
"
)
)
self
.
assert_
(
isinstance
(
posixpath
.
expanduser
(
"
~root/
"
),
basestring
))
self
.
assert_
(
isinstance
(
posixpath
.
expanduser
(
"
~foo/
"
),
basestring
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment