Improvement of decodeIntToUnicode()

This commit is contained in:
Miroslav Stampar 2012-07-23 19:31:06 +02:00
parent 1153b4563c
commit b820975217

View File

@ -2523,16 +2523,23 @@ def openFile(filename, mode='r'):
def decodeIntToUnicode(value): def decodeIntToUnicode(value):
""" """
Decodes inferenced integer value with usage of current page encoding Decodes inferenced integer value to an unicode character
""" """
retVal = value
if isinstance(value, int):
try: try:
# http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_ord # http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_ord
if Backend.getIdentifiedDbms() in (DBMS.MYSQL,) or conf.charset: if Backend.getIdentifiedDbms() in (DBMS.MYSQL,):
return struct.pack('B' if value < 256 else '<H', value).decode(kb.pageEncoding or UNICODE_ENCODING) retVal = getUnicode(struct.pack('B' if value < 256 else '<H', value))
elif value > 255:
retVal = unichr(value)
else: else:
return unichr(value) retVal = getUnicode(chr(value))
except: except:
return INFERENCE_UNKNOWN_CHAR retVal = INFERENCE_UNKNOWN_CHAR
return retVal
def unhandledExceptionMessage(): def unhandledExceptionMessage():
""" """