MCPcopy Index your code
hub / github.com/python/cpython / _getfinalpathname_nonstrict

Function _getfinalpathname_nonstrict

Lib/ntpath.py:605–659  ·  view source on GitHub ↗
(path, ignored_error=OSError)

Source from the content-addressed store, hash-verified

603 return path
604
605 def _getfinalpathname_nonstrict(path, ignored_error=OSError):
606 # These error codes indicate that we should stop resolving the path
607 # and return the value we currently have.
608 # 1: ERROR_INVALID_FUNCTION
609 # 2: ERROR_FILE_NOT_FOUND
610 # 3: ERROR_DIRECTORY_NOT_FOUND
611 # 5: ERROR_ACCESS_DENIED
612 # 21: ERROR_NOT_READY (implies drive with no media)
613 # 32: ERROR_SHARING_VIOLATION (probably an NTFS paging file)
614 # 50: ERROR_NOT_SUPPORTED
615 # 53: ERROR_BAD_NETPATH
616 # 65: ERROR_NETWORK_ACCESS_DENIED
617 # 67: ERROR_BAD_NET_NAME (implies remote server unavailable)
618 # 87: ERROR_INVALID_PARAMETER
619 # 123: ERROR_INVALID_NAME
620 # 161: ERROR_BAD_PATHNAME
621 # 1005: ERROR_UNRECOGNIZED_VOLUME
622 # 1920: ERROR_CANT_ACCESS_FILE
623 # 1921: ERROR_CANT_RESOLVE_FILENAME (implies unfollowable symlink)
624 allowed_winerror = 1, 2, 3, 5, 21, 32, 50, 53, 65, 67, 87, 123, 161, 1005, 1920, 1921
625
626 # Non-strict algorithm is to find as much of the target directory
627 # as we can and join the rest.
628 tail = path[:0]
629 while path:
630 try:
631 path = _getfinalpathname(path)
632 return join(path, tail) if tail else path
633 except ignored_error as ex:
634 if ex.winerror not in allowed_winerror:
635 raise
636 try:
637 # The OS could not resolve this path fully, so we attempt
638 # to follow the link ourselves. If we succeed, join the tail
639 # and return.
640 new_path = _readlink_deep(path,
641 ignored_error=ignored_error)
642 if new_path != path:
643 return join(new_path, tail) if tail else new_path
644 except ignored_error:
645 # If we fail to readlink(), let's keep traversing
646 pass
647 # If we get these errors, try to get the real name of the file without accessing it.
648 if ex.winerror in (1, 5, 32, 50, 87, 1920, 1921):
649 try:
650 name = _findfirstfile(path)
651 path, _ = split(path)
652 except ignored_error:
653 path, name = split(path)
654 else:
655 path, name = split(path)
656 if path and not name:
657 return path + tail
658 tail = join(name, tail) if tail else name
659 return tail
660
661 def realpath(path, /, *, strict=False):
662 path = normpath(path)

Callers 1

realpathFunction · 0.85

Calls 3

_readlink_deepFunction · 0.85
joinFunction · 0.70
splitFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…