diff --git a/tools/count_api_without_core_ops.py b/tools/count_api_without_core_ops.py index 99e84074158ad7ddbdb91148b53cc3433f03f3f8..664b94a059f5c8adbe541615e5472b43ad256915 100644 --- a/tools/count_api_without_core_ops.py +++ b/tools/count_api_without_core_ops.py @@ -22,6 +22,7 @@ import pydoc import hashlib import six import functools +import platform __all__ = ['get_apis_with_and_without_core_ops', ] @@ -34,9 +35,20 @@ omitted_list = [ def md5(doc): - hash = hashlib.md5() - hash.update(str(doc).encode('utf-8')) - return hash.hexdigest() + try: + hashinst = hashlib.md5() + if platform.python_version()[0] == "2": + hashinst.update(str(doc)) + else: + hashinst.update(str(doc).encode('utf-8')) + md5sum = hashinst.hexdigest() + except UnicodeDecodeError as e: + md5sum = None + print( + "Error({}) occurred when `md5({})`, discard it.".format( + str(e), doc), + file=sys.stderr) + return md5sum def split_with_and_without_core_ops(member, cur_name): diff --git a/tools/print_signatures.py b/tools/print_signatures.py index cfe34fa342656d26d06cb425c71851ed0ffaf609..6de9d84379fea595aa7497f9d22ce66f0e9f0c6f 100644 --- a/tools/print_signatures.py +++ b/tools/print_signatures.py @@ -34,9 +34,21 @@ visited_modules = set() def md5(doc): - hash = hashlib.md5() - hash.update(str(doc).encode('utf-8')) - return hash.hexdigest() + try: + hashinst = hashlib.md5() + if platform.python_version()[0] == "2": + hashinst.update(str(doc)) + else: + hashinst.update(str(doc).encode('utf-8')) + md5sum = hashinst.hexdigest() + except UnicodeDecodeError as e: + md5sum = None + print( + "Error({}) occurred when `md5({})`, discard it.".format( + str(e), doc), + file=sys.stderr) + + return md5sum def get_functools_partial_spec(func):