Allow paths without drive specifier (Jack).

This commit is contained in:
Guido van Rossum 1997-08-12 14:47:24 +00:00
parent e2ad88c202
commit d510b72fff
1 changed files with 8 additions and 4 deletions

View File

@ -4,8 +4,6 @@
def url2pathname(url): def url2pathname(url):
""" Convert a URL to a DOS path... """ Convert a URL to a DOS path...
Currently only works for absolute paths
///C|/foo/bar/spam.foo ///C|/foo/bar/spam.foo
becomes becomes
@ -13,6 +11,10 @@ def url2pathname(url):
C:\foo\bar\spam.foo C:\foo\bar\spam.foo
""" """
import string import string
if not '|' in url:
# No drive specifier, just convert slashes
components = string.splitfields(url, '/')
return string.joinfields(components, '\\')
comp = string.splitfields(url, '|') comp = string.splitfields(url, '|')
if len(comp) != 2 or comp[0][-1] not in string.letters: if len(comp) != 2 or comp[0][-1] not in string.letters:
error = 'Bad URL: ' + url error = 'Bad URL: ' + url
@ -28,8 +30,6 @@ def url2pathname(url):
def pathname2url(p): def pathname2url(p):
""" Convert a DOS path name to a file url... """ Convert a DOS path name to a file url...
Currently only works for absolute paths
C:\foo\bar\spam.foo C:\foo\bar\spam.foo
becomes becomes
@ -38,6 +38,10 @@ def pathname2url(p):
""" """
import string import string
if not ':' in p:
# No drive specifier, just convert slashes
components = string.splitfields(p, '\\')
return string.joinfields(components, '/')
comp = string.splitfields(p, ':') comp = string.splitfields(p, ':')
if len(comp) != 2 or len(comp[0]) > 1: if len(comp) != 2 or len(comp[0]) > 1:
error = 'Bad path: ' + p error = 'Bad path: ' + p