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
018dfae2
Commit
018dfae2
authored
Jul 19, 2000
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added rewritten normpath from Moshe Zadka that does the right thing with
paths containing ..
parent
7cb15245
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
23 deletions
+18
-23
Lib/posixpath.py
Lib/posixpath.py
+18
-23
No files found.
Lib/posixpath.py
View file @
018dfae2
...
@@ -346,30 +346,25 @@ are left unchanged"""
...
@@ -346,30 +346,25 @@ are left unchanged"""
def
normpath
(
path
):
def
normpath
(
path
):
"""Normalize path, eliminating double slashes, etc."""
"""Normalize path, eliminating double slashes, etc."""
if
path
==
''
:
return
'.'
import
string
import
string
# Treat initial slashes specially
initial_slash
=
(
path
[
0
]
==
'/'
)
slashes
=
''
comps
=
string
.
split
(
path
,
'/'
)
while
path
[:
1
]
==
'/'
:
new_comps
=
[]
slashes
=
slashes
+
'/'
for
comp
in
comps
:
path
=
path
[
1
:]
if
comp
in
(
''
,
'.'
):
comps
=
string
.
splitfields
(
path
,
'/'
)
continue
i
=
0
if
(
comp
!=
'..'
or
(
not
initial_slash
and
not
new_comps
)
or
while
i
<
len
(
comps
):
(
new_comps
and
new_comps
[
-
1
]
==
'..'
)):
if
comps
[
i
]
==
'.'
:
new_comps
.
append
(
comp
)
del
comps
[
i
]
elif
new_comps
:
while
i
<
len
(
comps
)
and
comps
[
i
]
==
''
:
new_comps
.
pop
()
del
comps
[
i
]
comps
=
new_comps
elif
comps
[
i
]
==
'..'
and
i
>
0
and
comps
[
i
-
1
]
not
in
(
''
,
'..'
):
path
=
string
.
join
(
comps
,
'/'
)
del
comps
[
i
-
1
:
i
+
1
]
if
initial_slash
:
i
=
i
-
1
path
=
'/'
+
path
elif
comps
[
i
]
==
''
and
i
>
0
and
comps
[
i
-
1
]
<>
''
:
return
path
or
'.'
del
comps
[
i
]
else
:
i
=
i
+
1
# If the path is now empty, substitute '.'
if
not
comps
and
not
slashes
:
comps
.
append
(
'.'
)
return
slashes
+
string
.
joinfields
(
comps
,
'/'
)
def
abspath
(
path
):
def
abspath
(
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