Python: Replace ad-hoc API query with library equivalent
C: whitespace changes
C: teach save_to_pcap to handle API events

save_to_pcap can be long-running, so it needs to flush API events
such as L1 status changes. If these aren't flushed, we're at the
mercy of the OS TCP receive buffers. On Windows, they seem to be
quite short, about 400 events (128k?).