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
746ea359
Commit
746ea359
authored
Jun 26, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
url2path for NT
parent
2281d355
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
Lib/nturl2path.py
Lib/nturl2path.py
+52
-0
No files found.
Lib/nturl2path.py
0 → 100644
View file @
746ea359
#
# nturl2path convert a NT pathname to a file URL and
# vice versa
def
url2pathname
(
url
):
""" Convert a URL to a DOS path...
Currently only works for absolute paths
///C|/foo/bar/spam.foo
becomes
C:
\
f
oo
\
b
ar
\
sp
a
m.foo
"""
import
string
comp
=
string
.
splitfields
(
url
,
'|'
)
if
len
(
comp
)
!=
2
or
comp
[
0
][
-
1
]
not
in
string
.
letters
:
error
=
'Bad URL: '
+
url
raise
IOError
,
error
drive
=
string
.
upper
(
comp
[
0
][
-
1
])
components
=
string
.
splitfields
(
comp
[
1
],
'/'
)
path
=
drive
+
':'
for
comp
in
components
:
if
comp
:
path
=
path
+
'
\
\
'
+
comp
return
path
def
pathname2url
(
p
):
""" Convert a DOS path name to a file url...
Currently only works for absolute paths
C:
\
f
oo
\
b
ar
\
sp
a
m.foo
becomes
///C|/foo/bar/spam.foo
"""
import
string
comp
=
string
.
splitfields
(
p
,
':'
)
if
len
(
comp
)
!=
2
or
len
(
comp
[
0
])
>
1
:
error
=
'Bad path: '
+
p
raise
IOError
,
error
drive
=
string
.
upper
(
comp
[
0
])
components
=
string
.
splitfields
(
comp
[
1
],
'
\
\
'
)
path
=
'///'
+
drive
+
'|'
for
comp
in
components
:
if
comp
:
path
=
path
+
'/'
+
comp
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