Skip to content
Prev Previous commit
Next Next commit
Update Lib/ntpath.py
Co-authored-by: Eryk Sun <eryksun@gmail.com>
  • Loading branch information
barneygale and eryksun authored Dec 28, 2022
commit d2818a35c134c48d42f9f924f5165df3151a8492
26 changes: 15 additions & 11 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,31 @@ def splitdrive(p):
sep = b'\\'
altsep = b'/'
colon = b':'
unc_prefix = b'\\\\?\\UNC\\'
unc_prefix = b'\\\\'
unc_device_prefix = b'\\\\?\\UNC\\'
else:
sep = '\\'
altsep = '/'
colon = ':'
unc_prefix = '\\\\?\\UNC\\'
unc_prefix = '\\\\'
unc_device_prefix = '\\\\?\\UNC\\'
normp = p.replace(altsep, sep)
if normp[1:2] == colon and normp[:1] != sep:
# Drive-letter logical drives, e.g. X:
# Drive-letter drives, e.g. X:
return p[:2], p[2:]
if normp[:2] == sep * 2:
if normp[:2] == unc_prefix:
# UNC drives, e.g. \\server\share or \\?\UNC\server\share
# Device drives, e.g. \\.\device or \\?\device
start = 8 if normp[:8].upper() == unc_prefix else 2
index = normp.find(sep, start)
if index == -1:
start = 8 if normp[:8].upper() == unc_device_prefix else 2
index1 = normp.find(sep, start)
if index1 == -1:
return p, p[:0]
index = normp.find(sep, index + 1)
if index == -1:
return p, p[:0]
return p[:index], p[index:]
index2 = normp.find(sep, index1 + 1)
if index2 == -1:
index2 = len(p)
if index2 - index1 == 1:
return p[:index1], p[index1:]
return p[:index2], p[index2:]
return p[:0], p


Expand Down