Given a path with elements separated by posixpath.sep, generate all parents of that path. >>> list(_parents('b/d')) ['b'] >>> list(_parents('/b/d/')) ['/b'] >>> list(_parents('b/d/f/')) ['b/d', 'b'] >>> list(_parents('b')) [] >>> list(_parents('')) [
(path)
| 24 | |
| 25 | |
| 26 | def _parents(path): |
| 27 | """ |
| 28 | Given a path with elements separated by |
| 29 | posixpath.sep, generate all parents of that path. |
| 30 | |
| 31 | >>> list(_parents('b/d')) |
| 32 | ['b'] |
| 33 | >>> list(_parents('/b/d/')) |
| 34 | ['/b'] |
| 35 | >>> list(_parents('b/d/f/')) |
| 36 | ['b/d', 'b'] |
| 37 | >>> list(_parents('b')) |
| 38 | [] |
| 39 | >>> list(_parents('')) |
| 40 | [] |
| 41 | """ |
| 42 | return itertools.islice(_ancestry(path), 1, None) |
| 43 | |
| 44 | |
| 45 | def _ancestry(path): |