Skip to content

Commit 1df0a44

Browse files
committed
Update nturl2path from Python 3.11
1 parent 3c8fb93 commit 1df0a44

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Lib/nturl2path.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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.
27

38
def url2pathname(url):
49
"""OS-specific conversion from a relative URL of the 'file' scheme
@@ -45,6 +50,14 @@ def pathname2url(p):
4550
# becomes
4651
# ///C:/foo/bar/spam.foo
4752
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)
4861
if not ':' in p:
4962
# No drive specifier, just convert slashes and quote the name
5063
if p[:2] == '\\\\':
@@ -54,7 +67,7 @@ def pathname2url(p):
5467
p = '\\\\' + p
5568
components = p.split('\\')
5669
return urllib.parse.quote('/'.join(components))
57-
comp = p.split(':')
70+
comp = p.split(':', maxsplit=2)
5871
if len(comp) != 2 or len(comp[0]) > 1:
5972
error = 'Bad path: ' + p
6073
raise OSError(error)

0 commit comments

Comments
 (0)