Revert incorrect commit 9351edad48523bb38b1bf651506786bdc8814f62, which broke file type detection
in chpathtool.py with Python 3 and magic module present.
>>> import magic
>>> m = magic.open(magic.MIME_TYPE)
>>> m.load()
0
>>> m.file(b"/etc/fstab")
'text/plain'
>>> m.file(str(b"/etc/fstab"))
"cannot open `b'/etc/fstab'' (No such file or directory)"
diff --git a/bin/chpathtool.py b/bin/chpathtool.py
index 6ddf329..6460662 100755
--- a/bin/chpathtool.py
+++ b/bin/chpathtool.py
@@ -51,12 +51,9 @@
return self._call(filename)
def _is_text_magic(self, filename):
- # regression in sys-apps/file causes
- # py 3.2 & 3.3 magic module to not handle bytes properly
- if isinstance(filename, bytes):
- mime_type = self._m.file(str(filename))
- else:
- mime_type = self._m.file(filename)
+ mime_type = self._m.file(filename)
+ if isinstance(mime_type, bytes):
+ mime_type = mime_type.decode('ascii', 'replace')
return mime_type.startswith('text/')
def _is_text_encoding(self, filename):