Fix saving kernel history in Python 2

Supersedes & closes #4582.

Doing `%hist -f foo` from any of the two process frontends is currently broken on Python 2 because it expects to write unicode, but the raw history is stored as byte strings. This decodes the code at the `ipkernel` level, before it gets handled by any of the IPython internals.