Преглед на файлове

added decoding depending on the python version in use to fix utf-8 problems on python2

prozessorkern преди 4 години
родител
ревизия
1ddb006bd9
променени са 3 файла, в които са добавени 9 реда и са изтрити 4 реда
  1. 5 1
      ext/std/tools/collect.py
  2. 3 2
      mpp/internal/api_impl.py
  3. 1 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:

Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
tests/general/test_std_code_cpp/sources/test.c