Add Python 3 support

Under Python 3, `sys.stdout.write()` doesn't accept bytes so we need to
give it a unicode string.

`transform()` returned its result encoded in the part's original
encoding, which didn't make much sense so I've removed that part to keep
the result in a unicode string.

I've tested the result with both Python 2 and 3 on a utf8 source file
containing non-ascii characters. Works fine.

Results are a bit fuzzier with source encoding that aren't utf-8, but
that problem was already present before this change.