Пример #1
0
    def compose(*args: "SequenceTransfer"):
        transfers = list(args)
        if len(transfers) < 1:
            raise SequenceTransferException(
                'compose require at least two transfers')

        first_transfer = transfers[0]
        last_transfer = transfers[-1]

        matches = []

        for i, (sequence, _) in enumerate(first_transfer.matches):
            tmp = sequence
            for f in transfers:
                tmp = f.apply(tmp)

            if i > 0 and matches[-1][1] == tmp:
                match = (Sequence.expand(matches[-1][0], sequence), tmp)
                matches.pop()
                matches.append(match)
            else:
                matches.append((sequence, tmp))

        return SequenceTransfer(first_transfer.source, last_transfer.target,
                                matches)
Пример #2
0
    def apply(self,
              source_sequence: Sequence,
              plugin: SequenceTransferPlugin = None) -> Sequence:
        """
        :param source_sequence: any sub-sequence of the source
        :param plugin: SequenceTransferPlugin instance
        :return: transferred sub-sequence in the target
        """

        if plugin is not None:
            return plugin.apply(self, source_sequence)

        source_sequence.raise_if_not_in(self._source)

        if source_sequence.size == 0 and source_sequence.start == self._source.start:
            return Sequence(
                self._index[0].start,
                self._index[0].start,
            )
        elif source_sequence.size == 0 and source_sequence.stop == self._source.stop:
            return Sequence(
                self._index[self._source.size - 1].stop,
                self._index[self._source.size - 1].stop,
            )
        else:
            return Sequence.expand(self._index[source_sequence.start],
                                   self._index[source_sequence.stop - 1])
Пример #3
0
    def apply(self, source_sequence: Sequence) -> Sequence:
        """
        :param source_sequence: any sub-sequence of the source
        :return: transferred sub-sequence in the target
        """
        source_sequence.raise_if_not_in(self._source)

        if source_sequence.size == 0 and source_sequence.start == self._source.start:
            return Sequence(
                self._index[0].start,
                self._index[0].start,
            )
        elif source_sequence.size == 0 and source_sequence.stop == self._source.stop:
            return Sequence(
                self._index[self._source.size - 1].stop,
                self._index[self._source.size - 1].stop,
            )
        else:
            return Sequence.expand(self._index[source_sequence.start],
                                   self._index[source_sequence.stop - 1])