Skip to content

Commit

Permalink
chg: [misc] extra function
Browse files Browse the repository at this point in the history
  • Loading branch information
cvandeplas committed Nov 7, 2024
1 parent 99c86b9 commit 7b920f9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sysdiagnose/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_version(filename="VERSION.txt"):
exit(f"Could not read version info, bailing out. Something is wrong: {str(e)}")


def load_plist_file_as_json(fname: str):
def load_plist_file_as_json(fname: str) -> dict:
if os.path.getsize(fname) == 0:
return {'error': ['Empty file']}
try:
Expand All @@ -48,11 +48,16 @@ def load_plist_file_as_json(fname: str):
return {'error': ['Invalid plist file']}


def load_plist_string_as_json(plist_string: str):
def load_plist_string_as_json(plist_string: str) -> dict:
plist = nska_deserialize.deserialize_plist_from_string(plist_string.encode(), full_recurse_convert_nska=True, format=dict)
return json_serializable(plist)


def load_plist_bytes_as_json(plist_bytes: bytes):
plist = nska_deserialize.deserialize_plist_from_string(plist_bytes, full_recurse_convert_nska=True, format=dict)
return json_serializable(plist)


# https://stackoverflow.com/questions/51674222/how-to-make-json-dumps-in-python-ignore-a-non-serializable-field
_cant_serialize = object()

Expand Down

0 comments on commit 7b920f9

Please sign in to comment.