diff --git a/moban/hashstore.py b/moban/hashstore.py index 17c9efd9..25b72518 100644 --- a/moban/hashstore.py +++ b/moban/hashstore.py @@ -65,6 +65,8 @@ def get_file_hash(afile): def get_hash(content): md5 = hashlib.md5() + if PY2 and content.__class__.__name__ == "unicode": + content = content.encode("utf-8") md5.update(content) return md5.digest().decode("latin1") diff --git a/moban/utils.py b/moban/utils.py index 3c498c95..87e0f63b 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -7,6 +7,7 @@ from moban import constants, exceptions log = logging.getLogger(__name__) +PY2 = sys.version_info[0] == 2 def merge(left, right): @@ -60,6 +61,8 @@ def file_permissions(afile): def write_file_out(filename, content): + if PY2 and content.__class__.__name__ == "unicode": + content = content.encode("utf-8") dest_folder = os.path.dirname(filename) if dest_folder: mkdir_p(dest_folder)