tableio 0.1__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.
- tableio-0.1/LICENSE.txt +22 -0
- tableio-0.1/PKG-INFO +109 -0
- tableio-0.1/README.md +105 -0
- tableio-0.1/README_pypi.md +83 -0
- tableio-0.1/pyproject.toml +24 -0
- tableio-0.1/setup.cfg +4 -0
- tableio-0.1/setup.py +26 -0
- tableio-0.1/src/tableio/__init__.py +6 -0
- tableio-0.1/src/tableio/capability.py +156 -0
- tableio-0.1/src/tableio/color.py +20 -0
- tableio-0.1/src/tableio/factory.py +807 -0
- tableio-0.1/src/tableio/optional_args.py +77 -0
- tableio-0.1/src/tableio/py.typed +0 -0
- tableio-0.1/src/tableio/reg_pkg_formats.py +30 -0
- tableio-0.1/src/tableio/tableio.py +780 -0
- tableio-0.1/src/tableio/tableio_csv.py +420 -0
- tableio-0.1/src/tableio/tableio_excel_openpyxl.py +630 -0
- tableio-0.1/src/tableio/tableio_excelbased.py +47 -0
- tableio-0.1/src/tableio/tableio_mformat.py +562 -0
- tableio-0.1/src/tableio/tableio_mformatbased.py +277 -0
- tableio-0.1/src/tableio/tableio_spreadsheetbased.py +46 -0
- tableio-0.1/src/tableio/tableio_textbased.py +137 -0
- tableio-0.1/src/tableio/value_type.py +621 -0
- tableio-0.1/tableio.egg-info/PKG-INFO +109 -0
- tableio-0.1/tableio.egg-info/SOURCES.txt +26 -0
- tableio-0.1/tableio.egg-info/dependency_links.txt +1 -0
- tableio-0.1/tableio.egg-info/requires.txt +7 -0
- tableio-0.1/tableio.egg-info/top_level.txt +1 -0
tableio-0.1/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tom Björkholm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
tableio-0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tableio
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Uniform way to write table data to and read from different file formats
|
|
5
|
+
Author: Tom Björkholm
|
|
6
|
+
Author-email: Tom Björkholm <klausuler_linnet0q@icloud.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Source code, https://bitbucket.org/tom-bjorkholm/table-io
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE.txt
|
|
15
|
+
Requires-Dist: pip>=26.0.1
|
|
16
|
+
Requires-Dist: setuptools>=82.0.1
|
|
17
|
+
Requires-Dist: build>=1.4.0
|
|
18
|
+
Requires-Dist: wheel>=0.46.3
|
|
19
|
+
Requires-Dist: mformat-ext>=0.6
|
|
20
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
21
|
+
Requires-Dist: types-openpyxl>=3.1.5.20260322
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
|
|
27
|
+
# tableio
|
|
28
|
+
|
|
29
|
+
The tableio package contains a number of classes providing a uniform way for
|
|
30
|
+
a python program to write table data (rows of columns) to and read table data
|
|
31
|
+
from a number of different common file formats.
|
|
32
|
+
|
|
33
|
+
The primary intended use is for text output from a python program, where the
|
|
34
|
+
programmer would like the user to be able to select the input and output file
|
|
35
|
+
formats.
|
|
36
|
+
|
|
37
|
+
The support for spreadsheets is for reading and writing data. There is no
|
|
38
|
+
intention to support reading or writing formulas. There is no support for
|
|
39
|
+
running calculations in the spreadsheets (although nothing will stop a
|
|
40
|
+
receiver of a spreadsheet created by tableio package to manually add
|
|
41
|
+
formulas in the received spreadsheet).
|
|
42
|
+
|
|
43
|
+
## Early design phase
|
|
44
|
+
|
|
45
|
+
This project is in an early design phase. This means that major changes to the APIs are still expected.
|
|
46
|
+
|
|
47
|
+
## Installing tableio
|
|
48
|
+
|
|
49
|
+
### Installing tableio on mac and Linux
|
|
50
|
+
|
|
51
|
+
````sh
|
|
52
|
+
pip3 install --upgrade tableio
|
|
53
|
+
````
|
|
54
|
+
|
|
55
|
+
### Installing tableio on Microsoft Windows
|
|
56
|
+
|
|
57
|
+
````sh
|
|
58
|
+
pip install --upgrade tableio
|
|
59
|
+
````
|
|
60
|
+
|
|
61
|
+
## Supported formats
|
|
62
|
+
|
|
63
|
+
The currently supported formats are:
|
|
64
|
+
|
|
65
|
+
| File format | Implementation | Can write | Can read |
|
|
66
|
+
|-------------|----------------|-----------|----------|
|
|
67
|
+
| CSV | csv | yes | yes |
|
|
68
|
+
| Excel | OpenPyXL | yes | yes |
|
|
69
|
+
| HTML | mformat | yes | - |
|
|
70
|
+
| LaTeX | mformat | yes | - |
|
|
71
|
+
| docx | mformat | yes | - |
|
|
72
|
+
| md | mformat | yes | - |
|
|
73
|
+
| odt | mformat | yes | - |
|
|
74
|
+
| pdf | mformat | yes | - |
|
|
75
|
+
| rst | mformat | yes | - |
|
|
76
|
+
| rtf | mformat | yes | - |
|
|
77
|
+
| txt | mformat | yes | - |
|
|
78
|
+
|
|
79
|
+
## Example programs
|
|
80
|
+
|
|
81
|
+
Some example programs are available at: [https://bitbucket.org/tom-bjorkholm/table-io/src/master/example/src/example/](https://bitbucket.org/tom-bjorkholm/table-io/src/master/example/src/example/).
|
|
82
|
+
|
|
83
|
+
## API documentation
|
|
84
|
+
|
|
85
|
+
Be aware that this is still in early development. The APIs may change between versions.
|
|
86
|
+
|
|
87
|
+
You can find the public API documentation at [https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/api.md](https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/api.md)
|
|
88
|
+
|
|
89
|
+
You can find the protected API documentation at [https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/protected_api.md](https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/protected_api.md)
|
|
90
|
+
The protected API documentation is only for developers that want to
|
|
91
|
+
extend the framework with by adding their own classes as registered
|
|
92
|
+
readers/writers to the factory.
|
|
93
|
+
|
|
94
|
+
Even though the API documentation exists, most users and programmers probably get
|
|
95
|
+
a better start by reading the examples.
|
|
96
|
+
|
|
97
|
+
## Version history
|
|
98
|
+
|
|
99
|
+
| Version | Date | Python version | Comment |
|
|
100
|
+
|---------|-------------|----------------|------------------------|
|
|
101
|
+
| 0.1 | 2026 Mar 23 | 3.12 or newer | First released version |
|
|
102
|
+
|
|
103
|
+
## Test summary
|
|
104
|
+
|
|
105
|
+
- Test result: 634 passed in 17s
|
|
106
|
+
- No Flake8 warnings.
|
|
107
|
+
- No mypy errors found.
|
|
108
|
+
- Built version(s): 0.1
|
|
109
|
+
- Build and test using Python 3.14.3
|
tableio-0.1/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# tableio
|
|
2
|
+
|
|
3
|
+
## Early protoype
|
|
4
|
+
|
|
5
|
+
This package is still an early prototype. This means that major changes to the APIs are expected.
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
> **👤 Looking to use this in your program**
|
|
10
|
+
> This repository is for developers of the package. If you want to install and use `tableio` including writing programs that use them, please visit the **PyPI project page [https://pypi.org/project/tableio](https://pypi.org/project/tableio) for installation instructions and user documentation.
|
|
11
|
+
|
|
12
|
+
## What is it
|
|
13
|
+
|
|
14
|
+
The tableio package contains a number of classes providing a uniform way for
|
|
15
|
+
a python program to write table data (rows of columns) to and read table data
|
|
16
|
+
from a number of different common file formats.
|
|
17
|
+
|
|
18
|
+
The primary intended use is for text output from a python program, where the
|
|
19
|
+
programmer would like the user to be able to select the input and output file
|
|
20
|
+
formats.
|
|
21
|
+
|
|
22
|
+
The support for spreadsheets is for reading and writing data. There is no
|
|
23
|
+
intention to support reading or writing formulas. There is no support for
|
|
24
|
+
running calculations in the spreadsheets (although nothing will stop a
|
|
25
|
+
receiver of a spreadsheet created by tableio package to manually add
|
|
26
|
+
formulas in the received spreadsheet).
|
|
27
|
+
|
|
28
|
+
## For developers
|
|
29
|
+
|
|
30
|
+
### Cloning
|
|
31
|
+
|
|
32
|
+
The tableio repo uses submodules. To clone it use the command:
|
|
33
|
+
|
|
34
|
+
````sh
|
|
35
|
+
git clone --recurse-submodules git@bitbucket.org:tom-bjorkholm/table-io.git
|
|
36
|
+
````
|
|
37
|
+
|
|
38
|
+
If you forgot to include the `--recurse-submodules` in your `git clone` command
|
|
39
|
+
you can fix it later with the command:
|
|
40
|
+
|
|
41
|
+
````sh
|
|
42
|
+
git submodule update --init --recursive
|
|
43
|
+
````
|
|
44
|
+
|
|
45
|
+
To update the version of thr submodule repo that you see in the main repo use the command:
|
|
46
|
+
|
|
47
|
+
````sh
|
|
48
|
+
git submodule update --remote --merge
|
|
49
|
+
````
|
|
50
|
+
|
|
51
|
+
### Needed environment
|
|
52
|
+
|
|
53
|
+
#### OS
|
|
54
|
+
|
|
55
|
+
For running the script and running the test suite you need a mac or a Linux computer. Even if the resulting package can be installed and used on Windows, the scripts for building and testing are only implemented for mac and Linux.
|
|
56
|
+
|
|
57
|
+
#### Python version
|
|
58
|
+
|
|
59
|
+
Please see README_pypi.md for information on needed python version. Main development is on newest Python version.
|
|
60
|
+
|
|
61
|
+
#### Zsh
|
|
62
|
+
|
|
63
|
+
Most scripts are Python.
|
|
64
|
+
Some scripts are zsh. zsh is available by default on modern macs. zsh can easily be installed on Linux (on Ubuntu: `sudo apt install zsh`).
|
|
65
|
+
|
|
66
|
+
### Quick start
|
|
67
|
+
|
|
68
|
+
1. Clone this repository
|
|
69
|
+
2. Run `./setup_build_environment.zsh` to set up the build environment
|
|
70
|
+
3. Run `./doBuild.zsh` to build and test the package
|
|
71
|
+
|
|
72
|
+
### Building application
|
|
73
|
+
|
|
74
|
+
There are 3 main scripts (and 2 extra convinience scripts) for building the application:
|
|
75
|
+
|
|
76
|
+
- `run_setup_build_environment.py` Run this script first to get the
|
|
77
|
+
environment set up for building.
|
|
78
|
+
- `run_build.py` Run this script to build an installation package (.whl) and
|
|
79
|
+
to run the tests on it in a venv (virtual environment).
|
|
80
|
+
- `run_clean.py` Deletes all files that was produced by the build to start
|
|
81
|
+
over from a clean state.
|
|
82
|
+
- `run_clean_build.py` Combines the use of `run_clean.py`,
|
|
83
|
+
`run_setup_build_environment.py` and `run_build.py` into one script.
|
|
84
|
+
Pylint discover some duplicate code warnings only on a clean build so this
|
|
85
|
+
is useful.
|
|
86
|
+
- `run_pypi_build.py` Builds for PyPI upload and can do the upload too.
|
|
87
|
+
|
|
88
|
+
The "testing" includes pytest, pylint, flake8 and mypy.
|
|
89
|
+
|
|
90
|
+
After running `run_build.py` you can open `reports/index.html` to see all test
|
|
91
|
+
reports.
|
|
92
|
+
|
|
93
|
+
### More build system information
|
|
94
|
+
|
|
95
|
+
The file `./common_build_tools/README.md` (in git submodule - see above) contains more
|
|
96
|
+
information about the build system. This README can also be viewed at
|
|
97
|
+
[https://bitbucket.org/tom-bjorkholm/common_build_tools/src/master/README.md](https://bitbucket.org/tom-bjorkholm/common_build_tools/src/master/README.md)
|
|
98
|
+
|
|
99
|
+
## Test summary
|
|
100
|
+
|
|
101
|
+
- Test result: 634 passed in 17s
|
|
102
|
+
- No Flake8 warnings.
|
|
103
|
+
- No mypy errors found.
|
|
104
|
+
- Built version(s): 0.1
|
|
105
|
+
- Build and test using Python 3.14.3
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# tableio
|
|
2
|
+
|
|
3
|
+
The tableio package contains a number of classes providing a uniform way for
|
|
4
|
+
a python program to write table data (rows of columns) to and read table data
|
|
5
|
+
from a number of different common file formats.
|
|
6
|
+
|
|
7
|
+
The primary intended use is for text output from a python program, where the
|
|
8
|
+
programmer would like the user to be able to select the input and output file
|
|
9
|
+
formats.
|
|
10
|
+
|
|
11
|
+
The support for spreadsheets is for reading and writing data. There is no
|
|
12
|
+
intention to support reading or writing formulas. There is no support for
|
|
13
|
+
running calculations in the spreadsheets (although nothing will stop a
|
|
14
|
+
receiver of a spreadsheet created by tableio package to manually add
|
|
15
|
+
formulas in the received spreadsheet).
|
|
16
|
+
|
|
17
|
+
## Early design phase
|
|
18
|
+
|
|
19
|
+
This project is in an early design phase. This means that major changes to the APIs are still expected.
|
|
20
|
+
|
|
21
|
+
## Installing tableio
|
|
22
|
+
|
|
23
|
+
### Installing tableio on mac and Linux
|
|
24
|
+
|
|
25
|
+
````sh
|
|
26
|
+
pip3 install --upgrade tableio
|
|
27
|
+
````
|
|
28
|
+
|
|
29
|
+
### Installing tableio on Microsoft Windows
|
|
30
|
+
|
|
31
|
+
````sh
|
|
32
|
+
pip install --upgrade tableio
|
|
33
|
+
````
|
|
34
|
+
|
|
35
|
+
## Supported formats
|
|
36
|
+
|
|
37
|
+
The currently supported formats are:
|
|
38
|
+
|
|
39
|
+
| File format | Implementation | Can write | Can read |
|
|
40
|
+
|-------------|----------------|-----------|----------|
|
|
41
|
+
| CSV | csv | yes | yes |
|
|
42
|
+
| Excel | OpenPyXL | yes | yes |
|
|
43
|
+
| HTML | mformat | yes | - |
|
|
44
|
+
| LaTeX | mformat | yes | - |
|
|
45
|
+
| docx | mformat | yes | - |
|
|
46
|
+
| md | mformat | yes | - |
|
|
47
|
+
| odt | mformat | yes | - |
|
|
48
|
+
| pdf | mformat | yes | - |
|
|
49
|
+
| rst | mformat | yes | - |
|
|
50
|
+
| rtf | mformat | yes | - |
|
|
51
|
+
| txt | mformat | yes | - |
|
|
52
|
+
|
|
53
|
+
## Example programs
|
|
54
|
+
|
|
55
|
+
Some example programs are available at: [https://bitbucket.org/tom-bjorkholm/table-io/src/master/example/src/example/](https://bitbucket.org/tom-bjorkholm/table-io/src/master/example/src/example/).
|
|
56
|
+
|
|
57
|
+
## API documentation
|
|
58
|
+
|
|
59
|
+
Be aware that this is still in early development. The APIs may change between versions.
|
|
60
|
+
|
|
61
|
+
You can find the public API documentation at [https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/api.md](https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/api.md)
|
|
62
|
+
|
|
63
|
+
You can find the protected API documentation at [https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/protected_api.md](https://bitbucket.org/tom-bjorkholm/table-io/src/master/doc/protected_api.md)
|
|
64
|
+
The protected API documentation is only for developers that want to
|
|
65
|
+
extend the framework with by adding their own classes as registered
|
|
66
|
+
readers/writers to the factory.
|
|
67
|
+
|
|
68
|
+
Even though the API documentation exists, most users and programmers probably get
|
|
69
|
+
a better start by reading the examples.
|
|
70
|
+
|
|
71
|
+
## Version history
|
|
72
|
+
|
|
73
|
+
| Version | Date | Python version | Comment |
|
|
74
|
+
|---------|-------------|----------------|------------------------|
|
|
75
|
+
| 0.1 | 2026 Mar 23 | 3.12 or newer | First released version |
|
|
76
|
+
|
|
77
|
+
## Test summary
|
|
78
|
+
|
|
79
|
+
- Test result: 634 passed in 17s
|
|
80
|
+
- No Flake8 warnings.
|
|
81
|
+
- No mypy errors found.
|
|
82
|
+
- Built version(s): 0.1
|
|
83
|
+
- Build and test using Python 3.14.3
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tableio"
|
|
7
|
+
version = "0.1"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Tom Björkholm", email="klausuler_linnet0q@icloud.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Uniform way to write table data to and read from different file formats"
|
|
12
|
+
readme = "README_pypi.md"
|
|
13
|
+
requires-python = ">=3.12"
|
|
14
|
+
license = "MIT"
|
|
15
|
+
license-files = ["LICENSE.txt"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Development Status :: 2 - Pre-Alpha"
|
|
20
|
+
]
|
|
21
|
+
dynamic = ["dependencies"]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
"Source code" = "https://bitbucket.org/tom-bjorkholm/table-io"
|
tableio-0.1/setup.cfg
ADDED
tableio-0.1/setup.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#! /usr/local/bin/python3
|
|
2
|
+
"""Setup file specifying build of .whl."""
|
|
3
|
+
|
|
4
|
+
from setuptools import setup
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name='tableio',
|
|
8
|
+
version='0.1',
|
|
9
|
+
description='Uniform way to write table data to and read from different ' \
|
|
10
|
+
'file formats',
|
|
11
|
+
author='Tom Björkholm',
|
|
12
|
+
author_email='klausuler_linnet0q@icloud.com',
|
|
13
|
+
python_requires='>=3.12',
|
|
14
|
+
packages=['tableio'],
|
|
15
|
+
package_dir={'tableio': 'src/tableio'},
|
|
16
|
+
package_data={'tableio': ['src/py.typed']},
|
|
17
|
+
install_requires=[ # pylint: disable=duplicate-code
|
|
18
|
+
'pip >= 26.0.1',
|
|
19
|
+
'setuptools >= 82.0.1',
|
|
20
|
+
'build >= 1.4.0',
|
|
21
|
+
'wheel >= 0.46.3',
|
|
22
|
+
'mformat-ext >= 0.6',
|
|
23
|
+
'openpyxl >= 3.1.5',
|
|
24
|
+
'types-openpyxl >= 3.1.5.20260322'
|
|
25
|
+
]
|
|
26
|
+
)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
"""Capabilities of the reader/writer class for a file format."""
|
|
3
|
+
|
|
4
|
+
# Copyright (c) 2026 Tom Björkholm
|
|
5
|
+
# MIT License
|
|
6
|
+
|
|
7
|
+
from typing import NamedTuple
|
|
8
|
+
from enum import IntEnum, auto
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Strictness(IntEnum):
|
|
12
|
+
"""Strictness of a capability."""
|
|
13
|
+
|
|
14
|
+
STRICT = auto()
|
|
15
|
+
"""Strictly enforce, raise if not supported."""
|
|
16
|
+
IGNORE = auto()
|
|
17
|
+
"""Ignored if not supported."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SingleCapability(NamedTuple):
|
|
21
|
+
"""Single capability of aspect of reader/writer class.
|
|
22
|
+
|
|
23
|
+
Describes if a reader/writer class for a file format can handle a
|
|
24
|
+
specific aspect when reading or writing a file.
|
|
25
|
+
|
|
26
|
+
A reader/writer class will provide information about its capabilities in a
|
|
27
|
+
Capabilities object. For the single capability this says if it is
|
|
28
|
+
supported, but also how the class behaves if it is requested and not
|
|
29
|
+
supported.
|
|
30
|
+
If supported is True, the strictness is not used.
|
|
31
|
+
If supported is False, and the strictness is STRICT, an exception is raised
|
|
32
|
+
when a call to the reader/writer class is made that requires the
|
|
33
|
+
capability.
|
|
34
|
+
If supported is False, and the strictness is IGNORE, the call is ignored.
|
|
35
|
+
|
|
36
|
+
When requesting reader/writer class from the factory, the requester can
|
|
37
|
+
specify that only reader/writer classes that support the requested
|
|
38
|
+
capabilities are returned.
|
|
39
|
+
If the requester sets supported to True for a capability, it means that
|
|
40
|
+
the requester will be making calls to the reader/writer class that requires
|
|
41
|
+
the capability.
|
|
42
|
+
If the requester sets supported to False for a capability, it means that
|
|
43
|
+
the requester will not be making calls to the reader/writer class that
|
|
44
|
+
requires the capability. (If the requester sets supported to false, the
|
|
45
|
+
strictness will not be used.)
|
|
46
|
+
If the requester sets supported to True and strictness to STRICT, it means
|
|
47
|
+
that the requester is only accepting reader/writer classes that support
|
|
48
|
+
the capability.
|
|
49
|
+
If the requester sets supported to True and strictness to IGNORE, it means
|
|
50
|
+
that the requester is accepting reader/writer classes that may ignore
|
|
51
|
+
calls using the capability.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
supported: bool = False
|
|
55
|
+
"""If the capability is supported."""
|
|
56
|
+
strictness: Strictness = Strictness.IGNORE
|
|
57
|
+
"""How the capability is handled if not supported. Default is to ignore."""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Capabilities(NamedTuple):
|
|
61
|
+
"""Capabilities of a reader/writer class for a file format."""
|
|
62
|
+
|
|
63
|
+
can_write: SingleCapability = SingleCapability()
|
|
64
|
+
"""The reader/writer class can write to the file format."""
|
|
65
|
+
|
|
66
|
+
can_read: SingleCapability = SingleCapability()
|
|
67
|
+
"""The reader/writer class can read from the file format."""
|
|
68
|
+
|
|
69
|
+
can_fmt_row: SingleCapability = SingleCapability()
|
|
70
|
+
"""The writer class can apply a format to a row."""
|
|
71
|
+
|
|
72
|
+
can_fmt_value: SingleCapability = SingleCapability()
|
|
73
|
+
"""The writer class can apply a format to a value."""
|
|
74
|
+
|
|
75
|
+
filtered_data_range: SingleCapability = SingleCapability()
|
|
76
|
+
"""The writer class can mark a table as a filterable data range."""
|
|
77
|
+
|
|
78
|
+
can_write_box: SingleCapability = SingleCapability()
|
|
79
|
+
"""The writer class can write to position given by a box."""
|
|
80
|
+
|
|
81
|
+
can_read_box: SingleCapability = SingleCapability()
|
|
82
|
+
"""The reader class can read from position given by a box."""
|
|
83
|
+
|
|
84
|
+
can_write_highlight: SingleCapability = SingleCapability()
|
|
85
|
+
"""The writer class can write highlight according to format."""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def single_capability_match(offered: SingleCapability,
|
|
89
|
+
will_use: SingleCapability,
|
|
90
|
+
ignore_allowed: bool = True) -> bool:
|
|
91
|
+
"""Check if the offered single capability matches the will use.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
offered: The offered single capability. Does the reader/writer
|
|
95
|
+
class support this capability?
|
|
96
|
+
will_use: The will use single capability. Does the requester intend to
|
|
97
|
+
use this capability?
|
|
98
|
+
ignore_allowed: If False: when the offered single capability would
|
|
99
|
+
ignore the will use single capability it is
|
|
100
|
+
considered a mismatch, and will return False.
|
|
101
|
+
If False: when the offered single capability would
|
|
102
|
+
ignore the will use single capability it is
|
|
103
|
+
considered a match, and will return True.
|
|
104
|
+
Returns:
|
|
105
|
+
True if the offered single capability matches the will use,
|
|
106
|
+
False otherwise.
|
|
107
|
+
"""
|
|
108
|
+
if not will_use.supported:
|
|
109
|
+
return True
|
|
110
|
+
if offered.supported:
|
|
111
|
+
return True
|
|
112
|
+
if Strictness.STRICT in (offered.strictness, will_use.strictness):
|
|
113
|
+
return False
|
|
114
|
+
if ignore_allowed:
|
|
115
|
+
return True
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def capability_match(offered: Capabilities,
|
|
120
|
+
will_use: Capabilities,
|
|
121
|
+
ignore_allowed: bool = False) -> bool:
|
|
122
|
+
"""Check if the offered capabilities match the required capabilities.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
offered: The offered capabilities. What capabilities does the
|
|
126
|
+
reader/writer class support?
|
|
127
|
+
will_use: The recuested capabilities. What capabilities
|
|
128
|
+
does the requester intend to use?
|
|
129
|
+
ignore_allowed: If False: when an offered capability would ignore a
|
|
130
|
+
will use capability it is considered a mismatch, and
|
|
131
|
+
considered a mismatch, and will return False.
|
|
132
|
+
If True: when an offered capability would ignore a
|
|
133
|
+
will use capability it is considered a match, and
|
|
134
|
+
will return True.
|
|
135
|
+
Returns:
|
|
136
|
+
True if the offered capabilities match the will_use capabilities,
|
|
137
|
+
False otherwise.
|
|
138
|
+
"""
|
|
139
|
+
for single_offered, single_will_use in zip(offered, will_use):
|
|
140
|
+
if not single_capability_match(single_offered, single_will_use,
|
|
141
|
+
ignore_allowed):
|
|
142
|
+
return False
|
|
143
|
+
return True
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class CapabilityNotSupported(ValueError):
|
|
147
|
+
"""Exception raised when a capability is not supported."""
|
|
148
|
+
|
|
149
|
+
def __init__(self, action: str):
|
|
150
|
+
"""Initialize the exception.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
action: The requested action that is not supported.
|
|
154
|
+
"""
|
|
155
|
+
self.action = action
|
|
156
|
+
super().__init__(f'The class does not support {action}.')
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
"""Highlight colors for the tableio package."""
|
|
3
|
+
|
|
4
|
+
# Copyright (c) 2026 Tom Björkholm
|
|
5
|
+
# MIT License
|
|
6
|
+
|
|
7
|
+
from enum import IntEnum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Color(IntEnum):
|
|
11
|
+
"""Highlight colors for the tableio package."""
|
|
12
|
+
|
|
13
|
+
NONE = 0
|
|
14
|
+
"""No hightlight color."""
|
|
15
|
+
RED = 1
|
|
16
|
+
"""Red highlight color."""
|
|
17
|
+
GREEN = 2
|
|
18
|
+
"""Green highlight color."""
|
|
19
|
+
YELLOW = 3
|
|
20
|
+
"""Yellow highlight color."""
|