I don't understand this.  If `unicode` is passed in we end up with `bytes` after this.  If `bytes` is passed in, we end up with `unicode` after this.  In one case of the other, `write(msg)` will fail below, right?

I think the sane thing to do here is to behave like Python 3 and *require* that unicode is passed into this function (since if it's bytes, we can't assume the encoding -- `utf-8` is probably the safest assumption, but it can't always be assumed).  That punts the issue of what encoding the byte string is to higher level code that might actually stand a chance of knowing.