numbers-parser 4.18.4__tar.gz → 4.19.0__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.18.4/src/numbers_parser.egg-info → numbers_parser-4.19.0}/PKG-INFO +1 -1
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/pyproject.toml +51 -42
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/_unpack_numbers.py +6 -3
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/cell.py +97 -65
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/constants.py +13 -8
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/containers.py +36 -1
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/currencies.py +13 -9
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/document.py +2 -4
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/iwork.py +12 -10
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/model.py +171 -128
- {numbers_parser-4.18.4 → numbers_parser-4.19.0/src/numbers_parser.egg-info}/PKG-INFO +1 -1
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_borders.py +76 -28
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_coverage.py +7 -18
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_issues.py +98 -7
- numbers_parser-4.19.0/tests/test_large.py +88 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_local_docs.py +29 -20
- numbers_parser-4.19.0/tests/test_memory_leaks.py +31 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_unpack_numbers.py +1 -4
- numbers_parser-4.18.4/tests/test_large.py +0 -39
- numbers_parser-4.18.4/tests/test_memory_leaks.py +0 -28
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/LICENSE.rst +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/README.md +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/setup.cfg +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/__init__.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/_cat_numbers.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/_csv2numbers.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/bullets.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/data/empty.numbers +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/exceptions.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/experimental.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/formula.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TNArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TNArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TNCommandArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TNCommandArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSAArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSAArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSACommandArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCEArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCH3DArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCHArchives_Common_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCHArchives_GEN_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCHArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCHArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCHCommandArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCHPreUFFArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCKArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSCKArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSDArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSDArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSDCommandArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSKArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSPArchiveMessages_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSPDatabaseMessages_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSPMessages_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSSArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSSArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSTArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSTArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSTCommandArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSTStylePropertyArchiving_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSWPArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSWPArchives_sos_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/TSWPCommandArchives_pb2.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/__init__.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/fontmap.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/functionmap.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/generated/mapping.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/iwafile.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/numbers_cache.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/numbers_uuid.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/roman.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser/xrefs.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser.egg-info/SOURCES.txt +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser.egg-info/dependency_links.txt +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser.egg-info/entry_points.txt +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser.egg-info/requires.txt +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/src/numbers_parser.egg-info/top_level.txt +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_all_formulas.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_api_change.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_bullets.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_cat_numbers.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_categories.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_create_cells.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_csv2numbers.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_currency.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_folder.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_formatting.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_formulas.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_merges.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_package.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_properties.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_roman.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_save.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_slices.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_styles.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_table_size.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_tables.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_unsupported.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_uuids.py +0 -0
- {numbers_parser-4.18.4 → numbers_parser-4.19.0}/tests/test_version.py +0 -0
|
@@ -22,7 +22,7 @@ classifiers = [
|
|
|
22
22
|
description = "Read and write Apple Numbers spreadsheets"
|
|
23
23
|
name = "numbers-parser"
|
|
24
24
|
readme = "README.md"
|
|
25
|
-
version = "4.
|
|
25
|
+
version = "4.19.0"
|
|
26
26
|
|
|
27
27
|
[project.urls]
|
|
28
28
|
repository = "https://github.com/masaccio/numbers-parser"
|
|
@@ -90,6 +90,14 @@ omit = ["src/numbers_parser/generated/*.py"]
|
|
|
90
90
|
directory = "coverage_html_report"
|
|
91
91
|
show_contexts = false
|
|
92
92
|
|
|
93
|
+
[tool.coverage.report]
|
|
94
|
+
exclude_lines = [
|
|
95
|
+
"pragma: no cover",
|
|
96
|
+
"raise NotImplementedError",
|
|
97
|
+
"if TYPE_CHECKING:",
|
|
98
|
+
"@abstractmethod",
|
|
99
|
+
]
|
|
100
|
+
|
|
93
101
|
[tool.pytest.ini_options]
|
|
94
102
|
addopts = "--cov=src/numbers_parser --cov-report=html --cov-report=term-missing:skip-covered"
|
|
95
103
|
|
|
@@ -129,51 +137,52 @@ fix = true
|
|
|
129
137
|
lint.ignore = [
|
|
130
138
|
"T201", # Allow print()
|
|
131
139
|
# To fix:
|
|
132
|
-
"ANN001", #Missing type annotation
|
|
133
|
-
"ANN002", #Missing type annotation
|
|
134
|
-
"ANN003", #Missing type annotation
|
|
135
|
-
"ANN201", #Missing return type annotation
|
|
136
|
-
"ANN202", #Missing return type annotation
|
|
137
|
-
"ANN204", #Missing return type annotation
|
|
138
|
-
"ANN205", #Missing return type annotation
|
|
139
|
-
"ANN206", #Missing return type annotation
|
|
140
|
-
"ANN401", #Dynamically typed expressions
|
|
141
|
-
"ARG001", #Unused function argument
|
|
142
|
-
"ARG002", #Unused method argument
|
|
143
|
-
"ARG003", #Unused class method argument
|
|
144
|
-
"BLE001", #Do not catch blind exception
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
140
|
+
"ANN001", # Missing type annotation
|
|
141
|
+
"ANN002", # Missing type annotation
|
|
142
|
+
"ANN003", # Missing type annotation
|
|
143
|
+
"ANN201", # Missing return type annotation
|
|
144
|
+
"ANN202", # Missing return type annotation
|
|
145
|
+
"ANN204", # Missing return type annotation
|
|
146
|
+
"ANN205", # Missing return type annotation
|
|
147
|
+
"ANN206", # Missing return type annotation
|
|
148
|
+
"ANN401", # Dynamically typed expressions
|
|
149
|
+
"ARG001", # Unused function argument
|
|
150
|
+
"ARG002", # Unused method argument
|
|
151
|
+
"ARG003", # Unused class method argument
|
|
152
|
+
"BLE001", # Do not catch blind exception
|
|
153
|
+
"CPY001", # Copyright
|
|
154
|
+
"C901", # Code too complex
|
|
155
|
+
"D100", # Missing docstring
|
|
156
|
+
"D101", # Missing docstring
|
|
157
|
+
"D102", # Missing docstring
|
|
158
|
+
"D103", # Missing docstring
|
|
159
|
+
"D105", # Missing docstring
|
|
160
|
+
"D107", # Missing docstring
|
|
152
161
|
"D205", # Blank line - conflicts with black
|
|
153
|
-
"D210", #No whitespaces allowed surrounding docstring text
|
|
154
|
-
"D400", #First line should end with a period
|
|
155
|
-
"D401", #First line of docstring should be in imperative mood
|
|
156
|
-
"D415", #First line should end with a period, question mark, or exclamation point
|
|
157
|
-
"E501", #Line too long
|
|
158
|
-
"ERA001", #
|
|
159
|
-
"FBT001", #Boolean-typed positional argument in function definition
|
|
160
|
-
"FBT002", #Boolean default positional argument in function definition
|
|
161
|
-
"FBT003", #Boolean positional value in function call
|
|
162
|
-
"FIX002", #Line contains TODO, consider resolving the issue
|
|
163
|
-
"ISC003", #Explicitly concatenated string should be implicitly concatenated
|
|
164
|
-
"PERF401", #Use a list comprehension to create a transformed list
|
|
165
|
-
"PLR0913", #Too many arguments
|
|
166
|
-
"PLR2004", #Magic value used
|
|
167
|
-
"PLW0603", #Using the global statement
|
|
162
|
+
"D210", # No whitespaces allowed surrounding docstring text
|
|
163
|
+
"D400", # First line should end with a period
|
|
164
|
+
"D401", # First line of docstring should be in imperative mood
|
|
165
|
+
"D415", # First line should end with a period, question mark, or exclamation point
|
|
166
|
+
"E501", # Line too long
|
|
167
|
+
"ERA001", # Remove commented out code
|
|
168
|
+
"FBT001", # Boolean-typed positional argument in function definition
|
|
169
|
+
"FBT002", # Boolean default positional argument in function definition
|
|
170
|
+
"FBT003", # Boolean positional value in function call
|
|
171
|
+
"FIX002", # Line contains TODO, consider resolving the issue
|
|
172
|
+
"ISC003", # Explicitly concatenated string should be implicitly concatenated
|
|
173
|
+
"PERF401", # Use a list comprehension to create a transformed list
|
|
174
|
+
"PLR0913", # Too many arguments
|
|
175
|
+
"PLR2004", # Magic value used
|
|
176
|
+
"PLW0603", # Using the global statement
|
|
168
177
|
"PTH103", # Use of os.makedirs()
|
|
169
178
|
"PTH118", # Use of os.path.join()
|
|
170
179
|
"PTH119", # Use of os.path.basename()
|
|
171
180
|
"PTH123", # Use of open()
|
|
172
|
-
"RUF001", #String contains ambiguous
|
|
173
|
-
"RUF002", #Docstring contains ambiguous
|
|
174
|
-
"RUF003", #Comment contains ambiguous
|
|
175
|
-
"SIM115", #Use a context manager for opening files
|
|
176
|
-
"SLF001", #Private member accessed
|
|
181
|
+
"RUF001", # String contains ambiguous
|
|
182
|
+
"RUF002", # Docstring contains ambiguous
|
|
183
|
+
"RUF003", # Comment contains ambiguous
|
|
184
|
+
"SIM115", # Use a context manager for opening files
|
|
185
|
+
"SLF001", # Private member accessed
|
|
177
186
|
"TD002", # TODO author
|
|
178
187
|
"TD003", # TODO author
|
|
179
188
|
# Conflicts with other rules
|
|
@@ -187,7 +196,7 @@ lint.unfixable = [
|
|
|
187
196
|
]
|
|
188
197
|
line-length = 100
|
|
189
198
|
src = ["src", "tests"]
|
|
190
|
-
target-version = "
|
|
199
|
+
target-version = "py310"
|
|
191
200
|
|
|
192
201
|
[tool.ruff.lint.pylint]
|
|
193
202
|
max-statements = 100
|
|
@@ -63,6 +63,9 @@ class NumbersUnpacker(IWorkHandler):
|
|
|
63
63
|
with open(target_path, "wb") as out:
|
|
64
64
|
out.write(blob)
|
|
65
65
|
|
|
66
|
+
def store_object(self, filename: str, identifier: int, archive: object) -> None:
|
|
67
|
+
pass
|
|
68
|
+
|
|
66
69
|
def ensure_directory_exists(self, path: str) -> None:
|
|
67
70
|
"""Ensure that a path's directory exists."""
|
|
68
71
|
parts = os.path.split(path)
|
|
@@ -143,9 +146,9 @@ def main() -> None:
|
|
|
143
146
|
elif len(args.document) == 0:
|
|
144
147
|
parser.print_help()
|
|
145
148
|
else:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
logger.addHandler(
|
|
149
|
+
handler = logging.StreamHandler()
|
|
150
|
+
handler.setFormatter(logging.Formatter("%(levelname)s:%(name)s:%(message)s"))
|
|
151
|
+
logger.addHandler(handler)
|
|
149
152
|
if args.debug:
|
|
150
153
|
logger.setLevel("DEBUG")
|
|
151
154
|
else:
|
|
@@ -52,10 +52,12 @@ from numbers_parser.constants import (
|
|
|
52
52
|
FormatType,
|
|
53
53
|
FractionAccuracy,
|
|
54
54
|
NegativeNumberStyle,
|
|
55
|
+
NumberFormatConditionType,
|
|
55
56
|
PaddingType,
|
|
56
57
|
)
|
|
57
58
|
from numbers_parser.currencies import CURRENCIES, CURRENCY_SYMBOLS
|
|
58
59
|
from numbers_parser.exceptions import UnsupportedError, UnsupportedWarning
|
|
60
|
+
from numbers_parser.generated import TSKArchives_pb2 as TSKArchives
|
|
59
61
|
from numbers_parser.generated import TSPMessages_pb2 as TSPMessages
|
|
60
62
|
from numbers_parser.generated import TSTArchives_pb2 as TSTArchives
|
|
61
63
|
from numbers_parser.generated.TSWPArchives_pb2 import (
|
|
@@ -407,7 +409,8 @@ class BorderType(IntEnum):
|
|
|
407
409
|
NONE = BORDER_STYLE_MAP["none"]
|
|
408
410
|
|
|
409
411
|
|
|
410
|
-
|
|
412
|
+
@dataclass(frozen=True)
|
|
413
|
+
class Border: # noqa: PLW1641
|
|
411
414
|
"""
|
|
412
415
|
Create a cell border to use with the :py:class:`~numbers_parser.Table` method
|
|
413
416
|
:py:meth:`~numbers_parser.Table.set_cell_border`.
|
|
@@ -439,40 +442,51 @@ class Border:
|
|
|
439
442
|
|
|
440
443
|
"""
|
|
441
444
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
) -> None:
|
|
449
|
-
if not isinstance(width, float):
|
|
445
|
+
width: float = DEFAULT_BORDER_WIDTH
|
|
446
|
+
color: RGB = None
|
|
447
|
+
style: BorderType = None
|
|
448
|
+
|
|
449
|
+
def __post_init__(self) -> None:
|
|
450
|
+
if not isinstance(self.width, float):
|
|
450
451
|
msg = "width must be a float number of points"
|
|
451
452
|
raise TypeError(msg)
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
color = RGB(*DEFAULT_BORDER_COLOR)
|
|
456
|
-
self.color = rgb_color(color)
|
|
457
|
-
|
|
458
|
-
if style is None:
|
|
459
|
-
style = BorderType(BORDER_STYLE_MAP[DEFAULT_BORDER_STYLE])
|
|
460
|
-
if isinstance(style, str):
|
|
461
|
-
style = style.lower()
|
|
462
|
-
if style not in BORDER_STYLE_MAP:
|
|
463
|
-
msg = "invalid border style"
|
|
464
|
-
raise TypeError(msg)
|
|
465
|
-
self.style = BORDER_STYLE_MAP[style]
|
|
453
|
+
|
|
454
|
+
if self.color is None:
|
|
455
|
+
object.__setattr__(self, "color", RGB(*DEFAULT_BORDER_COLOR))
|
|
466
456
|
else:
|
|
467
|
-
self
|
|
457
|
+
object.__setattr__(self, "color", rgb_color(self.color))
|
|
458
|
+
|
|
459
|
+
current_style = self.style
|
|
460
|
+
if current_style is None:
|
|
461
|
+
# Default fallback
|
|
462
|
+
current_style = BorderType(BORDER_STYLE_MAP[DEFAULT_BORDER_STYLE])
|
|
463
|
+
|
|
464
|
+
elif isinstance(current_style, str):
|
|
465
|
+
# String conversion (e.g., "dashes" -> BorderType.DASHES)
|
|
466
|
+
current_style = current_style.lower()
|
|
467
|
+
if current_style not in BORDER_STYLE_MAP:
|
|
468
|
+
msg = f"invalid border style: '{current_style}'"
|
|
469
|
+
raise TypeError(msg)
|
|
470
|
+
current_style = BorderType(BORDER_STYLE_MAP[current_style])
|
|
471
|
+
elif not isinstance(current_style, BorderType):
|
|
472
|
+
try:
|
|
473
|
+
current_style = BorderType(current_style)
|
|
474
|
+
except ValueError as e:
|
|
475
|
+
msg = f"invalid border style value: {current_style}"
|
|
476
|
+
raise TypeError(msg) from e
|
|
477
|
+
|
|
478
|
+
object.__setattr__(self, "style", current_style)
|
|
468
479
|
|
|
469
|
-
|
|
480
|
+
def __repr__(self):
|
|
481
|
+
return str(self)
|
|
470
482
|
|
|
471
483
|
def __str__(self) -> str:
|
|
472
484
|
style_name = BorderType(self.style).name.lower()
|
|
473
485
|
return f"Border(width={self.width}, color={self.color}, style={style_name})"
|
|
474
486
|
|
|
475
487
|
def __eq__(self, value: object) -> bool:
|
|
488
|
+
if value is None:
|
|
489
|
+
return False
|
|
476
490
|
return all(
|
|
477
491
|
[self.width == value.width, self.color == value.color, self.style == value.style],
|
|
478
492
|
)
|
|
@@ -503,8 +517,7 @@ class CellBorder:
|
|
|
503
517
|
|
|
504
518
|
@top.setter
|
|
505
519
|
def top(self, value) -> None:
|
|
506
|
-
|
|
507
|
-
self._top = value
|
|
520
|
+
self._top = value
|
|
508
521
|
|
|
509
522
|
@property
|
|
510
523
|
def right(self):
|
|
@@ -514,8 +527,7 @@ class CellBorder:
|
|
|
514
527
|
|
|
515
528
|
@right.setter
|
|
516
529
|
def right(self, value) -> None:
|
|
517
|
-
|
|
518
|
-
self._right = value
|
|
530
|
+
self._right = value
|
|
519
531
|
|
|
520
532
|
@property
|
|
521
533
|
def bottom(self):
|
|
@@ -525,8 +537,7 @@ class CellBorder:
|
|
|
525
537
|
|
|
526
538
|
@bottom.setter
|
|
527
539
|
def bottom(self, value) -> None:
|
|
528
|
-
|
|
529
|
-
self._bottom = value
|
|
540
|
+
self._bottom = value
|
|
530
541
|
|
|
531
542
|
@property
|
|
532
543
|
def left(self):
|
|
@@ -536,8 +547,7 @@ class CellBorder:
|
|
|
536
547
|
|
|
537
548
|
@left.setter
|
|
538
549
|
def left(self, value) -> None:
|
|
539
|
-
|
|
540
|
-
self._left = value
|
|
550
|
+
self._left = value
|
|
541
551
|
|
|
542
552
|
|
|
543
553
|
class MergeReference:
|
|
@@ -562,7 +572,6 @@ class CellStorageFlags:
|
|
|
562
572
|
_text_style_id: int = None
|
|
563
573
|
_formula_id: int = None
|
|
564
574
|
_control_id: int = None
|
|
565
|
-
_formula_error_id: int = None
|
|
566
575
|
_suggest_id: int = None
|
|
567
576
|
_num_format_id: int = None
|
|
568
577
|
_currency_format_id: int = None
|
|
@@ -877,7 +886,7 @@ class Cell(CellStorageFlags, Cacheable):
|
|
|
877
886
|
storage_flags._control_id = unpack("<i", buffer[offset : offset + 4])[0]
|
|
878
887
|
offset += 4
|
|
879
888
|
if flags & 0x800:
|
|
880
|
-
|
|
889
|
+
# formula_error_id skipped
|
|
881
890
|
offset += 4
|
|
882
891
|
if flags & 0x1000:
|
|
883
892
|
storage_flags._suggest_id = unpack("<i", buffer[offset : offset + 4])[0]
|
|
@@ -975,7 +984,8 @@ class Cell(CellStorageFlags, Cacheable):
|
|
|
975
984
|
self.size = (1, 1)
|
|
976
985
|
self.merge_range = None
|
|
977
986
|
self.rect = None
|
|
978
|
-
self
|
|
987
|
+
if getattr(self, "_border", None) is None:
|
|
988
|
+
self._border = CellBorder()
|
|
979
989
|
|
|
980
990
|
def _to_buffer(self) -> bytearray: # noqa: PLR0912, PLR0915
|
|
981
991
|
"""Create a storage buffer for a cell using v5 (modern) layout."""
|
|
@@ -1141,12 +1151,8 @@ class Cell(CellStorageFlags, Cacheable):
|
|
|
1141
1151
|
|
|
1142
1152
|
image_id = style.cell_properties.cell_fill.image.imagedata.identifier
|
|
1143
1153
|
datas = self._model.objects[PACKAGE_ID].datas
|
|
1144
|
-
stored_filename = next(
|
|
1145
|
-
|
|
1146
|
-
) # pragma: nocover (issue-1333)
|
|
1147
|
-
preferred_filename = next(
|
|
1148
|
-
x.preferred_file_name for x in datas if x.identifier == image_id
|
|
1149
|
-
) # pragma: nocover (issue-1333)
|
|
1154
|
+
stored_filename = next(x.file_name for x in datas if x.identifier == image_id)
|
|
1155
|
+
preferred_filename = next(x.preferred_file_name for x in datas if x.identifier == image_id)
|
|
1150
1156
|
all_paths = self._model.objects.file_store.keys()
|
|
1151
1157
|
image_pathnames = [x for x in all_paths if x == f"Data/{stored_filename}"]
|
|
1152
1158
|
|
|
@@ -1199,6 +1205,7 @@ class Cell(CellStorageFlags, Cacheable):
|
|
|
1199
1205
|
custom_format,
|
|
1200
1206
|
self._d128,
|
|
1201
1207
|
format_map[format_uuid].name,
|
|
1208
|
+
format_map[format_uuid].conditions,
|
|
1202
1209
|
)
|
|
1203
1210
|
elif custom_format.format_type == FormatType.DECIMAL:
|
|
1204
1211
|
return _format_decimal(self._d128, custom_format)
|
|
@@ -1571,16 +1578,6 @@ def _unpack_decimal128(buffer: bytearray) -> float:
|
|
|
1571
1578
|
return float(value)
|
|
1572
1579
|
|
|
1573
1580
|
|
|
1574
|
-
def _decode_date_format_field(field: str, value: datetime) -> str:
|
|
1575
|
-
if field in DATETIME_FIELD_MAP:
|
|
1576
|
-
s = DATETIME_FIELD_MAP[field]
|
|
1577
|
-
if callable(s):
|
|
1578
|
-
return s(value)
|
|
1579
|
-
return value.strftime(s)
|
|
1580
|
-
warn(f"Unsupported field code '{field}'", UnsupportedWarning, stacklevel=4)
|
|
1581
|
-
return ""
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
1581
|
def _decode_date_format(date_format, value):
|
|
1585
1582
|
"""Parse a custom date format string and return a formatted datetime value."""
|
|
1586
1583
|
chars = [*date_format]
|
|
@@ -1609,6 +1606,7 @@ def _decode_date_format(date_format, value):
|
|
|
1609
1606
|
elif current_char.isalpha():
|
|
1610
1607
|
remaining_str = date_format[index:]
|
|
1611
1608
|
matched_field = None
|
|
1609
|
+
|
|
1612
1610
|
for field in DATETIME_FIELD_MAP:
|
|
1613
1611
|
# Greedily match the longest possible valid field
|
|
1614
1612
|
if remaining_str.startswith(field):
|
|
@@ -1616,14 +1614,18 @@ def _decode_date_format(date_format, value):
|
|
|
1616
1614
|
break
|
|
1617
1615
|
|
|
1618
1616
|
if matched_field:
|
|
1619
|
-
|
|
1617
|
+
s = DATETIME_FIELD_MAP[field]
|
|
1618
|
+
if callable(s):
|
|
1619
|
+
result += s(value)
|
|
1620
|
+
else:
|
|
1621
|
+
result += value.strftime(s)
|
|
1620
1622
|
index += len(matched_field)
|
|
1621
1623
|
else:
|
|
1622
1624
|
unknown_field = ""
|
|
1623
1625
|
while index < len(chars) and chars[index].isalpha():
|
|
1624
1626
|
unknown_field += chars[index]
|
|
1625
1627
|
index += 1
|
|
1626
|
-
|
|
1628
|
+
warn(f"Unsupported field code '{unknown_field}'", UnsupportedWarning, stacklevel=4)
|
|
1627
1629
|
else:
|
|
1628
1630
|
result += current_char
|
|
1629
1631
|
index += 1
|
|
@@ -1663,12 +1665,48 @@ def _expand_quotes(value: str) -> str:
|
|
|
1663
1665
|
return formatted_value
|
|
1664
1666
|
|
|
1665
1667
|
|
|
1666
|
-
def _decode_number_format(
|
|
1668
|
+
def _decode_number_format( # noqa: PLR0912
|
|
1669
|
+
number_format: TSKArchives.FormatStructArchive,
|
|
1670
|
+
value: float,
|
|
1671
|
+
name: str,
|
|
1672
|
+
conditions: list[TSKArchives.CustomFormatArchive.Condition],
|
|
1673
|
+
):
|
|
1667
1674
|
"""Parse a custom date format string and return a formatted number value."""
|
|
1668
1675
|
if value is None:
|
|
1669
1676
|
return None
|
|
1670
1677
|
|
|
1671
1678
|
custom_format_string = number_format.custom_format_string
|
|
1679
|
+
sign = "-" if value < 0 else ""
|
|
1680
|
+
for condition in conditions:
|
|
1681
|
+
value_sigfig = sigfig(value, sigfigs=MAX_SIGNIFICANT_DIGITS, warn=False)
|
|
1682
|
+
if (
|
|
1683
|
+
(
|
|
1684
|
+
condition.condition_type == NumberFormatConditionType.EQUAL
|
|
1685
|
+
and value_sigfig == condition.condition_value_dbl
|
|
1686
|
+
)
|
|
1687
|
+
or (
|
|
1688
|
+
condition.condition_type == NumberFormatConditionType.LESS_THAN
|
|
1689
|
+
and value_sigfig < condition.condition_value_dbl
|
|
1690
|
+
)
|
|
1691
|
+
or (
|
|
1692
|
+
condition.condition_type == NumberFormatConditionType.LESS_THAN_OR_EQUAL_TO
|
|
1693
|
+
and value_sigfig <= condition.condition_value_dbl
|
|
1694
|
+
)
|
|
1695
|
+
or (
|
|
1696
|
+
condition.condition_type == NumberFormatConditionType.GREATER_THAN
|
|
1697
|
+
and value_sigfig > condition.condition_value_dbl
|
|
1698
|
+
)
|
|
1699
|
+
or (
|
|
1700
|
+
condition.condition_type == NumberFormatConditionType.GREATER_THAN_OR_EQUAL_TO
|
|
1701
|
+
and value_sigfig >= condition.condition_value_dbl
|
|
1702
|
+
)
|
|
1703
|
+
):
|
|
1704
|
+
custom_format_string = condition.condition_format.custom_format_string
|
|
1705
|
+
# Numbers discards sign when rules apply
|
|
1706
|
+
sign = ""
|
|
1707
|
+
break
|
|
1708
|
+
|
|
1709
|
+
value = abs(value)
|
|
1672
1710
|
value *= number_format.scale_factor
|
|
1673
1711
|
if "%" in custom_format_string and number_format.scale_factor == 1.0:
|
|
1674
1712
|
# Per cent scale has 100x but % does not
|
|
@@ -1682,12 +1720,8 @@ def _decode_number_format(number_format, value, name): # noqa: PLR0912
|
|
|
1682
1720
|
)
|
|
1683
1721
|
|
|
1684
1722
|
if (match := re.search(r"([#0.,]+(E[+]\d+)?)", custom_format_string)) is None:
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
UnsupportedWarning,
|
|
1688
|
-
stacklevel=1,
|
|
1689
|
-
)
|
|
1690
|
-
return str(value)
|
|
1723
|
+
# Value is not part of the format
|
|
1724
|
+
return _expand_quotes(custom_format_string)
|
|
1691
1725
|
|
|
1692
1726
|
format_spec = match.group(1)
|
|
1693
1727
|
scientific_spec = match.group(2)
|
|
@@ -1794,7 +1828,7 @@ def _decode_number_format(number_format, value, name): # noqa: PLR0912
|
|
|
1794
1828
|
formatted_value += "." + str(decimal)[2:]
|
|
1795
1829
|
|
|
1796
1830
|
formatted_value = custom_format_string.replace(format_spec, formatted_value)
|
|
1797
|
-
return _expand_quotes(formatted_value)
|
|
1831
|
+
return sign + _expand_quotes(formatted_value)
|
|
1798
1832
|
|
|
1799
1833
|
|
|
1800
1834
|
def _format_decimal(value: float, number_format, percent: bool = False) -> str:
|
|
@@ -1927,9 +1961,7 @@ def _float_to_n_digit_fraction(value: float, max_digits: int) -> str:
|
|
|
1927
1961
|
and return as a string.
|
|
1928
1962
|
"""
|
|
1929
1963
|
max_denominator = 10**max_digits - 1
|
|
1930
|
-
(numerator, denominator) = (
|
|
1931
|
-
Fraction.from_float(value).limit_denominator(max_denominator).as_integer_ratio()
|
|
1932
|
-
)
|
|
1964
|
+
(numerator, denominator) = Fraction(value).limit_denominator(max_denominator).as_integer_ratio()
|
|
1933
1965
|
whole = int(value)
|
|
1934
1966
|
numerator -= whole * denominator
|
|
1935
1967
|
return _format_fraction_parts_to(whole, numerator, denominator)
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from enum import IntEnum
|
|
3
|
+
from importlib.resources import files
|
|
3
4
|
from math import ceil
|
|
4
5
|
|
|
5
6
|
import enum_tools.documentation
|
|
6
7
|
|
|
7
|
-
# Path to package data varies by Python version so we can
|
|
8
|
-
# only ever generate coverage for one
|
|
9
|
-
try:
|
|
10
|
-
from importlib.resources import files
|
|
11
|
-
except ImportError: # pragma: nocover
|
|
12
|
-
from importlib_resources import files
|
|
13
|
-
|
|
14
8
|
__all__ = [
|
|
15
9
|
"CellPadding",
|
|
16
10
|
"CellType",
|
|
@@ -103,6 +97,8 @@ SUPPORTED_NUMBERS_VERSIONS = [
|
|
|
103
97
|
# Numbers Creator Studio
|
|
104
98
|
"26.0",
|
|
105
99
|
"26.1",
|
|
100
|
+
"26.2",
|
|
101
|
+
"26.3",
|
|
106
102
|
]
|
|
107
103
|
|
|
108
104
|
|
|
@@ -156,7 +152,7 @@ _DATETIME_FIELD_MAP = {
|
|
|
156
152
|
"W": lambda x: str(_week_of_month(x) - 1),
|
|
157
153
|
"ww": "%W",
|
|
158
154
|
"G": "AD", # TODO: support BC
|
|
159
|
-
"F":
|
|
155
|
+
"F": _days_occurred_in_month,
|
|
160
156
|
"S": lambda x: str(x.microsecond).zfill(6)[0],
|
|
161
157
|
"SS": lambda x: str(x.microsecond).zfill(6)[0:2],
|
|
162
158
|
"SSS": lambda x: str(x.microsecond).zfill(6)[0:3],
|
|
@@ -417,6 +413,15 @@ class CellInteractionType(IntEnum):
|
|
|
417
413
|
TOGGLE = 8
|
|
418
414
|
|
|
419
415
|
|
|
416
|
+
class NumberFormatConditionType(IntEnum):
|
|
417
|
+
NONE = -1
|
|
418
|
+
EQUAL = 0
|
|
419
|
+
LESS_THAN = 1
|
|
420
|
+
LESS_THAN_OR_EQUAL_TO = 2
|
|
421
|
+
GREATER_THAN = 3
|
|
422
|
+
GREATER_THAN_OR_EQUAL_TO = 4
|
|
423
|
+
|
|
424
|
+
|
|
420
425
|
class CellValueType(IntEnum):
|
|
421
426
|
NIL_TYPE = 1
|
|
422
427
|
BOOLEAN_TYPE = 2
|
|
@@ -2,7 +2,7 @@ import math
|
|
|
2
2
|
import re
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from numbers_parser.constants import PACKAGE_ID, SUPPORTED_NUMBERS_VERSIONS
|
|
5
|
+
from numbers_parser.constants import DOCUMENT_ID, PACKAGE_ID, SUPPORTED_NUMBERS_VERSIONS
|
|
6
6
|
from numbers_parser.iwafile import IWAFile, copy_object_to_iwa_file, create_iwa_segment
|
|
7
7
|
from numbers_parser.iwork import IWork, IWorkHandler
|
|
8
8
|
|
|
@@ -112,6 +112,41 @@ class ObjectStore(IWorkHandler):
|
|
|
112
112
|
obj_id,
|
|
113
113
|
)
|
|
114
114
|
|
|
115
|
+
def remove_unreferenced_objects(self) -> None:
|
|
116
|
+
"""Removes all objects from the ObjectStore that are not referenced."""
|
|
117
|
+
referenced_ids = {DOCUMENT_ID, PACKAGE_ID}
|
|
118
|
+
|
|
119
|
+
def find_references(msg):
|
|
120
|
+
"""Recursively find all TSP.Reference messages in protobuf."""
|
|
121
|
+
if hasattr(msg, "identifier") and msg.DESCRIPTOR.name == "Reference":
|
|
122
|
+
referenced_ids.add(msg.identifier)
|
|
123
|
+
|
|
124
|
+
for field_desc, value in msg.ListFields():
|
|
125
|
+
if field_desc.type != field_desc.TYPE_MESSAGE:
|
|
126
|
+
continue
|
|
127
|
+
if field_desc.is_repeated:
|
|
128
|
+
for item in value:
|
|
129
|
+
find_references(item)
|
|
130
|
+
else:
|
|
131
|
+
find_references(value)
|
|
132
|
+
|
|
133
|
+
for obj in self._objects.values():
|
|
134
|
+
find_references(obj)
|
|
135
|
+
|
|
136
|
+
unreferenced_ids = set(self._objects.keys()) - referenced_ids
|
|
137
|
+
unreferenced_ids -= {c.identifier for c in self._objects[PACKAGE_ID].components}
|
|
138
|
+
|
|
139
|
+
# Delete unreferenced archives. In principal we could delete unreferenced files,
|
|
140
|
+
# but deleting tables/sheets is unsupported so this never happens.
|
|
141
|
+
for obj_id in unreferenced_ids:
|
|
142
|
+
del self._objects[obj_id]
|
|
143
|
+
filename = self._object_to_filename_map.pop(obj_id)
|
|
144
|
+
iwa_file = self._file_store[filename]
|
|
145
|
+
for chunk in iwa_file.chunks:
|
|
146
|
+
chunk.archives = [
|
|
147
|
+
arch for arch in chunk.archives if arch.header.identifier != obj_id
|
|
148
|
+
]
|
|
149
|
+
|
|
115
150
|
@property
|
|
116
151
|
def file_store(self):
|
|
117
152
|
return self._file_store
|
|
@@ -53,7 +53,6 @@ CURRENCIES = [
|
|
|
53
53
|
"BUK",
|
|
54
54
|
"BWP",
|
|
55
55
|
"BYB",
|
|
56
|
-
"BYN",
|
|
57
56
|
"BYR",
|
|
58
57
|
"BZD",
|
|
59
58
|
"CAD",
|
|
@@ -64,7 +63,6 @@ CURRENCIES = [
|
|
|
64
63
|
"CLE",
|
|
65
64
|
"CLF",
|
|
66
65
|
"CLP",
|
|
67
|
-
"CNH",
|
|
68
66
|
"CNX",
|
|
69
67
|
"CNY",
|
|
70
68
|
"COP",
|
|
@@ -87,7 +85,6 @@ CURRENCIES = [
|
|
|
87
85
|
"ECV",
|
|
88
86
|
"EEK",
|
|
89
87
|
"EGP",
|
|
90
|
-
"EQE",
|
|
91
88
|
"ERN",
|
|
92
89
|
"ESA",
|
|
93
90
|
"ESB",
|
|
@@ -149,7 +146,6 @@ CURRENCIES = [
|
|
|
149
146
|
"LKR",
|
|
150
147
|
"LRD",
|
|
151
148
|
"LSL",
|
|
152
|
-
"LSM",
|
|
153
149
|
"LTL",
|
|
154
150
|
"LTT",
|
|
155
151
|
"LUC",
|
|
@@ -172,7 +168,6 @@ CURRENCIES = [
|
|
|
172
168
|
"MNT",
|
|
173
169
|
"MOP",
|
|
174
170
|
"MRO",
|
|
175
|
-
"MRU",
|
|
176
171
|
"MTL",
|
|
177
172
|
"MTP",
|
|
178
173
|
"MUR",
|
|
@@ -225,14 +220,12 @@ CURRENCIES = [
|
|
|
225
220
|
"SHP",
|
|
226
221
|
"SIT",
|
|
227
222
|
"SKK",
|
|
228
|
-
"SLE",
|
|
229
223
|
"SLL",
|
|
230
224
|
"SOS",
|
|
231
225
|
"SRD",
|
|
232
226
|
"SRG",
|
|
233
227
|
"SSP",
|
|
234
228
|
"STD",
|
|
235
|
-
"STN",
|
|
236
229
|
"SUR",
|
|
237
230
|
"SVC",
|
|
238
231
|
"SYP",
|
|
@@ -260,11 +253,9 @@ CURRENCIES = [
|
|
|
260
253
|
"UYI",
|
|
261
254
|
"UYP",
|
|
262
255
|
"UYU",
|
|
263
|
-
"UYW ",
|
|
264
256
|
"UZS",
|
|
265
257
|
"VEB",
|
|
266
258
|
"VEF",
|
|
267
|
-
"VES",
|
|
268
259
|
"VND",
|
|
269
260
|
"VNN",
|
|
270
261
|
"VUV",
|
|
@@ -305,6 +296,18 @@ CURRENCIES = [
|
|
|
305
296
|
"ZWD",
|
|
306
297
|
"ZWL",
|
|
307
298
|
"ZWR",
|
|
299
|
+
"BYN",
|
|
300
|
+
"CNH",
|
|
301
|
+
"STN",
|
|
302
|
+
"EQE",
|
|
303
|
+
"LSM",
|
|
304
|
+
"MRU",
|
|
305
|
+
"UYW",
|
|
306
|
+
"VES",
|
|
307
|
+
"SLE",
|
|
308
|
+
"VED",
|
|
309
|
+
"XCG",
|
|
310
|
+
"ZWG",
|
|
308
311
|
]
|
|
309
312
|
|
|
310
313
|
CURRENCY_SYMBOLS = {
|
|
@@ -321,6 +324,7 @@ CURRENCY_SYMBOLS = {
|
|
|
321
324
|
"KRW": "₩",
|
|
322
325
|
"MXN": "MX$",
|
|
323
326
|
"NZD": "NZ$",
|
|
327
|
+
"THB": "฿",
|
|
324
328
|
"TWD": "NT$",
|
|
325
329
|
"USD": "$",
|
|
326
330
|
"VND": "₫",
|