Skip to content
Snippets Groups Projects
Commit 1504b287 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

Merge branch 'py2_py3_fixes' into '1.5.x'

Py2/Py3 fixes

See merge request !11
parents 463849b0 a8df29d5
Branches
Tags v2.1.3
2 merge requests!17Merge development branch 1.5.x,!11Py2/Py3 fixes
Pipeline #
...@@ -44,12 +44,12 @@ def _sha256(s): ...@@ -44,12 +44,12 @@ def _sha256(s):
"""A python2/3 shortcut for :py:func:`haslib.sha256.hexdigest` to will """A python2/3 shortcut for :py:func:`haslib.sha256.hexdigest` to will
ensure that the given string is unicode before going further. ensure that the given string is unicode before going further.
""" """
try: if isinstance(s, six.string_types):
if isinstance(s, six.string_types): try:
s = six.u(s) s = six.u(s).encode('utf-8')
except: except:
pass s = s.encode('utf-8')
return hashlib.sha256(s.encode('utf-8')).hexdigest() return hashlib.sha256(s).hexdigest()
#---------------------------------------------------------- #----------------------------------------------------------
......
...@@ -190,6 +190,15 @@ class File(object): ...@@ -190,6 +190,15 @@ class File(object):
self.backup() self.backup()
mode = 'wb' if self.binary else 'wt' mode = 'wb' if self.binary else 'wt'
if self.binary:
mode = 'wb'
if isinstance(contents, six.string_types):
contents = contents.encode('utf-8')
else:
mode = 'wt'
if not isinstance(contents, six.string_types):
contents = contents.decode('utf-8')
with open(self.path, mode) as f: with open(self.path, mode) as f:
f.write(contents) f.write(contents)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment