diff options
author | 2014-08-04 14:11:24 +0200 | |
---|---|---|
committer | 2014-08-04 14:11:24 +0200 | |
commit | 213335d85286cd7a188d9f83b59ce0d6c2da7146 (patch) | |
tree | 0734b93c7322ba0fbbf7c8bf237b575d1c400740 /bin | |
parent | pym/_emerge/depgrapgh.py: Fix bug 518968 (diff) | |
download | portage-213335d85286cd7a188d9f83b59ce0d6c2da7146.tar.gz portage-213335d85286cd7a188d9f83b59ce0d6c2da7146.tar.bz2 portage-213335d85286cd7a188d9f83b59ce0d6c2da7146.zip |
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)"
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/chpathtool.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/bin/chpathtool.py b/bin/chpathtool.py index 6ddf329e8..64606623a 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): |