Use nt._getfullpathname instead of os.path.abspath

This commit is contained in:
Tzu-ping Chung 2020-07-19 22:33:38 +08:00
parent d20ab7b4f2
commit 42fd0b0772
1 changed files with 4 additions and 3 deletions

View File

@ -15,7 +15,7 @@ from urllib.parse import quote_from_bytes as urlquote_from_bytes
if os.name == 'nt': if os.name == 'nt':
import nt import nt
from nt import _getfinalpathname from nt import _getfinalpathname, _getfullpathname
else: else:
nt = None nt = None
@ -191,7 +191,7 @@ class _WindowsFlavour(_Flavour):
return os.getcwd() return os.getcwd()
if strict: if strict:
return self._ext_to_normal(_getfinalpathname(s)) return self._ext_to_normal(_getfinalpathname(s))
s = path = os.path.abspath(s) s = path = _getfullpathname(s)
previous_s = None previous_s = None
tail_parts = [] # End of the path after the first one not found tail_parts = [] # End of the path after the first one not found
while True: while True:
@ -201,7 +201,8 @@ class _WindowsFlavour(_Flavour):
previous_s = s previous_s = s
s, tail = os.path.split(s) s, tail = os.path.split(s)
tail_parts.append(tail) tail_parts.append(tail)
if previous_s == s: # Root reached, fallback to abspath() if previous_s == s:
# Root reached, fallback to _getfullpathname()
return path return path
else: else:
return os.path.join(s, *reversed(tail_parts)) return os.path.join(s, *reversed(tail_parts))