Skip to content

Commit

Permalink
Merge pull request #287 from jayvdb/i281
Browse files Browse the repository at this point in the history
🚑 fix unicode support on Python 2.7
  • Loading branch information
chfw authored Jul 11, 2019
2 parents 4ffe02e + 10bebef commit 7dc6379
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions moban/hashstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 3 additions & 0 deletions moban/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from moban import constants, exceptions

log = logging.getLogger(__name__)
PY2 = sys.version_info[0] == 2


def merge(left, right):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7dc6379

Please sign in to comment.