diff options
Diffstat (limited to 'magic.py')
-rw-r--r-- | magic.py | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -193,14 +193,15 @@ def coerce_filename(filename): return None # ctypes will implicitly convert unicode strings to bytes with - # .encode('ascii'). A more useful default here is - # getfilesystemencoding(). We need to leave byte-str unchanged. + # .encode('ascii'). If you use the filesystem encoding + # then you'll get inconsistent behavior (crashes) depending on the user's + # LANG environment variable is_unicode = (sys.version_info[0] <= 2 and isinstance(filename, unicode)) or \ (sys.version_info[0] >= 3 and isinstance(filename, str)) if is_unicode: - return filename.encode(sys.getfilesystemencoding()) + return filename.encode('utf-8') else: return filename |