Esempio n. 1
0
def read(plist_path: str) -> Dict:
    """Read a plist file and return its contents as a dictionary."""
    exc.raise_if_falsy(plist_path=plist_path)
    data, error = NSData.dataWithContentsOfFile_options_error_(
        plist_path, 0, objc.nil)

    if not data:
        msg = 'Failed to load plist file at path: {}'.format(plist_path)
        _raise_ioerror_from_nserror(error, msg)

    contents, dummy, error = NSPropertyListSerialization.propertyListWithData_options_format_error_(
        data, NSPropertyListMutableContainersAndLeaves, objc.nil, objc.nil)

    if not contents:
        msg = 'Failed to deserialize plist at path: {}'.format(plist_path)
        _raise_ioerror_from_nserror(error, msg)

    return contents