Properly handle bytes <-> str for Python 3