refactor stats handling for python 3

Centralize the stats encoding/decoding more and make it work for python
3. It looks like the marshal module output format changed between py2
and py3, so python 3 smiley can't read python 2 databases.

Change-Id: I5d4f9aefd402a927d2469bccf908441aab124c91