1 """Convert a NT pathname to a file URL and vice versa."""
4 """ Convert a URL to a DOS path...
13 # No drive specifier, just convert slashes
15 # path is something like ////host/path/on/remote/host
16 # convert this to \\host\path\on\remote\host
17 # (notice halving of slashes at the start of the path)
19 components
= string
.split(url
, '/')
20 # make sure not to convert quoted slashes :-)
21 return urllib
.unquote(string
.join(components
, '\\'))
22 comp
= string
.split(url
, '|')
23 if len(comp
) != 2 or comp
[0][-1] not in string
.letters
:
24 error
= 'Bad URL: ' + url
26 drive
= string
.upper(comp
[0][-1])
27 components
= string
.split(comp
[1], '/')
29 for comp
in components
:
31 path
= path
+ '\\' + urllib
.unquote(comp
)
35 """ Convert a DOS path name to a file url...
40 ///C|/foo/bar/spam.foo
45 # No drive specifier, just convert slashes and quote the name
47 # path is something like \\host\path\on\remote\host
48 # convert this to ////host/path/on/remote/host
49 # (notice doubling of slashes at the start of the path)
51 components
= string
.split(p
, '\\')
52 return urllib
.quote(string
.join(components
, '/'))
53 comp
= string
.split(p
, ':')
54 if len(comp
) != 2 or len(comp
[0]) > 1:
55 error
= 'Bad path: ' + p
58 drive
= urllib
.quote(string
.upper(comp
[0]))
59 components
= string
.split(comp
[1], '\\')
60 path
= '///' + drive
+ '|'
61 for comp
in components
:
63 path
= path
+ '/' + urllib
.quote(comp
)