diff options
author | Christos Zoulas <christos@zoulas.com> | 2016-02-02 19:05:12 +0000 |
---|---|---|
committer | Christos Zoulas <christos@zoulas.com> | 2016-02-02 19:05:12 +0000 |
commit | 5560418ebc6f94e80953c8646383fdb70758fc7a (patch) | |
tree | 2182380c0fae3799aadfb91ba0dd505515855e9c /python | |
parent | e3f9082f8b64dd0a3f7c99c88bfcdac18ad7cb9a (diff) | |
download | file-git-5560418ebc6f94e80953c8646383fdb70758fc7a.tar.gz |
PR/511: Orestis: Restore python-2 compatibility.
Diffstat (limited to 'python')
-rw-r--r-- | python/magic.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/python/magic.py b/python/magic.py index 8cff29a9..c48f7d5a 100644 --- a/python/magic.py +++ b/python/magic.py @@ -126,12 +126,15 @@ class Magic(object): if isinstance(filename, bytes): bi = filename else: - bi = bytes(filename, 'utf-8') + try: # keep Python 2 compatibility + bi = bytes(filename, 'utf-8') + except TypeError: + bi = bytes(filename) r = _file(self._magic_t, bi) if isinstance(r, str): return r else: - return str(r, 'utf-8') + return str(r).encode('utf-8') def descriptor(self, fd): """ @@ -149,7 +152,7 @@ class Magic(object): if isinstance(r, str): return r else: - return str(r, 'utf-8') + return str(r).encode('utf-8') def error(self): """ @@ -160,7 +163,7 @@ class Magic(object): if isinstance(e, str): return e else: - return str(e, 'utf-8') + return str(e).encode('utf-8') def setflags(self, flags): """ |