Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pyOneNote/FileNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,12 @@ def __init__(self, file, fileNodeChunkReference):
self.guidFooter = uuid.UUID(bytes_le=self.guidFooter)

def __str__(self):
return self.FileData[:128].hex()
fd = self.FileData
if isinstance(fd, (bytes, bytearray)):
return fd[:128].hex()
if isinstance(fd, str):
return fd[:128]
return repr(fd)[:128]


class ObjectSpaceObjectPropSet:
Expand Down Expand Up @@ -668,7 +673,14 @@ def get_properties(self):
try:
propertyVal = self.rgData[i].Data.decode('utf-16')
except:
propertyVal = self.rgData[i].Data.hex()
data = self.rgData[i].Data
if isinstance(data, (bytes, bytearray)):
propertyVal = data.hex()
elif isinstance(data, str):
# Already decoded somewhere upstream; pass through.
propertyVal = data
else:
propertyVal = repr(data)
else:
property_name_lower = propertyName.lower()
if 'time' in property_name_lower:
Expand Down Expand Up @@ -759,7 +771,11 @@ def __init__(self, file, propertySet):
self.Data, = struct.unpack('{}s'.format(self.cb), file.read(self.cb))

def __str__(self):
return self.Data.hex()
if isinstance(self.Data, (bytes, bytearray)):
return self.Data.hex()
if isinstance(self.Data, str):
return self.Data
return repr(self.Data)


class PropertyID:
Expand Down
13 changes: 12 additions & 1 deletion pyOneNote/OneDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,19 @@ def get_global_identification_table(self):
def get_json(self):
files_in_hex = {}
for key, file in self.get_files().items():
content = file['content']
if isinstance(content, (bytes, bytearray)):
content_hex = content.hex()
elif isinstance(content, str):
# Already a string; encode to bytes first to keep JSON output hex-only.
try:
content_hex = content.encode('latin-1').hex()
except UnicodeEncodeError:
content_hex = content.encode('utf-8', errors='replace').hex()
else:
content_hex = b''.hex()
files_in_hex[key] = {'extension': file['extension'],
'content': file['content'].hex(),
'content': content_hex,
'identity': file['identity']}

res = {
Expand Down