MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / normpath

Function normpath

tools/python-3.11.9-amd64/Lib/ntpath.py:496–535  ·  view source on GitHub ↗

Normalize path, eliminating double slashes, etc.

(path)

Source from the content-addressed store, hash-verified

494
495except ImportError:
496 def normpath(path):
497 """Normalize path, eliminating double slashes, etc."""
498 path = os.fspath(path)
499 if isinstance(path, bytes):
500 sep = b'\\'
501 altsep = b'/'
502 curdir = b'.'
503 pardir = b'..'
504 else:
505 sep = '\\'
506 altsep = '/'
507 curdir = '.'
508 pardir = '..'
509 path = path.replace(altsep, sep)
510 prefix, path = splitdrive(path)
511
512 # collapse initial backslashes
513 if path.startswith(sep):
514 prefix += sep
515 path = path.lstrip(sep)
516
517 comps = path.split(sep)
518 i = 0
519 while i < len(comps):
520 if not comps[i] or comps[i] == curdir:
521 del comps[i]
522 elif comps[i] == pardir:
523 if i > 0 and comps[i-1] != pardir:
524 del comps[i-1:i+1]
525 i -= 1
526 elif i == 0 and prefix.endswith(sep):
527 del comps[i]
528 else:
529 i += 1
530 else:
531 i += 1
532 # If the path is now empty, substitute '.'
533 if not prefix and not comps:
534 comps.append(curdir)
535 return prefix + sep.join(comps)
536
537else:
538 def normpath(path):

Callers 5

_abspath_fallbackFunction · 0.70
abspathFunction · 0.70
_readlink_deepFunction · 0.70
realpathFunction · 0.70
relpathFunction · 0.70

Calls 8

startswithMethod · 0.80
lstripMethod · 0.80
endswithMethod · 0.80
splitdriveFunction · 0.70
replaceMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected