I got to start a new django 1.8-project in python 3.4 for once, and happily coded away. Turns out, the PaaS it needs to run on has a broken python 3.4, so... my code now needs to work in 2.7.8.
Everything works in both versions except I need to read from an uploaded file, bot in the web and from the commandline. In the management command I can do:
import io
with io.open(fieldname, 'rt', encoding='UTF-8') as F: do_stuff(F)
... and it works in both 2.7.8 and 3.4.x.
But a FileField in Python 3 reads stuff as bytes. So in the form, I need to check whether the chunk of data I get is bytes, and if it is, convert it to unicode from 'UTF-8'.
How to do that? It'll probably involve six in some way but the docs for six, and django's "how to have things run on both python 2 and 3"-docs, could be better.