@@ -496,38 +496,36 @@ def normpath(path): |
|
|
496 |
496 |
comps.append(curdir) |
497 |
497 |
return prefix + sep.join(comps) |
498 |
498 |
|
|
499 |
+def _abspath_fallback(path): |
|
500 |
+"""Return the absolute version of a path as a fallback function in case |
|
501 |
+ `nt._getfullpathname` is not available or raises OSError. See bpo-31047 for |
|
502 |
+ more. |
|
503 |
+ |
|
504 |
+ """ |
|
505 |
+ |
|
506 |
+path = os.fspath(path) |
|
507 |
+if not isabs(path): |
|
508 |
+if isinstance(path, bytes): |
|
509 |
+cwd = os.getcwdb() |
|
510 |
+else: |
|
511 |
+cwd = os.getcwd() |
|
512 |
+path = join(cwd, path) |
|
513 |
+return normpath(path) |
499 |
514 |
|
500 |
515 |
# Return an absolute path. |
501 |
516 |
try: |
502 |
517 |
from nt import _getfullpathname |
503 |
518 |
|
504 |
519 |
except ImportError: # not running on Windows - mock up something sensible |
505 |
|
-def abspath(path): |
506 |
|
-"""Return the absolute version of a path.""" |
507 |
|
-path = os.fspath(path) |
508 |
|
-if not isabs(path): |
509 |
|
-if isinstance(path, bytes): |
510 |
|
-cwd = os.getcwdb() |
511 |
|
-else: |
512 |
|
-cwd = os.getcwd() |
513 |
|
-path = join(cwd, path) |
514 |
|
-return normpath(path) |
|
520 |
+abspath = _abspath_fallback |
515 |
521 |
|
516 |
522 |
else: # use native Windows method on Windows |
517 |
523 |
def abspath(path): |
518 |
524 |
"""Return the absolute version of a path.""" |
519 |
|
- |
520 |
|
-if path: # Empty path must return current working directory. |
521 |
|
-path = os.fspath(path) |
522 |
|
-try: |
523 |
|
-path = _getfullpathname(path) |
524 |
|
-except OSError: |
525 |
|
-pass # Bad path - return unchanged. |
526 |
|
-elif isinstance(path, bytes): |
527 |
|
-path = os.getcwdb() |
528 |
|
-else: |
529 |
|
-path = os.getcwd() |
530 |
|
-return normpath(path) |
|
525 |
+try: |
|
526 |
+return _getfullpathname(path) |
|
527 |
+except OSError: |
|
528 |
+return _abspath_fallback(path) |
531 |
529 |
|
532 |
530 |
# realpath is a no-op on systems without islink support |
533 |
531 |
realpath = abspath |