def filter(self, func, cascade=True, **vars) -> 'PacketFilter': """ Create a new PacketFilter based on this packet filter with given filter func :param func: a callable that returns a bool (e.x. lambda p: xxx) or a filter string :param cascade: True if calling next in the new filter will also set index for this filter, False otherwise :param vars: variables for filter string :return: a new PacketFilter """ print('\n>>> filtering in range %s~%s%s:' % (self._index, self._stop_index, "<end>" if self._stop_index == len(self._pkts) else "<stop>"), file=sys.stderr) func = make_filter_func(func, **vars) self._check_type_ok() return PacketFilter(self._pkts, self._index, self._stop_index, filter_func=lambda p: self._filter_func(p) and func(p), parent=self if cascade else None)
def verify(self, func: Union[str, Callable], **vars) -> bool: print("\n>>> verifying packet:", file=sys.stderr, flush=False) func = make_filter_func(func, **vars) ok = func(self) print("\t=> %s" % ok, file=sys.stderr) return ok