It’s fine to allow people to specify a Python expression per CLI, but a Python API should work with Python types.
The API should be changed so
read_pcap and read_har take kwargs instead of a dict of params
- filters are specified by passing calllbacks
E.g.:
reader.read_pcap('file.pcap', filter=lambda tcp: tcp.dst == '1.1.1.1')
This can easily be done:
from inspect import signature
...
def filter_packet(self, filter, eth, ip=None, tcp=None):
if not filter: return True
if isinstance(filter, str): return eval(filter)
if not callable(filter: raise TypeError('filter needs to be callable')
sig = signature(filter)
params = {
k: v
for k: v in dict(eth=eth, ip=ip, tcp=tcp).items()
if v is not None and k in sig.parameters
}
filter(**params)
It’s fine to allow people to specify a Python expression per CLI, but a Python API should work with Python types.
The API should be changed so
read_pcapandread_hartake kwargs instead of a dict of paramsE.g.:
This can easily be done: