use surrogateescape to decode in RawHeader
This commit is contained in:
parent
46b15774bd
commit
1d117742fa
1 changed files with 12 additions and 6 deletions
|
|
@ -806,7 +806,7 @@ class RawHeader(object):
|
|||
end = self.header.find(six.b('\0'), pos)
|
||||
value = self.header[pos:end]
|
||||
try:
|
||||
value = _decode_item(value)
|
||||
value = self.decode_bytes(value)
|
||||
except Exception:
|
||||
print('INVALID STRING')
|
||||
print("String(%d): %r" % (end - pos, value))
|
||||
|
|
@ -820,7 +820,7 @@ class RawHeader(object):
|
|||
end = self.header.find(six.b('\0'), pos)
|
||||
value = self.header[pos:end]
|
||||
try:
|
||||
value = _decode_item(value)
|
||||
value = self.decode_bytes(value)
|
||||
except Exception:
|
||||
print('INVALID STRING')
|
||||
print("String(%d): %r" % (end - pos, value))
|
||||
|
|
@ -832,7 +832,7 @@ class RawHeader(object):
|
|||
end = self.header.find(six.b('\0'), pos)
|
||||
value = self.header[pos:end]
|
||||
try:
|
||||
value = _decode_item(value)
|
||||
value = self.decode_bytes(value)
|
||||
except Exception:
|
||||
print('INVALID STRING')
|
||||
print("i18n(%d): %r" % (end - pos, value))
|
||||
|
|
@ -854,6 +854,12 @@ class RawHeader(object):
|
|||
print("Overflow size: %d" % (expected_ofs - pos))
|
||||
print("Offset: 0x%x" % self.datalen)
|
||||
|
||||
def decode_bytes(self, value):
|
||||
if six.PY2:
|
||||
return value
|
||||
else:
|
||||
return value.decode(errors='surrogateescape')
|
||||
|
||||
def __getitem__(self, key):
|
||||
tag, dtype, offset, count = self.index[key]
|
||||
assert tag == key
|
||||
|
|
@ -883,7 +889,7 @@ class RawHeader(object):
|
|||
end = self.header.find(six.b('\0'), pos)
|
||||
value = self.header[pos:end]
|
||||
if decode:
|
||||
value = _decode_item(value)
|
||||
value = self.decode_bytes(value)
|
||||
return value
|
||||
elif dtype == 7:
|
||||
# raw data
|
||||
|
|
@ -895,7 +901,7 @@ class RawHeader(object):
|
|||
end = self.header.find(six.b('\0'), pos)
|
||||
value = self.header[pos:end]
|
||||
if decode:
|
||||
value = _decode_item(value)
|
||||
value = self.decode_bytes(value)
|
||||
result.append(value)
|
||||
pos = end + 1
|
||||
return result
|
||||
|
|
@ -907,7 +913,7 @@ class RawHeader(object):
|
|||
end = self.header.find(six.b('\0'), pos)
|
||||
value = self.header[pos:end]
|
||||
if decode:
|
||||
value = _decode_item(value)
|
||||
value = self.decode_bytes(value)
|
||||
result.append(value)
|
||||
pos = end + 1
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue