From 6ac0014c2c310e01f93c1a9830bd19d5a64399bc Mon Sep 17 00:00:00 2001 From: Ngalim Siregar Date: Thu, 18 Jul 2019 21:36:05 +0700 Subject: [PATCH 1/5] bpo-37609: Add device path support in ntpath splitdrive --- Lib/ntpath.py | 35 +++++++++++++++++++++++++---------- Lib/test/test_ntpath.py | 5 +++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 1d22d5f1dc2ab5..2cc653cc0f3213 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -134,16 +134,9 @@ 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\... @@ -151,6 +144,9 @@ def splitdrive(p): index = normp.find(sep, 2) if index == -1: return p[:0], p + if is_extended_unc(normp, colon): + start = normp.find(sep, index + 1) + 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) @@ -159,11 +155,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): + 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 + + +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. diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 285fb69dc1e88f..4a12efd5df5d54 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -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')) From 00d328be4b650ba94262baea1f839adfd6707780 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2019 14:40:01 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst diff --git a/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst b/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst new file mode 100644 index 00000000000000..b62073a3330e6e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst @@ -0,0 +1 @@ +Add support for unc device path in :mod:`ntpath.splitdrive` \ No newline at end of file From c0447ffdbaba9eaee9f70d8b56d80a2fa26b4e14 Mon Sep 17 00:00:00 2001 From: Ngalim Siregar Date: Fri, 19 Jul 2019 23:23:30 +0700 Subject: [PATCH 3/5] Update logic when found colon in UNC --- Lib/ntpath.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 2cc653cc0f3213..2db4f102121645 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -146,7 +146,9 @@ def splitdrive(p): return p[:0], p if is_extended_unc(normp, colon): start = normp.find(sep, index + 1) - index = normp.find(sep, start + 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) From 1981add34c9a17b44cd470a54d5234859dbf9c71 Mon Sep 17 00:00:00 2001 From: Ngalim Siregar Date: Sat, 20 Jul 2019 01:18:34 +0700 Subject: [PATCH 4/5] Change how detecting extending UNC Path --- Lib/ntpath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 2db4f102121645..5496ef8e112fc8 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -171,7 +171,7 @@ def is_drive_path(path, colon): def is_extended_unc(path, colon): - return path[2] in ['?', '.'] and path[-2] != colon + return path[2] in ['?', '.'] and path[-2] != colon and path[4:7] == 'UNC' def get_separator(path): From eb4e996f41e6be93363eb1cd8e7b6872cb86a712 Mon Sep 17 00:00:00 2001 From: Ngalim Siregar Date: Sun, 28 Jul 2019 09:24:55 +0700 Subject: [PATCH 5/5] Update role in Misc message --- .../next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst b/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst index b62073a3330e6e..37430f1bb0f4e0 100644 --- a/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst +++ b/Misc/NEWS.d/next/Library/2019-07-18-14-39-59.bpo-37609.1ZYNbG.rst @@ -1 +1 @@ -Add support for unc device path in :mod:`ntpath.splitdrive` \ No newline at end of file +Add support for unc device path in :func:`ntpath.splitdrive` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy