| 739 | |
| 740 | |
| 741 | class PacketList(_PacketList[Packet], |
| 742 | BasePacketList[Packet], |
| 743 | _CanvasDumpExtended): |
| 744 | def sr(self, multi=False, lookahead=None): |
| 745 | # type: (bool, Optional[int]) -> Tuple[SndRcvList, PacketList] |
| 746 | """ |
| 747 | Matches packets in the list |
| 748 | |
| 749 | :param multi: True if a packet can have multiple answers |
| 750 | :param lookahead: Maximum number of packets between packet and answer. |
| 751 | If 0 or None, full remaining list is |
| 752 | scanned for answers |
| 753 | :return: ( (matched couples), (unmatched packets) ) |
| 754 | """ |
| 755 | remain = self.res[:] |
| 756 | sr = [] # type: List[QueryAnswer] |
| 757 | i = 0 |
| 758 | if lookahead is None or lookahead == 0: |
| 759 | lookahead = len(remain) |
| 760 | while i < len(remain): |
| 761 | s = remain[i] |
| 762 | j = i |
| 763 | while j < min(lookahead + i, len(remain) - 1): |
| 764 | j += 1 |
| 765 | r = remain[j] |
| 766 | if r.answers(s): |
| 767 | sr.append(QueryAnswer(s, r)) |
| 768 | if multi: |
| 769 | remain[i]._answered = 1 |
| 770 | remain[j]._answered = 2 |
| 771 | continue |
| 772 | del remain[j] |
| 773 | del remain[i] |
| 774 | i -= 1 |
| 775 | break |
| 776 | i += 1 |
| 777 | if multi: |
| 778 | remain = [x for x in remain if not hasattr(x, "_answered")] |
| 779 | return SndRcvList(sr), PacketList(remain) |
| 780 | |
| 781 | |
| 782 | _PacketIterable = Union[ |
no outgoing calls
no test coverage detected