8000 gh-117114: Add `isdevdrive` to `posixpath` by nineteendo · Pull Request #117115 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117114: Add isdevdrive to posixpath #117115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 25, 2024
8000
Prev Previous commit
Next Next commit
Fixed splitdrive for "/:/foo"
  • Loading branch information
nineteendo committed Mar 21, 2024
commit e9cc0c968135e61436c56e6b27c66f4bdbea1760
9 changes: 5 additions & 4 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def splitdrive(p):
colon = ':'
unc_prefix = '\\\\?\\UNC\\'
normp = p.replace(altsep, sep)
if normp[:2] == sep * 2:
if normp[:1] != sep:
if normp[1:2] == colon:
# Drive-letter drives, e.g. X:
return p[:2], p[2:]
elif normp[1:2] == sep:
# 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
Expand All @@ -188,9 +192,6 @@ def splitdrive(p):
if index2 == -1:
return p, p[:0]
return p[:index2], p[index2:]
if normp[1:2] == colon:
# Drive-letter drives, e.g. X:
return p[:2], p[2:]
return p[:0], p


Expand Down
9 changes: 5 additions & 4 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def test_splitdrive(self):
tester('ntpath.splitdrive("//?/UNC/server/share/dir")',
("//?/UNC/server/share", "/dir"))

# gh-101363: match GetFullPathNameW() drive letter parsing behaviour
tester('ntpath.splitdrive(" :/foo")', (" :", "/foo"))
tester('ntpath.splitdrive("/:/foo")', ("", "/:/foo"))


def test_splitroot(self):
tester("ntpath.splitroot('')", ('', '', ''))
tester("ntpath.splitroot('foo')", ('', '', 'foo'))
Expand Down Expand Up @@ -210,10 +215,6 @@ def test_splitroot(self):
tester('ntpath.splitroot("//x")', ("//x", "", "")) # non-empty server & missing share
tester('ntpath.splitroot("//x/")', ("//x/", "", "")) # non-empty server & empty share

# gh-101363: match GetFullPathNameW() drive letter parsing behaviour
tester('ntpath.splitroot(" :/foo")', (" :", "/", "foo"))
tester('ntpath.splitroot("/:/foo")', ("", "/", ":/foo"))

def test_split(self):
tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
Expand Down
0