Parcourir la source

trying to fix wrong encoding in windows python3

prozessorkern il y a 4 ans
Parent
commit
2c15b9e4be
1 fichiers modifiés avec 3 ajouts et 1 suppressions
  1. 3 1
      metrixpp/ext/std/tools/collect.py

+ 3 - 1
metrixpp/ext/std/tools/collect.py

@@ -144,8 +144,10 @@ class DirectoryReader():
                         f = open(full_path, 'rU');
                         text = f.read();
                         # getting along with the different string handling of python 2 and 3
-                        if sys.version_info[0] < 3:
+                        try:
                             text = text.decode('utf-8')
+                        except (UnicodeDecodeError, AttributeError):
+                            pass
                         f.close()
                         checksum = binascii.crc32(text.encode('utf8')) & 0xffffffff # to match python 3