Fix issue #765 with non ascii characters in user-data

Read in the file:// contents as text, which is decoded via
locale.getpreferredencoding().

This introduces a py2/py3 compat_open so that you can open
a file with a encoding argument (not availble in py2's open()).