Skip to content
Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Update pathlib.py
  • Loading branch information
AlbinaGiliazova authored Aug 10, 2018
commit 4a5d84d9279b4d783e93c9c91640a3091cfa79fd
16 changes: 9 additions & 7 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def splitroot(self, part, sep=sep):
prefix = ''
third = part[2:3]
if (second == sep and first == sep and third != sep):
# is a UNC path:
# is a UNC and/or Global path:
# vvvvvvvvvvvvvvvvvvvvv root
# \\machine\mountpoint\directory\etc\...
# directory ^^^^^^^^^^^^^^
Expand All @@ -164,10 +164,11 @@ def splitroot(self, part, sep=sep):
drv = part[:2]
part = part[2:]
first = third
# Except for "UNC" and "Global" paths, the drive should be
# Except for UNC and Global paths, the drive should be
# the first component after the local-device prefix.
# See https://bugs.python.org/issue33898
elif part != sep and prefix and 'UNC' not in prefix and 'Global' not in prefix:
# All UNC and some of Global paths are parsed in if-condition above.
elif part != sep and prefix and 'global' not in self.casefold(prefix):
index = part.find(sep)
if index != -1:
drv = part[:index]
Expand All @@ -183,6 +184,7 @@ def splitroot(self, part, sep=sep):
return prefix + drv, root, part

def casefold(self, s):
# .lower() is not recommended. See https://bugs.python.org/issue32612
return s.lower()

def casefold_parts(self, parts):
Expand Down Expand Up @@ -223,20 +225,20 @@ def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
# Do not assume case sensitivity.
# See https://docs.microsoft.com/ru-ru/windows/desktop/FileIO/naming-a-file
Comment thread
zooba marked this conversation as resolved.
Outdated
# But .lower() is not recommended. See https://bugs.python.org/issue32612
s1 = s[:index]
if s1 == 'Global' or s1 == 'GLOBAL':
s1 = self.casefold(s[:index])
if s1 == 'global':
Comment thread
zooba marked this conversation as resolved.
Outdated
prefix += s[:6]
# For example, Path('//?/Global/Z:/').drive
Comment thread
zooba marked this conversation as resolved.
Outdated
if s[8:9] == ':':
prefix += s[6:7]
s = s[7:]
# For example, r'\\?\Global\UNC\server\share'
Comment thread
zooba marked this conversation as resolved.
Outdated
elif s[7:10] == 'UNC':
elif self.casefold(s[7:11]) == 'unc\\':
prefix += s[6:10]
s = '\\' + s[10:]
else:
s = '\\' + s[6:]
if s1 == 'UNC':
if s1 == 'unc':
Comment thread
zooba marked this conversation as resolved.
Outdated
prefix += s[:3]
s = '\\' + s[3:]
return prefix, s
Expand Down