Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-81790: support "UNC" device paths inntpath.splitdrive()#91882

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
c97bfbf
gh-81790: support "UNC" device paths in ntpath.splitdrive()
barneygaleApr 24, 2022
2da18ba
Add docs, news, tests.
barneygaleApr 24, 2022
49f9373
Add a couple of comments.
barneygaleApr 24, 2022
57840d4
Improve variable names a little
barneygaleApr 24, 2022
264d79e
Address review feedback
barneygaleApr 25, 2022
0652b12
Add a few comments
barneygaleApr 25, 2022
bcc561c
Fix volume-by-guid path support
barneygaleApr 26, 2022
40c1eaf
Update Lib/ntpath.py
barneygaleApr 26, 2022
34358c8
Update Lib/ntpath.py
barneygaleApr 26, 2022
0213a72
Update Lib/ntpath.py
barneygaleApr 26, 2022
a7fa62b
Revise implementation to affect only paths beginning `\\?\UNC\`.
barneygaleMay 28, 2022
992f59d
Undo formatting change.
barneygaleMay 28, 2022
3f163ff
Re-introduce comment with some interesting findings on extended paths.
barneygaleMay 28, 2022
4244684
Fix handling of `\\?\UNC` (no trailing slash)
barneygaleMay 31, 2022
471e3b4
Remove extending paths findings comment.
barneygaleMay 31, 2022
8f9ab9a
Remove unnecessary tests
barneygaleJun 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
gh-81790: support "UNC" device paths in ntpath.splitdrive()
  • Loading branch information
@barneygale
barneygale committedApr 24, 2022
commitc97bfbf31fd300d50d60d9e0559d499f11120651
21 changes: 17 additions & 4 deletionsLib/ntpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -146,17 +146,30 @@ def splitdrive(p):
sep = b'\\'
altsep = b'/'
colon = b':'
unc2 = b'\\\\'
unc4 = b'\\\\?\\'
unc8 = b'\\\\?\\UNC\\'
else:
sep = '\\'
altsep = '/'
colon = ':'
unc2 = '\\\\'
unc4 = '\\\\?\\'
unc8 = '\\\\?\\UNC\\'
normp = p.replace(altsep, sep)
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
if normp[:8] == unc8:
normp = sep * 8 + normp[8:]
offset = 6
elif normp[:4] == unc4:
offset = 4
else:
offset = 0
if (normp[offset:offset + 2] == unc2) and (normp[offset + 2:offset + 3] != sep):
# is a UNC path:
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
# \\machine\mountpoint\directory\etc\...
# directory ^^^^^^^^^^^^^^^
index = normp.find(sep, 2)
index = normp.find(sep,offset +2)
if index == -1:
return p[:0], p
index2 = normp.find(sep, index + 1)
Expand All@@ -167,8 +180,8 @@ def splitdrive(p):
if index2 == -1:
index2 = len(p)
return p[:index2], p[index2:]
if normp[1:2] == colon:
return p[:2], p[2:]
if normp[offset + 1:offset +2] == colon:
return p[:offset +2], p[offset +2:]
return p[:0], p


Expand Down
53 changes: 4 additions & 49 deletionsLib/pathlib.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -120,9 +120,6 @@ class _WindowsFlavour(_Flavour):

is_supported = (os.name == 'nt')

drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
ext_namespace_prefix = '\\\\?\\'

reserved_names = (
{'CON', 'PRN', 'AUX', 'NUL', 'CONIN$', 'CONOUT$'} |
{'COM%s' % c for c in '123456789\xb9\xb2\xb3'} |
Expand All@@ -145,43 +142,11 @@ class _WindowsFlavour(_Flavour):
# even with the '\\?\' prefix.

def splitroot(self, part, sep=sep):
first = part[0:1]
second = part[1:2]
if (second == sep and first == sep):
# XXX extended paths should also disable the collapsing of "."
# components (according to MSDN docs).
prefix, part = self._split_extended_path(part)
first = part[0:1]
second = part[1:2]
drv, rest = self.pathmod.splitdrive(part)
if drv[:1] == sep or rest[:1] == sep:
return drv, sep, rest.lstrip(sep)
else:
prefix = ''
third = part[2:3]
if (second == sep and first == sep and third != sep):
# is a UNC path:
# vvvvvvvvvvvvvvvvvvvvv root
# \\machine\mountpoint\directory\etc\...
# directory ^^^^^^^^^^^^^^
index = part.find(sep, 2)
if index != -1:
index2 = part.find(sep, index + 1)
# a UNC path can't have two slashes in a row
# (after the initial two)
if index2 != index + 1:
if index2 == -1:
index2 = len(part)
if prefix:
return prefix + part[1:index2], sep, part[index2+1:]
else:
return part[:index2], sep, part[index2+1:]
drv = root = ''
if second == ':' and first in self.drive_letters:
drv = part[:2]
part = part[2:]
first = third
if first == sep:
root = first
part = part.lstrip(sep)
return prefix + drv, root, part
return drv, '', rest

def casefold(self, s):
return s.lower()
Expand All@@ -192,16 +157,6 @@ def casefold_parts(self, parts):
def compile_pattern(self, pattern):
return re.compile(fnmatch.translate(pattern), re.IGNORECASE).fullmatch

def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
prefix = ''
if s.startswith(ext_prefix):
prefix = s[:4]
s = s[4:]
if s.startswith('UNC\\'):
prefix += s[:3]
s = '\\' + s[3:]
return prefix, s

def is_reserved(self, parts):
# NOTE: the rules for reserved names seem somewhat complicated
# (e.g. r"..\NUL" is reserved but not r"foo\NUL" if "foo" does not
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp