Просмотр исходного кода

Merge pull request #18 from metrixplusplus/bugfix/#16-unicode-decode-error

trying to fix utf-8 decoding problems in python2
Andrey 4 лет назад
Родитель
Сommit
86b58a1117
3 измененных файлов с 366 добавлено и 4 удалено
  1. 5 1
      ext/std/tools/collect.py
  2. 3 2
      mpp/internal/api_impl.py
  3. 358 1
      tests/general/test_std_code_cpp/sources/test.c

+ 5 - 1
ext/std/tools/collect.py

@@ -10,6 +10,7 @@ import mpp.api
 
 import re
 import os
+import sys
 import logging
 import time
 import binascii
@@ -142,11 +143,14 @@ class DirectoryReader():
                         ts = time.time()
                         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:
+                            text = text.decode('utf-8')
                         f.close()
                         checksum = binascii.crc32(text.encode('utf8')) & 0xffffffff # to match python 3
                         
                         db_loader = plugin.get_plugin('mpp.dbf').get_loader()
-                        (data, is_updated) = db_loader.create_file_data(norm_path, checksum, str(text))
+                        (data, is_updated) = db_loader.create_file_data(norm_path, checksum, text)
                         procerrors = parser.process(plugin, data, is_updated)
                         if plugin.is_proctime_enabled == True:
                             data.set_data('std.general', 'proctime',

+ 3 - 2
mpp/internal/api_impl.py

@@ -111,9 +111,10 @@ class PackagerFactory(object):
 
     class StringPackager(IPackager):
         def pack(self, unpacked_data):
-            if not isinstance(unpacked_data, str):
+            try:
+                return str(unpacked_data)
+            except ValueError:
                 raise PackagerError()
-            return str(unpacked_data)
             
         def unpack(self, packed_data): 
             try:

Разница между файлами не показана из-за своего большого размера
+ 358 - 1
tests/general/test_std_code_cpp/sources/test.c