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
2fc01093
Commit
2fc01093
authored
Aug 06, 2000
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite of normpath() by Corran Webster, so trailing :s are removed
(except for : and volume:, where they are needed).
parent
2afffd42
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
32 deletions
+23
-32
Lib/macpath.py
Lib/macpath.py
+23
-32
No files found.
Lib/macpath.py
View file @
2fc01093
...
...
@@ -179,39 +179,30 @@ def expanduser(path):
norm_error
=
'macpath.norm_error: path cannot be normalized'
def
normpath
(
s
):
"""Normalize a pathname: get rid of '::' sequences by backing up,
e.g., 'foo:bar::bletch' becomes 'foo:bletch'.
Raise the exception norm_error below if backing up is impossible,
e.g., for '::foo'."""
# XXX The Unix version doesn't raise an exception but simply
# returns an unnormalized path. Should do so here too.
import
string
if
':'
not
in
s
:
return
':'
+
s
f
=
string
.
splitfields
(
s
,
':'
)
pre
=
[]
post
=
[]
if
not
f
[
0
]:
pre
=
f
[:
1
]
f
=
f
[
1
:]
if
not
f
[
len
(
f
)
-
1
]:
post
=
f
[
-
1
:]
f
=
f
[:
-
1
]
res
=
[]
for
seg
in
f
:
if
seg
:
res
.
append
(
seg
)
"""Normalize a pathname. Will return the same result for
equivalent paths."""
if
":"
not
in
s
:
return
":"
+
s
comps
=
string
.
splitfields
(
s
,
":"
)
i
=
1
while
i
<
len
(
comps
)
-
1
:
if
comps
[
i
]
==
""
and
comps
[
i
-
1
]
!=
""
:
if
i
>
1
:
del
comps
[
i
-
1
:
i
+
1
]
i
=
i
-
1
else
:
# best way to handle this is to raise an exception
raise
norm_error
,
'Cannot use :: immedeately after volume name'
else
:
if
not
res
:
raise
norm_error
,
'path starts with ::'
del
res
[
len
(
res
)
-
1
]
if
not
(
pre
or
res
):
raise
norm_error
,
'path starts with volume::'
if
pre
:
res
=
pre
+
res
if
post
:
res
=
res
+
post
s
=
res
[
0
]
for
seg
in
res
[
1
:]:
s
=
s
+
':'
+
seg
i
=
i
+
1
s
=
string
.
join
(
comps
,
":"
)
# remove trailing ":" except for ":" and "Volume:"
if
s
[
-
1
]
==
":"
and
len
(
comps
)
>
2
and
s
!=
":"
*
len
(
s
):
s
=
s
[:
-
1
]
return
s
...
...
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