Skip to content

Commit a5cfbf2

Browse files
committed
Split pull request
1 parent 3c4c3d2 commit a5cfbf2

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

Lib/ntpath.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -554,49 +554,37 @@ def normpath(path):
554554
return prefix + sep.join(comps)
555555

556556

557+
def _abspath_fallback(path):
558+
"""Return the absolute version of a path as a fallback function in case
559+
`nt._getfullpathname` is not available or raises OSError. See bpo-31047 for
560+
more.
561+
562+
"""
563+
564+
path = os.fspath(path)
565+
if not isabs(path):
566+
if isinstance(path, bytes):
567+
cwd = os.getcwdb()
568+
else:
569+
cwd = os.getcwd()
570+
path = join(cwd, path)
571+
return normpath(path)
572+
557573
# Return an absolute path.
558574
try:
559575
from nt import _path_normpath_ex as _normpath
560576
from nt import _getfullpathname
561577

562578
except ImportError: # not running on Windows - mock up something sensible
563-
def abspath(path):
564-
"""Return the absolute version of a path."""
565-
path = os.fspath(path)
566-
if not isabs(path):
567-
if isinstance(path, bytes):
568-
cwd = os.getcwdb()
569-
else:
570-
cwd = os.getcwd()
571-
path = join(cwd, path)
572-
return normpath(path)
579+
abspath = _abspath_fallback
573580

574581
else: # use native Windows method on Windows
575582
def abspath(path):
576583
"""Return the absolute version of a path."""
577584
try:
578585
return _getfullpathname(_normpath(path, explicit_curdir=True))
579586
except (OSError, ValueError):
580-
# See gh-75230, handle outside for cleaner traceback
581-
pass
582-
path = os.fspath(path)
583-
if not isabs(path):
584-
if isinstance(path, bytes):
585-
sep = b'/'
586-
cwd = os.getcwdb()
587-
else:
588-
sep = '/'
589-
cwd = os.getcwd()
590-
drive, root, path = splitroot(path)
591-
if drive and drive != splitroot(cwd)[0]:
592-
try:
593-
path = join(_getfullpathname(drive), path)
594-
except (OSError, ValueError):
595-
# Invalid drive \x00: on Windows; assume root directory
596-
path = drive + sep + path
597-
else:
598-
path = join(cwd, root + path)
599-
return normpath(path)
587+
return _abspath_fallback(path)
600588

601589
try:
602590
from nt import _findfirstfile, _getfinalpathname, readlink as _nt_readlink

Lib/test/test_ntpath.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,6 @@ def test_abspath(self):
808808
tester('ntpath.abspath("C:\\spam. . .")', "C:\\spam")
809809
tester('ntpath.abspath("C:/nul")', "\\\\.\\nul")
810810
tester('ntpath.abspath("C:\\nul")', "\\\\.\\nul")
811-
self.assertTrue(ntpath.isabs(ntpath.abspath("C:spam")))
812-
self.assertTrue(ntpath.isabs(ntpath.abspath("C:\x00")))
813-
self.assertTrue(ntpath.isabs(ntpath.abspath("\x00:spam")))
814811
tester('ntpath.abspath("//..")', "\\\\")
815812
tester('ntpath.abspath("//../")', "\\\\..\\")
816813
tester('ntpath.abspath("//../..")', "\\\\..\\")

0 commit comments

Comments
 (0)