Skip to content

Instantly share code, notes, and snippets.

@dlenski
Last active January 29, 2016 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlenski/cbd36d42e5dce3e0ba0d to your computer and use it in GitHub Desktop.
Save dlenski/cbd36d42e5dce3e0ba0d to your computer and use it in GitHub Desktop.
Filter raw protocol messages from Pidgin debug log (`pidgin -d`)
#/usr/bin/env python2
from __future__ import print_function
from sys import stdin, stderr, stdout
import re
message = []
message_started = message_ended = None
for line in stdin:
m = re.match(r'MESSAGE (START|END) (.+)$', line)
if m:
if not message_started and m.group(1)=='START':
stderr.write(line)
message_started = m.group(2)
elif message_started==m.group(2) and m.group(1)=='END':
stderr.write(line)
message_ended = True
else:
raise RuntimeError, "Unexpected line %s while in message %s" % (line, message_started)
if message_started:
message.append(line)
if message_ended:
stdout.writelines(message)
stdout.write('----------------------------------------\n')
message = []
message_started = message_ended = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment