diff options
author | Adam Hupp <adam@hupp.org> | 2014-05-30 14:18:30 -0700 |
---|---|---|
committer | Adam Hupp <adam@hupp.org> | 2014-05-30 14:18:30 -0700 |
commit | 012f8a90501d314a694c136b73179af12b2f41e8 (patch) | |
tree | 87657d98e5c62398831974afd286bb356751ab0b | |
parent | 5c5036c96472eba1e5908e8b5527295d08aff106 (diff) | |
download | python-magic-012f8a90501d314a694c136b73179af12b2f41e8.tar.gz |
Always use utf-8 regardless of filesystem encoding
-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 |