MCPcopy Index your code
hub / github.com/RustPython/RustPython / _ancestry

Function _ancestry

Lib/zipfile/_path/__init__.py:44–68  ·  view source on GitHub ↗

Given a path with elements separated by posixpath.sep, generate all elements of that path. >>> list(_ancestry('b/d')) ['b/d', 'b'] >>> list(_ancestry('/b/d/')) ['/b/d', '/b'] >>> list(_ancestry('b/d/f/')) ['b/d/f', 'b/d', 'b'] >>> list(_ancestry('b')) ['b']

(path)

Source from the content-addressed store, hash-verified

42
43
44def _ancestry(path):
45 """
46 Given a path with elements separated by
47 posixpath.sep, generate all elements of that path.
48
49 >>> list(_ancestry('b/d'))
50 ['b/d', 'b']
51 >>> list(_ancestry('/b/d/'))
52 ['/b/d', '/b']
53 >>> list(_ancestry('b/d/f/'))
54 ['b/d/f', 'b/d', 'b']
55 >>> list(_ancestry('b'))
56 ['b']
57 >>> list(_ancestry(''))
58 []
59
60 Multiple separators are treated like a single.
61
62 >>> list(_ancestry('//b//d///f//'))
63 ['//b//d///f', '//b//d', '//b']
64 """
65 path = path.rstrip(posixpath.sep)
66 while path.rstrip(posixpath.sep):
67 yield path
68 path, tail = posixpath.split(path)
69
70
71_dedupe = dict.fromkeys

Callers 1

_parentsFunction · 0.85

Calls 2

rstripMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected