numbers-parser 4.21.0__tar.gz → 4.22.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {numbers_parser-4.21.0/src/numbers_parser.egg-info → numbers_parser-4.22.2}/PKG-INFO +4 -5
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/README.md +3 -4
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/pyproject.toml +11 -2
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/_unpack_numbers.py +10 -2
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/cell.py +24 -23
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/constants.py +24 -20
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/document.py +17 -7
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/iwork.py +1 -1
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/model.py +101 -1
- {numbers_parser-4.21.0 → numbers_parser-4.22.2/src/numbers_parser.egg-info}/PKG-INFO +4 -5
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_formatting.py +43 -2
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_issues.py +15 -2
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_styles.py +0 -32
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_unpack_numbers.py +31 -2
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/LICENSE.rst +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/setup.cfg +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/__init__.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/_cat_numbers.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/_csv2numbers.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/bullets.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/containers.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/currencies.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/data/empty.numbers +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/exceptions.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/experimental.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/formula.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TNArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TNArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TNCommandArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TNCommandArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSAArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSAArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSACommandArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCEArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCH3DArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_Common_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_GEN_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHCommandArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHPreUFFArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCKArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCKArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSDArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSDArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSDCommandArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSKArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSPArchiveMessages_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSPDatabaseMessages_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSPMessages_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSSArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSSArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSTArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSTArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSTCommandArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSTStylePropertyArchiving_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSWPArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSWPArchives_sos_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSWPCommandArchives_pb2.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/__init__.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/fontmap.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/functionmap.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/mapping.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/iwafile.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/numbers_cache.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/numbers_uuid.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/roman.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/xrefs.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/SOURCES.txt +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/dependency_links.txt +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/entry_points.txt +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/requires.txt +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/top_level.txt +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_all_formulas.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_api_change.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_borders.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_bullets.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_cat_numbers.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_categories.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_comments.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_coverage.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_create_cells.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_csv2numbers.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_currency.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_encrypted.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_folder.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_formulas.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_large.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_local_docs.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_memory_leaks.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_merges.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_package.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_properties.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_roman.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_save.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_slices.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_table_size.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_tables.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_unsupported.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_uuids.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_version.py +0 -0
- {numbers_parser-4.21.0 → numbers_parser-4.22.2}/tests/test_write_empty_cell.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: numbers-parser
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.22.2
|
|
4
4
|
Summary: Read and write Apple Numbers spreadsheets
|
|
5
5
|
Author-email: Jon Connell <python@figsandfudge.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -313,9 +313,9 @@ Columns of data can have a number of transformations applied to them. The primar
|
|
|
313
313
|
|
|
314
314
|
```text
|
|
315
315
|
usage: csv2numbers [-h] [-V] [--whitespace] [--reverse] [--no-header]
|
|
316
|
-
[--day-first] [--date COLUMNS] [--
|
|
317
|
-
[--
|
|
318
|
-
[-o [FILENAME ...]]
|
|
316
|
+
[--day-first] [--date COLUMNS] [--encoding ENCODING]
|
|
317
|
+
[--rename COLUMNS-MAP] [--transform COLUMNS-MAP]
|
|
318
|
+
[--delete COLUMNS] [-o [FILENAME ...]]
|
|
319
319
|
[csvfile ...]
|
|
320
320
|
|
|
321
321
|
positional arguments:
|
|
@@ -404,7 +404,6 @@ Current known limitations of `numbers-parser` which may be implemented in the fu
|
|
|
404
404
|
- New tables are inserted with a fixed offset below the last table in a worksheet which does not take into account title or caption size
|
|
405
405
|
- Captions can be created and edited as of numbers-parser version 4.12, but cannot be styled. New captions adopt the first caption style available in the current document
|
|
406
406
|
- Formulas cannot be written to a document
|
|
407
|
-
- Pivot tables are unsupported and saving a document with a pivot table issues a UnsupportedWarning (see [issue 73](https://github.com/masaccio/numbers-parser/issues/73) for details).
|
|
408
407
|
- Tables which have been saved grouped cannot be safely edited as references to written cells refer to the ungrouped cell rows rather than the row number in the groups.
|
|
409
408
|
|
|
410
409
|
The following limitations are expected to always remain:
|
|
@@ -287,9 +287,9 @@ Columns of data can have a number of transformations applied to them. The primar
|
|
|
287
287
|
|
|
288
288
|
```text
|
|
289
289
|
usage: csv2numbers [-h] [-V] [--whitespace] [--reverse] [--no-header]
|
|
290
|
-
[--day-first] [--date COLUMNS] [--
|
|
291
|
-
[--
|
|
292
|
-
[-o [FILENAME ...]]
|
|
290
|
+
[--day-first] [--date COLUMNS] [--encoding ENCODING]
|
|
291
|
+
[--rename COLUMNS-MAP] [--transform COLUMNS-MAP]
|
|
292
|
+
[--delete COLUMNS] [-o [FILENAME ...]]
|
|
293
293
|
[csvfile ...]
|
|
294
294
|
|
|
295
295
|
positional arguments:
|
|
@@ -378,7 +378,6 @@ Current known limitations of `numbers-parser` which may be implemented in the fu
|
|
|
378
378
|
- New tables are inserted with a fixed offset below the last table in a worksheet which does not take into account title or caption size
|
|
379
379
|
- Captions can be created and edited as of numbers-parser version 4.12, but cannot be styled. New captions adopt the first caption style available in the current document
|
|
380
380
|
- Formulas cannot be written to a document
|
|
381
|
-
- Pivot tables are unsupported and saving a document with a pivot table issues a UnsupportedWarning (see [issue 73](https://github.com/masaccio/numbers-parser/issues/73) for details).
|
|
382
381
|
- Tables which have been saved grouped cannot be safely edited as references to written cells refer to the ungrouped cell rows rather than the row number in the groups.
|
|
383
382
|
|
|
384
383
|
The following limitations are expected to always remain:
|
|
@@ -24,7 +24,7 @@ classifiers = [
|
|
|
24
24
|
description = "Read and write Apple Numbers spreadsheets"
|
|
25
25
|
name = "numbers-parser"
|
|
26
26
|
readme = "README.md"
|
|
27
|
-
version = "4.
|
|
27
|
+
version = "4.22.2"
|
|
28
28
|
|
|
29
29
|
[project.urls]
|
|
30
30
|
repository = "https://github.com/masaccio/numbers-parser"
|
|
@@ -48,6 +48,7 @@ dev = [
|
|
|
48
48
|
"python-magic>=0.4",
|
|
49
49
|
"colorama<1.0.0,>=0.4.6",
|
|
50
50
|
"pympler<2.0,>=1.1",
|
|
51
|
+
"pre-commit>=4.6.2",
|
|
51
52
|
]
|
|
52
53
|
docs = [
|
|
53
54
|
"sphinx<9.0,>=7.3",
|
|
@@ -56,6 +57,7 @@ docs = [
|
|
|
56
57
|
"sphinx-nefertiti>=0.7",
|
|
57
58
|
"sphinx-markdown-builder>=0.6",
|
|
58
59
|
"sphinx-copybutton>=0.5.2",
|
|
60
|
+
"sphinxcontrib-mermaid>=2.1.1",
|
|
59
61
|
# Security updates
|
|
60
62
|
"urllib3>=2.7.0",
|
|
61
63
|
"filelock>=3.20.1",
|
|
@@ -74,6 +76,13 @@ bootstrap = [
|
|
|
74
76
|
"pyobjc-framework-Cocoa>=10.2",
|
|
75
77
|
"py2app>=0.28",
|
|
76
78
|
]
|
|
79
|
+
visualcheck = [
|
|
80
|
+
"osascript>=0.0.27",
|
|
81
|
+
"pillow>=12.3.0",
|
|
82
|
+
"pixelmatch>=0.4.0",
|
|
83
|
+
"pymupdf>=1.28.2",
|
|
84
|
+
"rich>=15.0.0",
|
|
85
|
+
]
|
|
77
86
|
|
|
78
87
|
[build-system]
|
|
79
88
|
requires = ["setuptools >= 61.0"]
|
|
@@ -107,7 +116,7 @@ addopts = "--cov=src/numbers_parser --cov-report=html --cov-report=term-missing:
|
|
|
107
116
|
|
|
108
117
|
[tool.tox]
|
|
109
118
|
requires = ["tox>=4.0"]
|
|
110
|
-
env_list = ["py310", "py311", "py312", "py313"]
|
|
119
|
+
env_list = ["py310", "py311", "py312", "py313", "py314", "py315"]
|
|
111
120
|
|
|
112
121
|
[tool.tox.env_run_base]
|
|
113
122
|
deps = [
|
|
@@ -36,7 +36,15 @@ class NumbersUnpacker(IWorkHandler):
|
|
|
36
36
|
def store_file(self, filename: str, blob: bytes) -> None:
|
|
37
37
|
"""Store a protobuf archive."""
|
|
38
38
|
filename = re.sub(r".*\.numbers/", "", str(filename))
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
# Resolve absolute paths to prevent Zip Slip
|
|
41
|
+
out_abs = os.path.realpath(self.output_dir)
|
|
42
|
+
target_abs = os.path.realpath(os.path.join(out_abs, filename))
|
|
43
|
+
if os.path.commonpath([out_abs, target_abs]) != out_abs:
|
|
44
|
+
msg = f"Path traversal attempt detected in archive member: {filename}"
|
|
45
|
+
raise FileFormatError(msg)
|
|
46
|
+
|
|
47
|
+
self.ensure_directory_exists(target_abs)
|
|
40
48
|
target_path = os.path.join(self.output_dir, filename)
|
|
41
49
|
if isinstance(blob, IWAFile):
|
|
42
50
|
target_path = target_path.replace(".iwa", "")
|
|
@@ -100,7 +108,7 @@ class NumbersUnpacker(IWorkHandler):
|
|
|
100
108
|
elif k in ["cell_storage_buffer", "cell_storage_buffer_pre_bnc"]:
|
|
101
109
|
obj[k] = str(hexlify(b64decode(obj[k]), sep=":"))
|
|
102
110
|
obj[k] = obj[k].replace("b'", "").replace("'", "")
|
|
103
|
-
elif k in ["cell_offsets",
|
|
111
|
+
elif k in ["cell_offsets", "cell_offsets_pre_bnc"]:
|
|
104
112
|
offsets = array("h", b64decode(obj[k])).tolist()
|
|
105
113
|
obj[k] = ",".join([str(x) for x in offsets])
|
|
106
114
|
obj[k] = re.sub(r"(?:,-1)+$", ",[...]", obj[k])
|
|
@@ -1456,6 +1456,8 @@ class Cell(CellStorageFlags, Cacheable):
|
|
|
1456
1456
|
self._control_id = control_id
|
|
1457
1457
|
elif format_type in [FormattingType.DATETIME, CustomFormattingType.DATETIME]:
|
|
1458
1458
|
self._date_format_id = format_id
|
|
1459
|
+
elif format_type == FormattingType.DURATION:
|
|
1460
|
+
self._duration_format_id = format_id
|
|
1459
1461
|
elif format_type in [FormattingType.TEXT, CustomFormattingType.TEXT]:
|
|
1460
1462
|
self._text_format_id = format_id
|
|
1461
1463
|
else:
|
|
@@ -1789,7 +1791,7 @@ def _expand_quotes(value: str) -> str:
|
|
|
1789
1791
|
return formatted_value
|
|
1790
1792
|
|
|
1791
1793
|
|
|
1792
|
-
def _decode_number_format( # noqa: PLR0912
|
|
1794
|
+
def _decode_number_format( # noqa: PLR0912, PLR0915
|
|
1793
1795
|
number_format: TSKArchives.FormatStructArchive,
|
|
1794
1796
|
value: float,
|
|
1795
1797
|
name: str,
|
|
@@ -2069,35 +2071,31 @@ def _format_base(value: float, number_format) -> str:
|
|
|
2069
2071
|
return formatted_value.zfill(number_format.base_places)
|
|
2070
2072
|
|
|
2071
2073
|
|
|
2072
|
-
def
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
return
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
if numerator == denominator:
|
|
2080
|
-
return "1"
|
|
2081
|
-
return f"{numerator}/{denominator}"
|
|
2074
|
+
def _format_fraction_parts(whole: int, numerator: int, denominator: int) -> str:
|
|
2075
|
+
"""Return the simplest fraction for the given whole, numerator and denominator."""
|
|
2076
|
+
whole, numerator = abs(whole), abs(numerator)
|
|
2077
|
+
if not numerator:
|
|
2078
|
+
return str(whole)
|
|
2079
|
+
fraction = f"{numerator}/{denominator}"
|
|
2080
|
+
return f"{whole} {fraction}" if whole else fraction
|
|
2082
2081
|
|
|
2083
2082
|
|
|
2084
2083
|
def _float_to_fraction(value: float, denominator: int) -> str:
|
|
2085
2084
|
"""Convert a float to the nearest fraction and return as a string."""
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2085
|
+
numerator = round(abs(value) * denominator)
|
|
2086
|
+
whole, rem = divmod(numerator, denominator)
|
|
2087
|
+
|
|
2088
|
+
result = _format_fraction_parts(whole, rem, denominator)
|
|
2089
|
+
return f"-{result}" if value < 0 and result != "0" else result
|
|
2089
2090
|
|
|
2090
2091
|
|
|
2091
2092
|
def _float_to_n_digit_fraction(value: float, max_digits: int) -> str:
|
|
2092
|
-
"""
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
whole = int(value)
|
|
2099
|
-
numerator -= whole * denominator
|
|
2100
|
-
return _format_fraction_parts_to(whole, numerator, denominator)
|
|
2093
|
+
"""Convert a float to a fraction of a maximum number of digits and return as a string."""
|
|
2094
|
+
fraction = Fraction(abs(value)).limit_denominator(10**max_digits - 1)
|
|
2095
|
+
whole, numerator = divmod(fraction.numerator, fraction.denominator)
|
|
2096
|
+
|
|
2097
|
+
result = _format_fraction_parts(whole, numerator, fraction.denominator)
|
|
2098
|
+
return f"-{result}" if value < 0 and result != "0" else result
|
|
2101
2099
|
|
|
2102
2100
|
|
|
2103
2101
|
def _format_fraction(value: float, number_format) -> str:
|
|
@@ -2169,6 +2167,9 @@ class Formatting:
|
|
|
2169
2167
|
control_format: ControlFormattingType = ControlFormattingType.NUMBER
|
|
2170
2168
|
currency_code: str = "GBP"
|
|
2171
2169
|
date_time_format: str = DEFAULT_DATETIME_FORMAT
|
|
2170
|
+
duration_style: DurationStyle = DurationStyle.COMPACT
|
|
2171
|
+
duration_unit_largest: DurationUnits = None
|
|
2172
|
+
duration_unit_smallest: DurationUnits = None
|
|
2172
2173
|
decimal_places: int = None
|
|
2173
2174
|
fraction_accuracy: FractionAccuracy = FractionAccuracy.THREE
|
|
2174
2175
|
increment: float = 1.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
-
from enum import IntEnum
|
|
2
|
+
from enum import IntEnum, auto
|
|
3
3
|
from importlib.resources import files
|
|
4
4
|
from math import ceil
|
|
5
5
|
|
|
@@ -229,28 +229,29 @@ class FormatType(IntEnum):
|
|
|
229
229
|
|
|
230
230
|
|
|
231
231
|
class FormattingType(IntEnum):
|
|
232
|
-
BASE =
|
|
233
|
-
CURRENCY =
|
|
234
|
-
DATETIME =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
232
|
+
BASE = auto()
|
|
233
|
+
CURRENCY = auto()
|
|
234
|
+
DATETIME = auto()
|
|
235
|
+
DURATION = auto()
|
|
236
|
+
FRACTION = auto()
|
|
237
|
+
NUMBER = auto()
|
|
238
|
+
PERCENTAGE = auto()
|
|
239
|
+
SCIENTIFIC = auto()
|
|
240
|
+
TICKBOX = auto()
|
|
241
|
+
RATING = auto()
|
|
242
|
+
SLIDER = auto()
|
|
243
|
+
STEPPER = auto()
|
|
244
|
+
POPUP = auto()
|
|
245
|
+
TEXT = auto()
|
|
245
246
|
|
|
246
247
|
|
|
247
248
|
class ControlFormattingType(IntEnum):
|
|
248
|
-
BASE =
|
|
249
|
-
CURRENCY =
|
|
250
|
-
FRACTION =
|
|
251
|
-
NUMBER =
|
|
252
|
-
PERCENTAGE =
|
|
253
|
-
SCIENTIFIC =
|
|
249
|
+
BASE = auto()
|
|
250
|
+
CURRENCY = auto()
|
|
251
|
+
FRACTION = auto()
|
|
252
|
+
NUMBER = auto()
|
|
253
|
+
PERCENTAGE = auto()
|
|
254
|
+
SCIENTIFIC = auto()
|
|
254
255
|
|
|
255
256
|
|
|
256
257
|
class OwnerKind(IntEnum):
|
|
@@ -263,6 +264,7 @@ FORMATTING_ALLOWED_CELLS = {
|
|
|
263
264
|
"base": ["NumberCell"],
|
|
264
265
|
"currency": ["NumberCell"],
|
|
265
266
|
"datetime": ["DateCell"],
|
|
267
|
+
"duration": ["DurationCell"],
|
|
266
268
|
"fraction": ["NumberCell"],
|
|
267
269
|
"number": ["NumberCell"],
|
|
268
270
|
"percentage": ["NumberCell"],
|
|
@@ -352,6 +354,7 @@ ALLOWED_FORMATTING_PARAMETERS = {
|
|
|
352
354
|
"use_accounting_style",
|
|
353
355
|
],
|
|
354
356
|
FormattingType.DATETIME: ["date_time_format"],
|
|
357
|
+
FormattingType.DURATION: ["duration_style", "duration_unit_largest", "duration_unit_smallest"],
|
|
355
358
|
FormattingType.FRACTION: ["fraction_accuracy"],
|
|
356
359
|
FormattingType.NUMBER: [
|
|
357
360
|
"decimal_places",
|
|
@@ -386,6 +389,7 @@ FORMAT_TYPE_MAP = {
|
|
|
386
389
|
FormattingType.BASE: FormatType.BASE,
|
|
387
390
|
FormattingType.CURRENCY: FormatType.CURRENCY,
|
|
388
391
|
FormattingType.DATETIME: FormatType.DATE,
|
|
392
|
+
FormattingType.DURATION: FormatType.DURATION,
|
|
389
393
|
FormattingType.FRACTION: FormatType.FRACTION,
|
|
390
394
|
FormattingType.NUMBER: FormatType.DECIMAL,
|
|
391
395
|
FormattingType.PERCENTAGE: FormatType.PERCENT,
|
|
@@ -17,7 +17,6 @@ from numbers_parser.cell import (
|
|
|
17
17
|
MergedCell,
|
|
18
18
|
Style,
|
|
19
19
|
TextCell,
|
|
20
|
-
UnsupportedWarning,
|
|
21
20
|
)
|
|
22
21
|
from numbers_parser.constants import (
|
|
23
22
|
CUSTOM_FORMATTING_ALLOWED_CELLS,
|
|
@@ -79,7 +78,7 @@ class Document:
|
|
|
79
78
|
|
|
80
79
|
"""
|
|
81
80
|
|
|
82
|
-
def __init__(
|
|
81
|
+
def __init__( # noqa: PLR0917
|
|
83
82
|
self,
|
|
84
83
|
filename: str | Path | None = None,
|
|
85
84
|
sheet_name: str | None = "Sheet 1",
|
|
@@ -160,6 +159,13 @@ class Document:
|
|
|
160
159
|
If attempting to write a package into a folder that is not an
|
|
161
160
|
existing Numbers document.
|
|
162
161
|
|
|
162
|
+
Warns
|
|
163
|
+
-----
|
|
164
|
+
RuntimeWarning:
|
|
165
|
+
If saving a document that contains a pivot table. ``numbers-parser`` will
|
|
166
|
+
automatically update the coordinate metadata so that pivot tables can be
|
|
167
|
+
safely refreshed in Numbers, but this is considered unproven functionality.
|
|
168
|
+
|
|
163
169
|
"""
|
|
164
170
|
self.filename = filename
|
|
165
171
|
for sheet in self.sheets:
|
|
@@ -167,12 +173,11 @@ class Document:
|
|
|
167
173
|
if self._model.is_a_pivot_table(table._table_id):
|
|
168
174
|
table_name = self._model.table_name(table._table_id)
|
|
169
175
|
warn(
|
|
170
|
-
f"
|
|
171
|
-
|
|
176
|
+
f"Pivot table '{table_name}' may be corrupted by save.",
|
|
177
|
+
RuntimeWarning,
|
|
172
178
|
stacklevel=2,
|
|
173
179
|
)
|
|
174
|
-
|
|
175
|
-
self._model.recalculate_table_data(table._table_id, table._data)
|
|
180
|
+
self._model.recalculate_table_data(table._table_id, table._data)
|
|
176
181
|
self._model.save(Path(filename), package, password, hint)
|
|
177
182
|
|
|
178
183
|
def add_sheet(
|
|
@@ -460,7 +465,7 @@ class Sheet:
|
|
|
460
465
|
num_header_cols,
|
|
461
466
|
)
|
|
462
467
|
|
|
463
|
-
def _add_table(
|
|
468
|
+
def _add_table( # noqa: PLR0917
|
|
464
469
|
self,
|
|
465
470
|
table_name,
|
|
466
471
|
from_table_id,
|
|
@@ -1765,6 +1770,11 @@ class Table(Cacheable):
|
|
|
1765
1770
|
strftime-like formatting string of :ref:`Numbers date/time
|
|
1766
1771
|
directives <datetime_formats>`.
|
|
1767
1772
|
|
|
1773
|
+
:``"duration"``:
|
|
1774
|
+
* **duration_style** (*:py:class:`~numbers_parser.DurationStyle`, optional, default: DurationStyle.COMPACT*) - How the duration units are rendered.
|
|
1775
|
+
* **duration_unit_largest** (*:py:class:`~numbers_parser.DurationUnits`, optional, default: None*) - the first and largest duration unit to display
|
|
1776
|
+
* **duration_unit_smallest** (*:py:class:`~numbers_parser.DurationUnits`, optional, default: None*) - the last and smallest duration unit to display
|
|
1777
|
+
|
|
1768
1778
|
:``"fraction"``:
|
|
1769
1779
|
* **fraction_accuracy** (*:py:class:`~numbers_parser.FractionAccuracy`, optional, default: FractionAccuracy.THREE* - The
|
|
1770
1780
|
precision of the faction.
|
|
@@ -364,7 +364,7 @@ class IWork:
|
|
|
364
364
|
else:
|
|
365
365
|
with sub_filepath.open(mode="rb") as fh:
|
|
366
366
|
blob = fh.read()
|
|
367
|
-
package_filename = re.sub(r"
|
|
367
|
+
package_filename = re.sub(r".*?\.numbers/*", "", str(sub_filepath))
|
|
368
368
|
self._store_blob(package_filename, blob)
|
|
369
369
|
|
|
370
370
|
def _read_package_encryption(self, filepath: Path) -> None:
|
|
@@ -242,6 +242,7 @@ class _NumbersModel(Cacheable):
|
|
|
242
242
|
self.calculate_table_uuid_map()
|
|
243
243
|
|
|
244
244
|
def save(self, filepath: Path, package: bool, password: str, hint: str) -> None:
|
|
245
|
+
self.refresh_pivot_tables()
|
|
245
246
|
self.objects.save(filepath, package, password, hint)
|
|
246
247
|
|
|
247
248
|
def find_refs(self, ref: str) -> list:
|
|
@@ -563,6 +564,13 @@ class _NumbersModel(Cacheable):
|
|
|
563
564
|
range_control_max=formatting.maximum,
|
|
564
565
|
range_control_inc=formatting.increment,
|
|
565
566
|
)
|
|
567
|
+
elif format_type == FormattingType.STEPPER:
|
|
568
|
+
cell_spec = TSTArchives.CellSpecArchive(
|
|
569
|
+
interaction_type=CellInteractionType.STEPPER,
|
|
570
|
+
range_control_min=formatting.minimum,
|
|
571
|
+
range_control_max=formatting.maximum,
|
|
572
|
+
range_control_inc=formatting.increment,
|
|
573
|
+
)
|
|
566
574
|
else: # POPUP
|
|
567
575
|
popup_id = self.cell_popup_model(self._control_specs.id(table_id), formatting)
|
|
568
576
|
cell_spec = TSTArchives.CellSpecArchive(
|
|
@@ -1225,7 +1233,7 @@ class _NumbersModel(Cacheable):
|
|
|
1225
1233
|
self.update_cell_borders(table_id, data)
|
|
1226
1234
|
|
|
1227
1235
|
self.objects.remove_unreferenced_objects()
|
|
1228
|
-
|
|
1236
|
+
self.update_table_metadata_ranges(table_id, len(data), len(data[0]))
|
|
1229
1237
|
|
|
1230
1238
|
tile_idx = 0
|
|
1231
1239
|
max_tile_idx = len(data) >> 8
|
|
@@ -2827,6 +2835,98 @@ class _NumbersModel(Cacheable):
|
|
|
2827
2835
|
)
|
|
2828
2836
|
}
|
|
2829
2837
|
|
|
2838
|
+
def refresh_pivot_tables(self) -> None:
|
|
2839
|
+
"""
|
|
2840
|
+
Signal a data refresh for pivot tables on next load by bumping their
|
|
2841
|
+
refresh UUIDs and timestamps, while leaving rule UUIDs intact to
|
|
2842
|
+
preserve layout and styling.
|
|
2843
|
+
"""
|
|
2844
|
+
for sheet_id in self.sheet_ids():
|
|
2845
|
+
for table_id in self.table_ids(sheet_id):
|
|
2846
|
+
if not self.is_a_pivot_table(table_id):
|
|
2847
|
+
continue
|
|
2848
|
+
|
|
2849
|
+
table_model = self.objects[table_id]
|
|
2850
|
+
pivot_owner_id = table_model.pivot_owner.identifier
|
|
2851
|
+
pivot_owner = self.objects[pivot_owner_id]
|
|
2852
|
+
|
|
2853
|
+
# Only touch the data refresh trackers. Do not alter rule UUIDs.
|
|
2854
|
+
pivot_owner.refresh_uid.CopyFrom(NumbersUUID().protobuf2)
|
|
2855
|
+
pivot_owner.refresh_timestamp = (datetime.now() - EPOCH).total_seconds() # noqa: DTZ005
|
|
2856
|
+
|
|
2857
|
+
def update_table_metadata_ranges(self, table_id: int, num_rows: int, num_cols: int) -> None:
|
|
2858
|
+
"""Keep UID maps and dependency bounds in sync with data dimensions."""
|
|
2859
|
+
table_model = self.objects[table_id]
|
|
2860
|
+
|
|
2861
|
+
def _update_map(uid_map_ref):
|
|
2862
|
+
if not uid_map_ref or uid_map_ref.identifier == 0:
|
|
2863
|
+
return
|
|
2864
|
+
uid_map = self.objects[uid_map_ref.identifier]
|
|
2865
|
+
|
|
2866
|
+
col_uuids = [
|
|
2867
|
+
NumbersUUID(uid_map.sorted_column_uids[i]) for i in uid_map.column_uid_for_index
|
|
2868
|
+
]
|
|
2869
|
+
row_uuids = [NumbersUUID(uid_map.sorted_row_uids[i]) for i in uid_map.row_uid_for_index]
|
|
2870
|
+
|
|
2871
|
+
if num_cols > len(col_uuids):
|
|
2872
|
+
col_uuids.extend([NumbersUUID() for _ in range(num_cols - len(col_uuids))])
|
|
2873
|
+
elif num_cols < len(col_uuids):
|
|
2874
|
+
col_uuids = col_uuids[:num_cols]
|
|
2875
|
+
|
|
2876
|
+
if num_rows > len(row_uuids):
|
|
2877
|
+
row_uuids.extend([NumbersUUID() for _ in range(num_rows - len(row_uuids))])
|
|
2878
|
+
elif num_rows < len(row_uuids):
|
|
2879
|
+
row_uuids = row_uuids[:num_rows]
|
|
2880
|
+
|
|
2881
|
+
sorted_col_uuids = sorted(col_uuids, key=lambda x: x.int)
|
|
2882
|
+
sorted_row_uuids = sorted(row_uuids, key=lambda x: x.int)
|
|
2883
|
+
|
|
2884
|
+
clear_field_container(uid_map.sorted_column_uids)
|
|
2885
|
+
for u in sorted_col_uuids:
|
|
2886
|
+
uid_map.sorted_column_uids.append(u.protobuf2)
|
|
2887
|
+
|
|
2888
|
+
clear_field_container(uid_map.column_uid_for_index)
|
|
2889
|
+
clear_field_container(uid_map.column_index_for_uid)
|
|
2890
|
+
for _ in sorted_col_uuids:
|
|
2891
|
+
uid_map.column_index_for_uid.append(0)
|
|
2892
|
+
for col_idx, u in enumerate(col_uuids):
|
|
2893
|
+
sorted_idx = sorted_col_uuids.index(u)
|
|
2894
|
+
uid_map.column_uid_for_index.append(sorted_idx)
|
|
2895
|
+
uid_map.column_index_for_uid[sorted_idx] = col_idx
|
|
2896
|
+
|
|
2897
|
+
clear_field_container(uid_map.sorted_row_uids)
|
|
2898
|
+
for u in sorted_row_uuids:
|
|
2899
|
+
uid_map.sorted_row_uids.append(u.protobuf2)
|
|
2900
|
+
|
|
2901
|
+
clear_field_container(uid_map.row_uid_for_index)
|
|
2902
|
+
clear_field_container(uid_map.row_index_for_uid)
|
|
2903
|
+
for _ in sorted_row_uuids:
|
|
2904
|
+
uid_map.row_index_for_uid.append(0)
|
|
2905
|
+
for row_idx, u in enumerate(row_uuids):
|
|
2906
|
+
sorted_idx = sorted_row_uuids.index(u)
|
|
2907
|
+
uid_map.row_uid_for_index.append(sorted_idx)
|
|
2908
|
+
uid_map.row_index_for_uid[sorted_idx] = row_idx
|
|
2909
|
+
|
|
2910
|
+
_update_map(table_model.base_column_row_uids)
|
|
2911
|
+
|
|
2912
|
+
table_info_id = self.table_info_id(table_id)
|
|
2913
|
+
table_info = self.objects[table_info_id]
|
|
2914
|
+
_update_map(table_info.view_column_row_uids)
|
|
2915
|
+
|
|
2916
|
+
calc_engine = self.calc_engine()
|
|
2917
|
+
for dep_ref in calc_engine.dependency_tracker.formula_owner_dependencies:
|
|
2918
|
+
dep_archive = self.objects[dep_ref.identifier]
|
|
2919
|
+
if (
|
|
2920
|
+
dep_archive.owner_kind == OwnerKind.TABLE_MODEL
|
|
2921
|
+
and dep_archive.formula_owner.identifier == table_info_id
|
|
2922
|
+
):
|
|
2923
|
+
for field in ["spanning_column_dependencies", "spanning_row_dependencies"]:
|
|
2924
|
+
spanning = getattr(dep_archive, field)
|
|
2925
|
+
spanning.total_range_for_table.bottom_right_row = num_rows - 1
|
|
2926
|
+
spanning.total_range_for_table.bottom_right_column = num_cols - 1
|
|
2927
|
+
spanning.body_range_for_table.bottom_right_row = num_rows - 1
|
|
2928
|
+
spanning.body_range_for_table.bottom_right_column = num_cols - 1
|
|
2929
|
+
|
|
2830
2930
|
|
|
2831
2931
|
def rgb(obj) -> RGB:
|
|
2832
2932
|
"""Convert a TSPArchives.Color into an RGB tuple."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: numbers-parser
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.22.2
|
|
4
4
|
Summary: Read and write Apple Numbers spreadsheets
|
|
5
5
|
Author-email: Jon Connell <python@figsandfudge.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -313,9 +313,9 @@ Columns of data can have a number of transformations applied to them. The primar
|
|
|
313
313
|
|
|
314
314
|
```text
|
|
315
315
|
usage: csv2numbers [-h] [-V] [--whitespace] [--reverse] [--no-header]
|
|
316
|
-
[--day-first] [--date COLUMNS] [--
|
|
317
|
-
[--
|
|
318
|
-
[-o [FILENAME ...]]
|
|
316
|
+
[--day-first] [--date COLUMNS] [--encoding ENCODING]
|
|
317
|
+
[--rename COLUMNS-MAP] [--transform COLUMNS-MAP]
|
|
318
|
+
[--delete COLUMNS] [-o [FILENAME ...]]
|
|
319
319
|
[csvfile ...]
|
|
320
320
|
|
|
321
321
|
positional arguments:
|
|
@@ -404,7 +404,6 @@ Current known limitations of `numbers-parser` which may be implemented in the fu
|
|
|
404
404
|
- New tables are inserted with a fixed offset below the last table in a worksheet which does not take into account title or caption size
|
|
405
405
|
- Captions can be created and edited as of numbers-parser version 4.12, but cannot be styled. New captions adopt the first caption style available in the current document
|
|
406
406
|
- Formulas cannot be written to a document
|
|
407
|
-
- Pivot tables are unsupported and saving a document with a pivot table issues a UnsupportedWarning (see [issue 73](https://github.com/masaccio/numbers-parser/issues/73) for details).
|
|
408
407
|
- Tables which have been saved grouped cannot be safely edited as references to written cells refer to the ungrouped cell rows rather than the row number in the groups.
|
|
409
408
|
|
|
410
409
|
The following limitations are expected to always remain:
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Generator
|
|
2
|
+
from datetime import datetime, timedelta
|
|
2
3
|
|
|
3
4
|
import pytest
|
|
4
5
|
import pytest_check as check
|
|
5
6
|
|
|
6
7
|
from numbers_parser import (
|
|
8
|
+
Cell,
|
|
7
9
|
ControlFormattingType,
|
|
8
10
|
Document,
|
|
11
|
+
DurationStyle,
|
|
12
|
+
DurationUnits,
|
|
9
13
|
EmptyCell,
|
|
10
14
|
FractionAccuracy,
|
|
11
15
|
NegativeNumberStyle,
|
|
@@ -374,7 +378,7 @@ def test_custom_formatting(pytestconfig):
|
|
|
374
378
|
raise AssertionError
|
|
375
379
|
|
|
376
380
|
|
|
377
|
-
def
|
|
381
|
+
def test_custom_formatting_stress(pytestconfig):
|
|
378
382
|
if pytestconfig.getoption("max_check_fails") is not None:
|
|
379
383
|
max_check_fails = pytestconfig.getoption("max_check_fails")
|
|
380
384
|
else:
|
|
@@ -395,6 +399,31 @@ def test_formatting_stress(pytestconfig):
|
|
|
395
399
|
raise AssertionError
|
|
396
400
|
|
|
397
401
|
|
|
402
|
+
def test_standard_formatting_stress():
|
|
403
|
+
def chunks(cells: list[Cell]) -> Generator[tuple[int, Cell, str]]:
|
|
404
|
+
for ii in range(0, len(cells), 2):
|
|
405
|
+
yield (ii, cells[ii], cells[ii + 1].formatted_value)
|
|
406
|
+
|
|
407
|
+
doc = Document("tests/data/standard-format-stress.numbers")
|
|
408
|
+
for sheet in doc.sheets:
|
|
409
|
+
table = sheet.tables[0]
|
|
410
|
+
for cells in table.iter_rows(min_row=1):
|
|
411
|
+
test_name = f"{sheet.name}:{cells[0].value}"
|
|
412
|
+
if not test_name:
|
|
413
|
+
continue
|
|
414
|
+
raw_value = cells[1].value
|
|
415
|
+
for idx, cell, formatted_value in chunks(cells[2:]):
|
|
416
|
+
if isinstance(cell, EmptyCell):
|
|
417
|
+
continue
|
|
418
|
+
subtest_name = table.cell(0, idx + 2).value
|
|
419
|
+
check.equal(cell.value, raw_value, f"{test_name}:{subtest_name}:raw")
|
|
420
|
+
check.equal(
|
|
421
|
+
formatted_value,
|
|
422
|
+
cell.formatted_value,
|
|
423
|
+
(f"{test_name}:{subtest_name}:formatted"),
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
|
|
398
427
|
def test_write_date_format(configurable_save_file):
|
|
399
428
|
doc = Document(
|
|
400
429
|
num_header_cols=0,
|
|
@@ -434,6 +463,15 @@ def test_write_date_format(configurable_save_file):
|
|
|
434
463
|
table.write(row, col, ref_date)
|
|
435
464
|
table.set_cell_formatting(row, col, "datetime", date_time_format=date_time_format)
|
|
436
465
|
|
|
466
|
+
table.write(row + 1, 0, timedelta(days=1, hours=2))
|
|
467
|
+
table.set_cell_formatting(
|
|
468
|
+
row + 1,
|
|
469
|
+
0,
|
|
470
|
+
"duration",
|
|
471
|
+
duration_style=DurationStyle.LONG,
|
|
472
|
+
duration_unit_largest=DurationUnits.DAY,
|
|
473
|
+
duration_unit_smallest=DurationUnits.MINUTE,
|
|
474
|
+
)
|
|
437
475
|
doc.save(configurable_save_file)
|
|
438
476
|
|
|
439
477
|
doc = Document(configurable_save_file)
|
|
@@ -443,6 +481,9 @@ def test_write_date_format(configurable_save_file):
|
|
|
443
481
|
check.equal(table.cell(row, col).value, ref_date)
|
|
444
482
|
check.equal(table.cell(row, col).formatted_value, ref_value)
|
|
445
483
|
|
|
484
|
+
check.equal(table.cell(row + 1, 0).value, timedelta(days=1, hours=2))
|
|
485
|
+
check.equal(table.cell(row + 1, 0).formatted_value, "1 day 2 hours 0 minutes")
|
|
486
|
+
|
|
446
487
|
|
|
447
488
|
def test_write_numbers_format(configurable_save_file):
|
|
448
489
|
doc = Document(num_header_cols=0, num_header_rows=0, num_cols=8, num_rows=10)
|
|
@@ -423,9 +423,15 @@ def test_issue_69():
|
|
|
423
423
|
|
|
424
424
|
def test_issue_73(configurable_save_file):
|
|
425
425
|
doc = Document("tests/data/issue-73.numbers")
|
|
426
|
-
|
|
426
|
+
table = doc.sheets[0].tables["Table 1"]
|
|
427
|
+
table.write("A4", "foo")
|
|
428
|
+
table.write("B4", 10)
|
|
429
|
+
|
|
430
|
+
with pytest.warns(
|
|
431
|
+
RuntimeWarning, match="Pivot table 'Table 1 Pivot' may be corrupted by save."
|
|
432
|
+
):
|
|
427
433
|
doc.save(configurable_save_file)
|
|
428
|
-
|
|
434
|
+
doc.save(configurable_save_file)
|
|
429
435
|
|
|
430
436
|
|
|
431
437
|
def test_issue_74_1(configurable_save_file):
|
|
@@ -975,3 +981,10 @@ def test_issue_256():
|
|
|
975
981
|
"-1/2",
|
|
976
982
|
"-2",
|
|
977
983
|
]
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
def test_issue_266():
|
|
987
|
+
doc = Document("tests/data/issue-266.numbers")
|
|
988
|
+
table = doc.default_table
|
|
989
|
+
for row in range(table.num_rows):
|
|
990
|
+
assert table.cell(row, 1).formatted_value == table.cell(row, 2).value
|
|
@@ -168,38 +168,6 @@ def test_all_styles(configurable_save_file):
|
|
|
168
168
|
assert check_style(cell.style, **attrs)
|
|
169
169
|
|
|
170
170
|
|
|
171
|
-
@pytest.mark.experimental
|
|
172
|
-
def test_all_styles_visual_check(configurable_save_file):
|
|
173
|
-
print("\n\n************** VISUAL CHECKS OF STYLES **************")
|
|
174
|
-
|
|
175
|
-
doc = Document("tests/data/test-styles.numbers")
|
|
176
|
-
table = doc.sheets["Styles"].tables[0]
|
|
177
|
-
|
|
178
|
-
new_doc = Document()
|
|
179
|
-
new_table = new_doc.default_table
|
|
180
|
-
for row in range(table.num_rows):
|
|
181
|
-
new_table.row_height(table.row_height(row))
|
|
182
|
-
for col in range(table.num_cols):
|
|
183
|
-
new_table.col_width(table.col_width(col))
|
|
184
|
-
|
|
185
|
-
for row in range(table.num_rows):
|
|
186
|
-
for col in range(table.num_cols):
|
|
187
|
-
cell = table.cell(row, col)
|
|
188
|
-
if not cell.value:
|
|
189
|
-
continue
|
|
190
|
-
attrs = decode_style_attrs(cell.value)
|
|
191
|
-
if "name" in attrs:
|
|
192
|
-
del attrs["name"]
|
|
193
|
-
print(f"@[{cell.row},{cell.col}: {attrs}")
|
|
194
|
-
cell_str = "\n".join([f"{k}={v}" for k, v in attrs.items()])
|
|
195
|
-
style = doc.add_style(**attrs)
|
|
196
|
-
new_table.write(row, col, cell_str)
|
|
197
|
-
new_table.set_cell_style(row, col, style)
|
|
198
|
-
|
|
199
|
-
print(f"\n\n*** Saving {configurable_save_file} for visual check")
|
|
200
|
-
new_doc.save(configurable_save_file)
|
|
201
|
-
|
|
202
|
-
|
|
203
171
|
def test_all_style_changes(configurable_save_file):
|
|
204
172
|
# Flip styles and re-save as new custom styles
|
|
205
173
|
doc = Document("tests/data/test-styles.numbers")
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import plistlib
|
|
2
3
|
import runpy
|
|
3
4
|
import sys
|
|
5
|
+
import zipfile
|
|
4
6
|
from pathlib import Path
|
|
5
7
|
from unittest.mock import patch
|
|
6
8
|
|
|
@@ -8,6 +10,8 @@ import magic
|
|
|
8
10
|
import pytest
|
|
9
11
|
|
|
10
12
|
from numbers_parser import __version__
|
|
13
|
+
from numbers_parser._unpack_numbers import NumbersUnpacker
|
|
14
|
+
from numbers_parser.exceptions import FileFormatError
|
|
11
15
|
|
|
12
16
|
|
|
13
17
|
def test_version(script_runner):
|
|
@@ -195,8 +199,11 @@ def test_pretty_storage(script_runner, tmp_path):
|
|
|
195
199
|
with open(str(output_dir / "Index/Tables/Tile-875165.json")) as f:
|
|
196
200
|
data = json.load(f)
|
|
197
201
|
objects = data["chunks"][0]["archives"][0]["objects"][0]
|
|
198
|
-
|
|
199
|
-
assert
|
|
202
|
+
rowinfo = objects["rowInfos"][0]
|
|
203
|
+
assert rowinfo["cell_offsets"] == "-1,0,24,48,72,96,[...]"
|
|
204
|
+
assert rowinfo["cell_offsets_pre_bnc"] == "-1,0,20,40,60,80,[...]"
|
|
205
|
+
assert rowinfo["cell_storage_buffer"][0:26] == "05:03:00:00:00:00:00:00:08"
|
|
206
|
+
assert rowinfo["cell_storage_buffer_pre_bnc"][0:26] == "04:03:00:00:14:00:00:00:00"
|
|
200
207
|
|
|
201
208
|
|
|
202
209
|
def test_compact_json(script_runner, tmp_path):
|
|
@@ -287,3 +294,25 @@ def test_default_output_dir(script_runner, tmp_path):
|
|
|
287
294
|
assert ret.stdout == ""
|
|
288
295
|
assert ret.stderr == ""
|
|
289
296
|
assert Path.exists(tmp_path / "test-1/Metadata/Properties.plist")
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def test_unpack_path_traversal_prevention(tmp_path):
|
|
300
|
+
evil_file = tmp_path / "evil.numbers"
|
|
301
|
+
with zipfile.ZipFile(evil_file, "w") as z:
|
|
302
|
+
z.writestr("Metadata/Properties.plist", plistlib.dumps({}))
|
|
303
|
+
z.writestr("Metadata/BuildVersionHistory.plist", plistlib.dumps([]))
|
|
304
|
+
z.writestr("../escape_target/PWNED", b"marker")
|
|
305
|
+
|
|
306
|
+
output_dir = tmp_path / "out"
|
|
307
|
+
output_dir.mkdir()
|
|
308
|
+
escape_target_dir = tmp_path / "escape_target"
|
|
309
|
+
|
|
310
|
+
unpacker = NumbersUnpacker(output_dir=str(output_dir))
|
|
311
|
+
|
|
312
|
+
with pytest.raises(FileFormatError, match="Path traversal attempt detected"): # noqa: PT012, SIM117
|
|
313
|
+
with zipfile.ZipFile(evil_file, "r") as z:
|
|
314
|
+
for filename in z.namelist():
|
|
315
|
+
blob = z.read(filename)
|
|
316
|
+
unpacker.store_file(filename, blob)
|
|
317
|
+
|
|
318
|
+
assert not (escape_target_dir / "PWNED").exists()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TNArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TNArchives_sos_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSAArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSAArchives_sos_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCEArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCH3DArchives_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_GEN_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCHArchives_sos_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCKArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSCKArchives_sos_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSDArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSDArchives_sos_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSKArchives_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSPMessages_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSSArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSSArchives_sos_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSTArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSTArchives_sos_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSWPArchives_pb2.py
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser/generated/TSWPArchives_sos_pb2.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{numbers_parser-4.21.0 → numbers_parser-4.22.2}/src/numbers_parser.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|