sltmodel 0.1.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.
- sltmodel-0.1.0/.github/workflows/publish_to_pypi.yml +26 -0
- sltmodel-0.1.0/.github/workflows/publish_to_testpypi.yml +24 -0
- sltmodel-0.1.0/.gitignore +220 -0
- sltmodel-0.1.0/LICENSE +21 -0
- sltmodel-0.1.0/PKG-INFO +52 -0
- sltmodel-0.1.0/README.md +35 -0
- sltmodel-0.1.0/pyproject.toml +39 -0
- sltmodel-0.1.0/src/sltmodel/__init__.py +43 -0
- sltmodel-0.1.0/src/sltmodel/infosize.py +93 -0
- sltmodel-0.1.0/src/sltmodel/packet_data.py +518 -0
- sltmodel-0.1.0/src/sltmodel/payload_struct_defs.py +129 -0
- sltmodel-0.1.0/src/sltmodel/resources/__init__.py +22 -0
- sltmodel-0.1.0/src/sltmodel/resources/pcap.json +604 -0
- sltmodel-0.1.0/src/sltmodel/resources/pcapng.json +535 -0
- sltmodel-0.1.0/src/sltmodel/struct_instance.py +185 -0
- sltmodel-0.1.0/tests/test_packet_data.py +333 -0
- sltmodel-0.1.0/tests/test_payload_struct_defs.py +103 -0
- sltmodel-0.1.0/uv.lock +120 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish SltModel to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build-and-publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v3
|
|
18
|
+
|
|
19
|
+
- name: Build SltModel distribution
|
|
20
|
+
run: uv build
|
|
21
|
+
|
|
22
|
+
- name: Publish to PyPI
|
|
23
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
24
|
+
with:
|
|
25
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
26
|
+
packages-dir: dist
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish SltModel to TestPyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build-and-publish:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- name: Install uv
|
|
14
|
+
uses: astral-sh/setup-uv@v3
|
|
15
|
+
|
|
16
|
+
- name: Build SltModel distribution
|
|
17
|
+
run: uv build
|
|
18
|
+
|
|
19
|
+
- name: Publish to TestPyPI
|
|
20
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
21
|
+
with:
|
|
22
|
+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
|
23
|
+
repository-url: https://test.pypi.org/legacy/
|
|
24
|
+
packages-dir: dist
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
sltmodel-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fangface
|
|
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.
|
sltmodel-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sltmodel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GUI-independent data models and operations for StructLayoutToolkit
|
|
5
|
+
Project-URL: Homepage, https://github.com/fangface-hub/StructLayoutToolkitGui
|
|
6
|
+
Project-URL: Repository, https://github.com/fangface-hub/StructLayoutToolkitGui
|
|
7
|
+
Project-URL: Issues, https://github.com/fangface-hub/StructLayoutToolkitGui/issues
|
|
8
|
+
Author: fangface
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: byte,deserialization,layout,serialization,struct
|
|
12
|
+
Requires-Python: >=3.14
|
|
13
|
+
Requires-Dist: sltcalc>=1.1.0
|
|
14
|
+
Requires-Dist: sltcodec>=2.6.1
|
|
15
|
+
Requires-Dist: sltcore>=1.7.0
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# StructLayoutToolkitModel
|
|
19
|
+
|
|
20
|
+
StructLayoutToolkitModel (distribution name `sltmodel`) is a standalone,
|
|
21
|
+
GUI-independent model library that handles StructLayout definitions and binary
|
|
22
|
+
decoding. It provides the structure engine used by StructLayoutToolkitGui and
|
|
23
|
+
is intended for reuse by other clients such as a CLI.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```console
|
|
28
|
+
python -m pip install sltmodel
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## API
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from sltmodel import CaptureDocument, PayloadStructDef
|
|
35
|
+
from sltmodel.resources import load_pcap_layout
|
|
36
|
+
|
|
37
|
+
capture = CaptureDocument.from_bytes(capture_bytes)
|
|
38
|
+
pcap_layout = load_pcap_layout()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The package provides capture parsing and IP fragment reassembly, conditional
|
|
42
|
+
payload StructLayout definitions, StructInstance value helpers, InfoSize
|
|
43
|
+
conversion helpers, and the bundled PCAP/PCAPNG layouts. It does not import or
|
|
44
|
+
depend on Tkinter.
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
```console
|
|
49
|
+
uv sync
|
|
50
|
+
uv run pytest -q
|
|
51
|
+
uv build
|
|
52
|
+
```
|
sltmodel-0.1.0/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# StructLayoutToolkitModel
|
|
2
|
+
|
|
3
|
+
StructLayoutToolkitModel (distribution name `sltmodel`) is a standalone,
|
|
4
|
+
GUI-independent model library that handles StructLayout definitions and binary
|
|
5
|
+
decoding. It provides the structure engine used by StructLayoutToolkitGui and
|
|
6
|
+
is intended for reuse by other clients such as a CLI.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```console
|
|
11
|
+
python -m pip install sltmodel
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from sltmodel import CaptureDocument, PayloadStructDef
|
|
18
|
+
from sltmodel.resources import load_pcap_layout
|
|
19
|
+
|
|
20
|
+
capture = CaptureDocument.from_bytes(capture_bytes)
|
|
21
|
+
pcap_layout = load_pcap_layout()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The package provides capture parsing and IP fragment reassembly, conditional
|
|
25
|
+
payload StructLayout definitions, StructInstance value helpers, InfoSize
|
|
26
|
+
conversion helpers, and the bundled PCAP/PCAPNG layouts. It does not import or
|
|
27
|
+
depend on Tkinter.
|
|
28
|
+
|
|
29
|
+
## Development
|
|
30
|
+
|
|
31
|
+
```console
|
|
32
|
+
uv sync
|
|
33
|
+
uv run pytest -q
|
|
34
|
+
uv build
|
|
35
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sltmodel"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "GUI-independent data models and operations for StructLayoutToolkit"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"sltcalc>=1.1.0",
|
|
9
|
+
"sltcodec>=2.6.1",
|
|
10
|
+
"sltcore>=1.7.0",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "fangface" }
|
|
17
|
+
]
|
|
18
|
+
keywords = ["struct", "byte", "layout", "serialization", "deserialization"]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/fangface-hub/StructLayoutToolkitGui"
|
|
22
|
+
Repository = "https://github.com/fangface-hub/StructLayoutToolkitGui"
|
|
23
|
+
Issues = "https://github.com/fangface-hub/StructLayoutToolkitGui/issues"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["hatchling"]
|
|
27
|
+
build-backend = "hatchling.build"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.wheel]
|
|
30
|
+
packages = ["src/sltmodel"]
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=9.1.1",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
pythonpath = ["src"]
|
|
39
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""GUI-independent data models and operations for StructLayoutToolkit."""
|
|
2
|
+
from importlib import import_module
|
|
3
|
+
|
|
4
|
+
_EXPORTS = {
|
|
5
|
+
"format_infosize": (".infosize", "format_infosize"),
|
|
6
|
+
"infosize_to_json_data": (".infosize", "infosize_to_json_data"),
|
|
7
|
+
"infosize_value_to_string": (".infosize", "infosize_value_to_string"),
|
|
8
|
+
"parse_infosize_input": (".infosize", "parse_infosize_input"),
|
|
9
|
+
"CaptureDocument": (".packet_data", "CaptureDocument"),
|
|
10
|
+
"PacketFragment": (".packet_data", "PacketFragment"),
|
|
11
|
+
"ReassembledPacket": (".packet_data", "ReassembledPacket"),
|
|
12
|
+
"internet_checksum": (".packet_data", "internet_checksum"),
|
|
13
|
+
"PayloadStructDef": (".payload_struct_defs", "PayloadStructDef"),
|
|
14
|
+
"load_payload_struct_defs": (".payload_struct_defs",
|
|
15
|
+
"load_payload_struct_defs"),
|
|
16
|
+
"matching_struct_layout": (".payload_struct_defs",
|
|
17
|
+
"matching_struct_layout"),
|
|
18
|
+
"packet_eval_env": (".payload_struct_defs", "packet_eval_env"),
|
|
19
|
+
"save_payload_struct_defs": (".payload_struct_defs",
|
|
20
|
+
"save_payload_struct_defs"),
|
|
21
|
+
"field_instance_at_path": (".struct_instance", "field_instance_at_path"),
|
|
22
|
+
"format_field_value": (".struct_instance", "format_field_value"),
|
|
23
|
+
"format_type": (".struct_instance", "format_type"),
|
|
24
|
+
"format_value": (".struct_instance", "format_value"),
|
|
25
|
+
"minimum_struct_size": (".struct_instance", "minimum_struct_size"),
|
|
26
|
+
"parse_field_value": (".struct_instance", "parse_field_value"),
|
|
27
|
+
"parse_value": (".struct_instance", "parse_value"),
|
|
28
|
+
"replace_instance_field_value": (".struct_instance",
|
|
29
|
+
"replace_instance_field_value"),
|
|
30
|
+
"replace_instance_value": (".struct_instance", "replace_instance_value"),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
__all__ = list(_EXPORTS)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def __getattr__(name: str):
|
|
37
|
+
"""Load model APIs only when requested."""
|
|
38
|
+
try:
|
|
39
|
+
module_name, attribute_name = _EXPORTS[name]
|
|
40
|
+
except KeyError as exc:
|
|
41
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}"
|
|
42
|
+
) from exc
|
|
43
|
+
return getattr(import_module(module_name, __name__), attribute_name)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Shared InfoSize parsing/formatting helpers used by the editor windows.
|
|
2
|
+
|
|
3
|
+
These take the caller's InfoSize class as a parameter instead of importing
|
|
4
|
+
one directly, so callers (and their tests) can supply their own InfoSize
|
|
5
|
+
implementation without this module caching a stale class reference.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def format_infosize(value: object) -> str:
|
|
13
|
+
"""Format an InfoSize-like value as its ``byte,bit`` string form."""
|
|
14
|
+
return f"{value.byte},{value.bit}"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def parse_infosize_input(value: object, info_size_cls: type) -> object:
|
|
18
|
+
"""Parse ``byte,bit`` input, preserving non-static expressions."""
|
|
19
|
+
if isinstance(value, info_size_cls):
|
|
20
|
+
return value
|
|
21
|
+
if isinstance(value, dict) and value.get("__type__") == "InfoSize":
|
|
22
|
+
return info_size_cls(int(value.get("byte", 0)), int(value.get("bit",
|
|
23
|
+
0)))
|
|
24
|
+
text = str(value).strip()
|
|
25
|
+
if not text:
|
|
26
|
+
text = "0,0"
|
|
27
|
+
try:
|
|
28
|
+
parsed = json.loads(text)
|
|
29
|
+
except json.JSONDecodeError:
|
|
30
|
+
parsed = None
|
|
31
|
+
if isinstance(parsed, dict) and parsed.get("__type__") == "InfoSize":
|
|
32
|
+
return info_size_cls(int(parsed.get("byte", 0)),
|
|
33
|
+
int(parsed.get("bit", 0)))
|
|
34
|
+
parts = [part.strip() for part in text.split(",")]
|
|
35
|
+
if len(parts) == 1:
|
|
36
|
+
try:
|
|
37
|
+
return info_size_cls(int(parts[0]), 0)
|
|
38
|
+
except ValueError:
|
|
39
|
+
return text
|
|
40
|
+
if len(parts) == 2:
|
|
41
|
+
try:
|
|
42
|
+
byte, bit = (int(part) for part in parts)
|
|
43
|
+
except ValueError:
|
|
44
|
+
return text
|
|
45
|
+
return info_size_cls(byte, bit)
|
|
46
|
+
return text
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def infosize_value_to_string(value: object, info_size_cls: type) -> str:
|
|
50
|
+
"""Convert an InfoSize-like value to one editable cell string."""
|
|
51
|
+
|
|
52
|
+
def from_dict(item: dict) -> str:
|
|
53
|
+
info_size = info_size_cls(int(item.get("byte", 0)),
|
|
54
|
+
int(item.get("bit", 0)))
|
|
55
|
+
return format_infosize(info_size)
|
|
56
|
+
|
|
57
|
+
def from_string(item: str) -> str:
|
|
58
|
+
stripped = item.strip()
|
|
59
|
+
if not stripped:
|
|
60
|
+
return "0,0"
|
|
61
|
+
try:
|
|
62
|
+
parsed = json.loads(stripped)
|
|
63
|
+
except json.JSONDecodeError:
|
|
64
|
+
try:
|
|
65
|
+
info_size = info_size_cls(int(stripped), 0)
|
|
66
|
+
except ValueError:
|
|
67
|
+
return stripped
|
|
68
|
+
return format_infosize(info_size)
|
|
69
|
+
if isinstance(parsed, dict) and parsed.get("__type__") == "InfoSize":
|
|
70
|
+
return from_dict(parsed)
|
|
71
|
+
return stripped
|
|
72
|
+
|
|
73
|
+
if isinstance(value, info_size_cls):
|
|
74
|
+
return format_infosize(value)
|
|
75
|
+
|
|
76
|
+
handlers = {
|
|
77
|
+
dict:
|
|
78
|
+
lambda item: from_dict(item)
|
|
79
|
+
if item.get("__type__") == "InfoSize" else "0,0",
|
|
80
|
+
str:
|
|
81
|
+
from_string,
|
|
82
|
+
int:
|
|
83
|
+
lambda item: from_dict({
|
|
84
|
+
"byte": item,
|
|
85
|
+
"bit": 0
|
|
86
|
+
}),
|
|
87
|
+
}
|
|
88
|
+
return handlers.get(type(value), lambda _: "0,0")(value)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def infosize_to_json_data(value: object) -> dict:
|
|
92
|
+
"""Convert an InfoSize-like instance to its typed JSON dictionary."""
|
|
93
|
+
return json.loads(value.serialize())
|