1 """Convert a NT pathname to a file URL and vice versa."""
4 r
"""Convert a URL to a DOS path.
14 # No drive specifier, just convert slashes
16 # path is something like ////host/path/on/remote/host
17 # convert this to \\host\path\on\remote\host
18 # (notice halving of slashes at the start of the path)
20 components
= url
.split('/')
21 # make sure not to convert quoted slashes :-)
22 return urllib
.unquote('\\'.join(components
))
24 if len(comp
) != 2 or comp
[0][-1] not in string
.ascii_letters
:
25 error
= 'Bad URL: ' + url
27 drive
= comp
[0][-1].upper()
28 components
= comp
[1].split('/')
30 for comp
in components
:
32 path
= path
+ '\\' + urllib
.unquote(comp
)
36 r
"""Convert a DOS path name to a file url.
42 ///C|/foo/bar/spam.foo
47 # No drive specifier, just convert slashes and quote the name
49 # path is something like \\host\path\on\remote\host
50 # convert this to ////host/path/on/remote/host
51 # (notice doubling of slashes at the start of the path)
53 components
= p
.split('\\')
54 return urllib
.quote('/'.join(components
))
56 if len(comp
) != 2 or len(comp
[0]) > 1:
57 error
= 'Bad path: ' + p
60 drive
= urllib
.quote(comp
[0].upper())
61 components
= comp
[1].split('\\')
62 path
= '///' + drive
+ '|'
63 for comp
in components
:
65 path
= path
+ '/' + urllib
.quote(comp
)