Confining the change to just py3
@@ -23,6 +23,7 @@ from __future__ import absolute_import
import random
import zlib
from collections import namedtuple
+import six
import crcmod.predefined
@@ -122,16 +123,16 @@ def compute_checksum(checksum_type, args, csum=0):
return None
elif checksum_type == ChecksumType.crc32:
for arg in args:
- if isinstance(arg, str):
- arg = arg.encode('utf8')
+ if six.PY3 and isinstance(arg, str):
+ arg = arg.encode('utf8', errors='surrogateescape')
csum = zlib.crc32(arg, csum) & 0xffffffff
# TODO figure out farm32 cross platform issue
elif checksum_type == ChecksumType.farm32:
raise NotImplementedError()
elif checksum_type == ChecksumType.crc32c:
for arg in args:
- if isinstance(arg, str):
- arg = arg.encode('utf8', errors='')
+ if six.PY3 and isinstance(arg, str):
+ arg = arg.encode('utf8', errors='surrogateescape')
csum = crc32c(arg, csum)
else:
raise InvalidChecksumError()
