masaccio / numbers-parser

Python module for parsing Apple Numbers .numbers files
MIT License
201 stars 14 forks source link

Numbers 11.2 Support #2

Closed tsouchlarakis closed 2 years ago

tsouchlarakis commented 3 years ago

Unable to read a Numbers file without throwing an error on Numbers 11.2:

>>> from numbers_parser import Document
>>> doc = Document('numbers-test.numbers')
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/iwafile.py", line 148, in from_buffer
    klass = ID_NAME_MAP[message_info.type]
KeyError: 6372

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/iwafile.py", line 25, in from_buffer
    chunk, data = IWACompressedChunk.from_buffer(data, filename)
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/iwafile.py", line 84, in from_buffer
    archive, data = IWAArchiveSegment.from_buffer(data, filename)
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/iwafile.py", line 150, in from_buffer
    raise NotImplementedError(
NotImplementedError: Don't know how to parse Protobuf message type 6372

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/unpack.py", line 62, in _extract_iwa_archives
    iwaf = IWAFile.from_buffer(contents, filename)
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/iwafile.py", line 31, in from_buffer
    raise ValueError("Failed to deserialize " + filename) from e
ValueError: Failed to deserialize Index/CalculationEngine-860970.iwa

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/document.py", line 35, in __init__
    self._object_store = ObjectStore(filename)
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/containers.py", line 54, in __init__
    read_numbers_file(path,
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/unpack.py", line 35, in read_numbers_file
    _get_objects_from_zip_stream(zipf, handler, store_objects)
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/unpack.py", line 51, in _get_objects_from_zip_stream
    _extract_iwa_archives(contents, filename, handler, store_objects)
  File "/usr/local/lib/python3.9/site-packages/numbers_parser/unpack.py", line 64, in _extract_iwa_archives
    raise FileFormatError(f"{filename}: invalid IWA file {filename}") from e
NameError: name 'FileFormatError' is not defined
>>>
slott56 commented 2 years ago

It looks like the NameError: name 'FileFormatError' is not defined might be fixed in the code, but not yet pushed to PyPI? I'm having the same problem. The file I'm trying to open is https://github.com/slott56/Stingray-Reader/tree/main/sample/numbers_workbook_13.numbers

masaccio commented 2 years ago

There are two problems here: I've not imported FileFormatError (a trivial fix); and 11.2 has introduced some new Protobuf types, which requires a re-dump of the definitions. I am half-way through 11.2 support not helped by latest protobuf seg-faulting Python for me. Will look this weekend after I've built a clean environment to see if it's really a protobuf vs. Python problem

masaccio commented 2 years ago

It looks like the NameError: name 'FileFormatError' is not defined might be fixed in the code, but not yet pushed to The file I'm trying to open is https://github.com/slott56/Stingray-Reader/tree/main/sample/numbers_workbook_13.numbers

@slott56 My Numbers (11.2 on a Monterey Apple Silicon Mac) refuses to open that file. Has GitHub mangled it somehow? I've recreated all the protos from Numbers 11.2 and the datatype that fails in your doc (the 6219 reference) isn't defined in 11.2.

I've pushed changes to a 2.0.2 that correctly imports the exceptions and catches them for a sensible error in cat-numbers/unpack-numbers but that file is still broken.

masaccio commented 2 years ago

@tsouchlarakis apologies for not spotting your original issue -- don't know what happened there that I didn't see it.

Version 2.1 includes protos extracted from Numbers 11.2 and includes the ID (6372) that throws an exception for you. Can you try the latest from PyPI?

slott56 commented 2 years ago

Perfect.

tests/test_implementations.py::test_numbers_workbook PASSED              [100%]

I think this issue can be closed.

masaccio commented 2 years ago

Thanks for the quick test

slott56 commented 2 years ago

Thank you for a quick fix.