commit:     213335d85286cd7a188d9f83b59ce0d6c2da7146
Author:     Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org>
AuthorDate: Mon Aug  4 12:11:24 2014 +0000
Commit:     Arfrever Frehtes Taifersar Arahesis <arfrever <AT> apache <DOT> org>
CommitDate: Mon Aug  4 12:11:24 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=213335d8

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)"

---
 bin/chpathtool.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

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 @@ class IsTextFile(object):
                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):

Reply via email to