Commit bf127df8 authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: Add functions to convert/handle bytes/str/unicode (from slapos.util).

Stricter than six.ensure_{text,str}().
parent 15a42a59
......@@ -550,6 +550,22 @@ def checkPythonSourceCode(source_code_str, portal_type=None):
#LOG('Utils', INFO, 'Checking time (pylint): %.2f' % (time.time() - started))
return message_list
#####################################################
# Python 2-3 compat
#####################################################
if str is bytes:
bytes2str = str2bytes = lambda s: s
def unicode2str(s):
return s.encode('utf-8')
else:
def bytes2str(s):
return s.decode()
def str2bytes(s):
return s.encode()
def unicode2str(s):
return s
#####################################################
# Globals initialization
#####################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment