Unicode fixes for Python3
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user