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

Function normpath

Lib/posixpath.py:345–371  ·  view source on GitHub ↗

Normalize path, eliminating double slashes, etc.

(path)

Source from the content-addressed store, hash-verified

343
344except ImportError:
345 def normpath(path):
346 """Normalize path, eliminating double slashes, etc."""
347 path = os.fspath(path)
348 if isinstance(path, bytes):
349 sep = b'/'
350 dot = b'.'
351 dotdot = b'..'
352 else:
353 sep = '/'
354 dot = '.'
355 dotdot = '..'
356 if not path:
357 return dot
358 _, initial_slashes, path = splitroot(path)
359 comps = path.split(sep)
360 new_comps = []
361 for comp in comps:
362 if not comp or comp == dot:
363 continue
364 if (comp != dotdot or (not initial_slashes and not new_comps) or
365 (new_comps and new_comps[-1] == dotdot)):
366 new_comps.append(comp)
367 elif new_comps:
368 new_comps.pop()
369 comps = new_comps
370 path = initial_slashes + sep.join(comps)
371 return path or dot
372
373
374def abspath(path):

Callers 1

abspathFunction · 0.90

Calls 5

splitrootFunction · 0.90
splitMethod · 0.45
appendMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…