Always open files in text mode and always use utf-8
Introduces a common.open_text() helper with saner defaults for opening
text files across Python versions.
open() defaults to the locale encoding which on a properly configured
Unix is utf-8, but cp-1252 on Windows which can't handle all of Unicode.
Instead of using the default always use utf-8 for text files.
To reduce the difference of types processed by Python 2 vs 3 use
codecs.open() to open text files in text mode on Python 2. The
resulting file object will return unicode like on Python 3, but still
allows passing in ASCII only str.
Also fixes a few missing file.close() operations, which is important on
Windows as non-closed files can't be renamed/deleted on Windows.
https://bugzilla.gnome.org/show_bug.cgi?id=787862