2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-01-17 21:23:18 +00:00

Tolerate cp437 format text

UEFI output may still be cp437.  Tolerate through
attempting to use it.  UTF-8 continues to be preferred.
This commit is contained in:
Jarrod Johnson 2016-03-26 10:02:16 -04:00
parent 50aefee728
commit 79b1268a75

View File

@ -19,15 +19,25 @@ import confluent.tlv as tlv
import json
import struct
def decodestr(value):
ret = None
try:
ret = value.decode('utf-8')
except UnicodeDecodeError:
try:
ret = value.decode('cp437')
except UnicodeDecodeError:
ret = value
return ret
def unicode_dictvalues(dictdata):
for key in dictdata:
if isinstance(dictdata[key], str):
dictdata[key] = dictdata[key].decode('utf-8')
dictdata[key] = decodestr(dictdata[key])
elif isinstance(dictdata[key], list):
for i in xrange(len(dictdata[key])):
if isinstance(dictdata[key][i], str):
dictdata[key][i] = dictdata[key][i].decode('utf-8')
dictdata[key][i] = decodestr(dictdata[key][i])
elif isinstance(dictdata[key][i], dict):
unicode_dictvalues(dictdata[key][i])
elif isinstance(dictdata[key], dict):