python: improved packet decoding