Streamline conv_to_unicode

Also handle "None" strings and change default encoding to 'utf8' so that
it works without args when converting from UI input.
This commit is contained in:
John Ralls 2014-04-06 13:09:37 -07:00
parent 5972a3a16f
commit 43c37a603c

View File

@ -55,24 +55,17 @@ WINDOWS = ["Windows", "win32"]
#python 2 and 3 support, use correct conversion to unicode
if sys.version_info[0] < 3:
def conv_to_unicode(x, y=None):
if isinstance(x, unicode):
return x
return unicode(x, y) if y else unicode(x)
conv_to_unicode_direct = unicode
STRTYPE = basestring
UNITYPE = unicode
else:
def conv_to_unicode(x, y):
if isinstance(x, str):
return x
else:
return x.decode(y)
conv_to_unicode_direct = str
STRTYPE = str
UNITYPE = str
cuni = conv_to_unicode_direct
def conv_to_unicode(x, y='utf8'):
return x if x is None or isinstance(x, UNITYPE) else cuni(x, y)
# handle in database is bytes, while internally Gramps wants unicode for py3
if sys.version_info[0] < 3: