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

Function _ancestry

Lib/zipfile/_path/__init__.py:45–69  ·  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

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

Callers 1

_parentsFunction · 0.85

Calls 2

rstripMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…