Python Forum

Full Version: Converting query string as a condition for filter data.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I make a project where user gives a query string for example " ( (ip.src==10.74.45.110 && ip.dst==239.255.255.255) || ip.proto == 17 ) && eth.addr==6c:dd:30:d6:45:f1)"
where all eth.addr, ip.src, ip.dst and ip.proto are field names, and I want to extract all those packets which satisfy above conditions.
But I'm not sure how to write parser for this, is python have any such split function which can do this?
my data structure looks like
 {packet_number_1,{'field_name1': value 1, 'field_name2': value 2},
  packet_number_2,{'field_name1': value 1, 'field_name2': value 2}
  packet_number_3,{'field_name1': value 1, 'field_name2': value 2}
  packet_number_4,{'field_name1': value 1, 'field_name2': value 2}
  packet_number_5,{'field_name1': value 1, 'field_name2': value 2}
  packet_number_6,{'field_name1': value 1, 'field_name2': value 2}} 
This is not valid Python data structure. It's set and sets can't have non-hashable dictionaries as elements (not to mention smaller issues as missing commas and names which consist spaces).

Building of filter is usually not that hard but for any possible help one needs to provide valid data structure, query data and expected result.