Python version independent string and unicode handling.

This commit is contained in:
Markus Lampert
2017-10-22 12:01:35 -07:00
parent be115bcabf
commit 0d4e9d47c9
5 changed files with 28 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ other than PathLog, then it probably doesn't belong here.
'''
import PathScripts.PathLog as PathLog
import sys
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
@@ -96,3 +97,18 @@ Use this function to remove all expressions before deletion.'''
if hasattr(obj, 'ExpressionEngine'):
for attr,expr in obj.ExpressionEngine:
obj.setExpression(attr, None)
def toUnicode(string):
'''toUnicode(string) ... returns a unicode version of string regardless of the python version.'''
if sys.version_info[0] < 3:
return unicode(string)
return string
def isString(string):
'''isString(string) ... return True if string is a string, regardless of string type and python version.'''
if type(string) == str:
return True
if sys.version_info[0] < 3 and type(string) == unicode:
return True
return False