GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-37609: Add device path support in ntpath splitdrive by nsiregar · Pull Request #14841 · python/cpython

bpo-37609: Add device path support in ntpath splitdrive #14841

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.

Sign up for GitHub

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

Closed
nsiregar wants to merge 5 commits into python:main from nsiregar:bpo-37609-support-unc-device-path-ntpath-splitdrive

Uh oh!

There was an error while loading. Please reload this page.

Closed

bpo-37609: Add device path support in ntpath splitdrive #14841

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
6ac0014
bpo-37609: Add device path support in ntpath splitdrive
nsiregar Jul 18, 2019
00d328b
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 18, 2019
c0447ff
Update logic when found colon in UNC
nsiregar Jul 19, 2019
1981add
Change how detecting extending UNC Path
nsiregar Jul 19, 2019
eb4e996
Update role in Misc message
nsiregar Jul 28, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

37 changes: 27 additions & 10 deletions 37 Lib/ntpath.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,21 @@ def splitdrive(p):
"""
p = os.fspath(p)
if len(p) >= 2:
if isinstance(p, bytes):
sep = b'\\'
altsep = b'/'
colon = b':'
else:
sep = '\\'
altsep = '/'
colon = ':'
sep, altsep, colon = get_separator(p)
normp = p.replace(altsep, sep)
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
if is_unc_path(normp, sep):
# is a UNC path:
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
# \\machine\mountpoint\directory\etc\...
# directory ^^^^^^^^^^^^^^^
index = normp.find(sep, 2)
if index == -1:
return p[:0], p
if is_extended_unc(normp, colon):
start = normp.find(sep, index + 1)
drive_colon = normp.find(colon, index + 1)
if drive_colon == -1 or drive_colon > start:
index = normp.find(sep, start + 1)
index2 = normp.find(sep, index + 1)
# a UNC path can't have two slashes in a row
# (after the initial two)
Expand All @@ -159,11 +157,30 @@ def splitdrive(p):
if index2 == -1:
index2 = len(p)
return p[:index2], p[index2:]
if normp[1:2] == colon:
if is_drive_path(normp, colon):
return p[:2], p[2:]
return p[:0], p


def is_unc_path(path, sep):
Comment thread

@eryksun eryksun Sep 12, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are clearly private (e.g. parameterized by sep and colon), so the function names should have a leading underscore.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
return (path[0:2] == sep*2) and (path[2:3] != sep)


def is_drive_path(path, colon):
return path[1:2] == colon


def is_extended_unc(path, colon):
return path[2] in ['?', '.'] and path[-2] != colon and path[4:7] == 'UNC'


def get_separator(path):
sep, altsep, colon = ['\\', '/', ':']
if isinstance(path, bytes):
sep, altsep, colon = [b'\\', b'/', b':']
return sep, altsep, colon


# Split a path in head (everything up to the last '/') and tail (the
# rest). After the trailing '/' is stripped, the invariant
# join(head, tail) == p holds.
Expand Down
5 changes: 5 additions & 0 deletions 5 Lib/test/test_ntpath.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def test_splitdrive(self):
# Issue #19911: UNC part containing U+0130
self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'),
('//conky/MOUNTPOİNT', '/foo/bar'))
# Issue #37609: UNC device path
self.assertEqual(ntpath.splitdrive('//?/UNC/localhost/C$/foo/bar'),
('//?/UNC/localhost/C$', '/foo/bar'))
self.assertEqual(ntpath.splitdrive('//./UNC/localhost/C$/foo/bar'),
('//./UNC/localhost/C$', '/foo/bar'))

def test_split(self):
tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for unc device path in :func:`ntpath.splitdrive`
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.