@@ -554,49 +554,37 @@ def normpath(path):
554
554
return prefix + sep .join (comps )
555
555
556
556
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
+
557
573
# Return an absolute path.
558
574
try :
559
575
from nt import _path_normpath_ex as _normpath
560
576
from nt import _getfullpathname
561
577
562
578
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
573
580
574
581
else : # use native Windows method on Windows
575
582
def abspath (path ):
576
583
"""Return the absolute version of a path."""
577
584
try :
578
585
return _getfullpathname (_normpath (path , explicit_curdir = True ))
579
586
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 )
600
588
601
589
try :
602
590
from nt import _findfirstfile , _getfinalpathname , readlink as _nt_readlink
0 commit comments