MCPcopy Create free account
hub / github.com/twisted/twisted / segmentsFrom

Method segmentsFrom

src/twisted/python/filepath.py:542–570  ·  view source on GitHub ↗

Return a list of segments between a child and its ancestor. For example, in the case of a path X representing /a/b/c/d and a path Y representing /a/b, C{Y.segmentsFrom(X)} will return C{['c', 'd']}. @param ancestor: an instance of the same class as self, os

(self: _Self, ancestor: _Self)

Source from the content-addressed store, hash-verified

540 return path
541
542 def segmentsFrom(self: _Self, ancestor: _Self) -> list[AnyStr]:
543 """
544 Return a list of segments between a child and its ancestor.
545
546 For example, in the case of a path X representing /a/b/c/d and a path Y
547 representing /a/b, C{Y.segmentsFrom(X)} will return C{['c',
548 'd']}.
549
550 @param ancestor: an instance of the same class as self, ostensibly an
551 ancestor of self.
552
553 @raise ValueError: If the C{ancestor} parameter is not actually an
554 ancestor, i.e. a path for /x/y/z is passed as an ancestor for /a/b/c/d.
555
556 @return: a list of strs
557 """
558 # this might be an unnecessarily inefficient implementation but it will
559 # work on win32 and for zipfiles; later I will deterimine if the
560 # obvious fast implemenation does the right thing too
561 f = self
562 p: _Self = f.parent() # type:ignore[assignment]
563 segments: list[AnyStr] = []
564 while f != ancestor and p != f:
565 segments[0:0] = [f.basename()]
566 f = p
567 p = p.parent() # type:ignore[assignment]
568 if f == ancestor and segments:
569 return segments
570 raise ValueError(f"{ancestor!r} not parent of {self!r}")
571
572 # new in 8.0
573 def __hash__(self) -> int:

Callers 4

mapPathMethod · 0.80
listMethod · 0.80
fix-for-src-mv.pyFile · 0.80

Calls 2

parentMethod · 0.45
basenameMethod · 0.45

Tested by 1