def fix_parsed(m):
 if (m is None):
  return {'type': 'raw', 'data': []}
 if isinstance(m, basestring):
  return {'type': 'raw', 'data': [ord(b) for b in m]}
 assert isinstance(m, packet_base)
 if (not m.parsed):
  u = fix_parsed(m.raw)
  u['unparsed_type'] = m.__class__.__name__
  return u
 r = {}
 for (k, v) in fields_of(m, primitives_only=False).iteritems():
  if is_scalar(v):
   r[k] = v
  elif isinstance(v, (IPAddr, EthAddr)):
   r[k] = str(v)
 if hasattr(m, 'payload'):
  r['payload'] = fix_parsed(m.payload)
 if ('raw' in r):
  del r['raw']
 if ('next' in r):
  del r['next']
 r['type'] = m.__class__.__name__
 return r

def fix_parsed ( m ) : if ( m is None ) : return { 'type' : 'raw' , 'data' : [ ] } if isinstance ( m , basestring ) : return { 'type' : 'raw' , 'data' : [ ord ( b ) for b in m ] } assert isinstance ( m , packet_base ) if ( not m . parsed ) : u = fix_parsed ( m . raw ) u [ 'unparsed_type' ] = m . __class__ . __name__ return u r = { } for ( k , v ) in fields_of ( m , primitives_only = False ) . iteritems ( ) : if is_scalar ( v ) : r [ k ] = v elif isinstance ( v , ( IPAddr , EthAddr ) ) : r [ k ] = str ( v ) if hasattr ( m , 'payload' ) : r [ 'payload' ] = fix_parsed ( m . payload ) if ( 'raw' in r ) : del r [ 'raw' ] if ( 'next' in r ) : del r [ 'next' ] r [ 'type' ] = m . __class__ . __name__ return r
translate parsed packet data to dicts and stuff .