commit:     9351edad48523bb38b1bf651506786bdc8814f62
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Aug  3 15:08:18 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Aug  3 15:19:25 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=9351edad

bin/chpathtool.py: fix py3.2 &py3.3 test failure

The magic module for those 2 python versions do not handle byte strings 
correctly.
forcing the filename to str() fixes it for all pythons tested.

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

diff --git a/bin/chpathtool.py b/bin/chpathtool.py
index 6460662..6ddf329 100755
--- a/bin/chpathtool.py
+++ b/bin/chpathtool.py
@@ -51,9 +51,12 @@ class IsTextFile(object):
                return self._call(filename)
 
        def _is_text_magic(self, filename):
-               mime_type = self._m.file(filename)
-               if isinstance(mime_type, bytes):
-                       mime_type = mime_type.decode('ascii', 'replace')
+               # 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)
                return mime_type.startswith('text/')
 
        def _is_text_encoding(self, filename):

Reply via email to