File tree 1 file changed +15
-2
lines changed 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
- """Convert a NT pathname to a file URL and vice versa."""
1
+ """Convert a NT pathname to a file URL and vice versa.
2
+
3
+ This module only exists to provide OS-specific code
4
+ for urllib.requests, thus do not use directly.
5
+ """
6
+ # Testing is done through test_urllib.
2
7
3
8
def url2pathname (url ):
4
9
"""OS-specific conversion from a relative URL of the 'file' scheme
@@ -45,6 +50,14 @@ def pathname2url(p):
45
50
# becomes
46
51
# ///C:/foo/bar/spam.foo
47
52
import urllib .parse
53
+ # First, clean up some special forms. We are going to sacrifice
54
+ # the additional information anyway
55
+ if p [:4 ] == '\\ \\ ?\\ ' :
56
+ p = p [4 :]
57
+ if p [:4 ].upper () == 'UNC\\ ' :
58
+ p = '\\ ' + p [4 :]
59
+ elif p [1 :2 ] != ':' :
60
+ raise OSError ('Bad path: ' + p )
48
61
if not ':' in p :
49
62
# No drive specifier, just convert slashes and quote the name
50
63
if p [:2 ] == '\\ \\ ' :
@@ -54,7 +67,7 @@ def pathname2url(p):
54
67
p = '\\ \\ ' + p
55
68
components = p .split ('\\ ' )
56
69
return urllib .parse .quote ('/' .join (components ))
57
- comp = p .split (':' )
70
+ comp = p .split (':' , maxsplit = 2 )
58
71
if len (comp ) != 2 or len (comp [0 ]) > 1 :
59
72
error = 'Bad path: ' + p
60
73
raise OSError (error )
You can’t perform that action at this time.
0 commit comments