Unicode fixes for Python3

This commit is contained in:
cclauss
2019-01-04 12:18:25 +01:00
committed by wmayer
parent 0453ee71e6
commit e3545c8c06
12 changed files with 108 additions and 101 deletions

View File

@@ -32,6 +32,8 @@ So if you add to this file and think about importing anything from PathScripts
other than PathLog, then it probably doesn't belong here.
'''
import six
import PathScripts.PathLog as PathLog
import sys
@@ -107,20 +109,12 @@ Use this function to remove all expressions before deletion.'''
def toUnicode(string):
'''toUnicode(string) ... returns a unicode version of string regardless of the python version.'''
if sys.version_info.major < 3:
return unicode(string)
return string
return six.text_type(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.major < 3 and type(string) == unicode:
return True
return False
return isinstance(string, six.text_type)
def keyValueIter(dictionary):
'''keyValueIter(dict) ... return iterable object over dictionary's (key,value) tuples.'''
if sys.version_info.major < 3:
return dictionary.items()
return dictionary.items()
return six.iteritems(dictionary)