simplify some code
use native str type for attribute lookup to reduce Py2 overhead
clean up some test code
fix and test compressed plain text serialisation to file-like objects