oliviadb-dli 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.
- oliviadb_dli-0.1.0/LICENSE +202 -0
- oliviadb_dli-0.1.0/NOTICE-native.md +11 -0
- oliviadb_dli-0.1.0/PKG-INFO +52 -0
- oliviadb_dli-0.1.0/README.md +38 -0
- oliviadb_dli-0.1.0/pyproject.toml +29 -0
- oliviadb_dli-0.1.0/setup.cfg +4 -0
- oliviadb_dli-0.1.0/src/oliviadb_dli/__init__.py +505 -0
- oliviadb_dli-0.1.0/src/oliviadb_dli/py.typed +0 -0
- oliviadb_dli-0.1.0/src/oliviadb_dli.egg-info/PKG-INFO +52 -0
- oliviadb_dli-0.1.0/src/oliviadb_dli.egg-info/SOURCES.txt +11 -0
- oliviadb_dli-0.1.0/src/oliviadb_dli.egg-info/dependency_links.txt +1 -0
- oliviadb_dli-0.1.0/src/oliviadb_dli.egg-info/top_level.txt +1 -0
- oliviadb_dli-0.1.0/tests/test_basic.py +197 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
2
|
+
# The native library in the wheels
|
|
3
|
+
|
|
4
|
+
The wheels of `oliviadb-dli` carry `liboliviadb_dli` in `oliviadb_dli/lib/`: OliviaDB's DL/I
|
|
5
|
+
library, taken from the GitHub Release of the OliviaDB core (https://github.com/OliviaDB/oliviadb)
|
|
6
|
+
of the same version and checked against its `SHA256SUMS`. It is licensed under AGPL-3.0-only or
|
|
7
|
+
OliviaDB's commercial licence (`LICENSE-native.md`, the core's `LICENSE.md`; its third-party
|
|
8
|
+
notices in `THIRD_PARTY-native.md`); its source is that repository at the release's tag.
|
|
9
|
+
|
|
10
|
+
The Python code is Apache-2.0 (`LICENSE`). A wheel as a whole:
|
|
11
|
+
`Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)`.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oliviadb-dli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DL/I calls from Python on OliviaDB: schedule programs on DBD/PSB definitions and make GU, GN, ISRT, REPL, DLET and the other calls
|
|
5
|
+
License-Expression: Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)
|
|
6
|
+
Project-URL: Homepage, https://olivia-db.com/
|
|
7
|
+
Project-URL: Documentation, https://docs.olivia-db.com/dli-quickstart/
|
|
8
|
+
Project-URL: Source, https://github.com/OliviaDB/oliviadb-python
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE-native.md
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
16
|
+
# oliviadb-dli
|
|
17
|
+
|
|
18
|
+
DL/I calls from Python on OliviaDB: open a store, import DBDGEN and PSBGEN source, schedule a
|
|
19
|
+
program on a PSB and make its calls (GU, GN, GNP, the hold forms, ISRT, REPL, DLET and the system
|
|
20
|
+
service calls) with I/O areas and segment search arguments, as an IMS program does through its PCBs.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from oliviadb_dli import Library, Runtime, Ssa
|
|
24
|
+
|
|
25
|
+
with Library.load().open("store") as system:
|
|
26
|
+
system.load_library("dli") # PARTDB.dbd, PARTPSB.psb
|
|
27
|
+
prog = system.schedule("PARTPSB", Runtime.ASCII_BE)
|
|
28
|
+
io = bytearray(prog.io_size(1))
|
|
29
|
+
status = prog.call(1, "GU", io, [Ssa("PART").qual("PARTNO", "=", b"P00001").build()])
|
|
30
|
+
print(status, bytes(io), prog.pcb(1).key_feedback)
|
|
31
|
+
prog.terminate() # commit; abort() backs out
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Licence
|
|
35
|
+
|
|
36
|
+
The Python code is Apache-2.0. The wheels for Linux (x86_64, aarch64) and macOS (arm64, x86_64)
|
|
37
|
+
also contain OliviaDB's DL/I library `liboliviadb_dli`, which is licensed under AGPL-3.0-only or
|
|
38
|
+
OliviaDB's commercial licence. A wheel as a whole is therefore
|
|
39
|
+
`Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)`: using it is using the
|
|
40
|
+
AGPL-licensed library, unless you have OliviaDB's commercial licence. The source distribution
|
|
41
|
+
contains no library.
|
|
42
|
+
|
|
43
|
+
## The library
|
|
44
|
+
|
|
45
|
+
Loaded from the file `OLIVIADB_DLI_LIB` names, else the wheel's copy, else the system's library
|
|
46
|
+
search path. It needs C ABI version 13 or later (OliviaDB 0.1.0).
|
|
47
|
+
|
|
48
|
+
## Character sets
|
|
49
|
+
|
|
50
|
+
`Program.call` and `Ssa` write names, function codes and operators in ASCII, for programs
|
|
51
|
+
scheduled with `Runtime.ASCII_BE` or `Runtime.ASCII_LE`. A program scheduled with
|
|
52
|
+
`Runtime.EBCDIC` makes its calls with `Program.call_bytes` and SSAs in EBCDIC bytes of its own.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
2
|
+
# oliviadb-dli
|
|
3
|
+
|
|
4
|
+
DL/I calls from Python on OliviaDB: open a store, import DBDGEN and PSBGEN source, schedule a
|
|
5
|
+
program on a PSB and make its calls (GU, GN, GNP, the hold forms, ISRT, REPL, DLET and the system
|
|
6
|
+
service calls) with I/O areas and segment search arguments, as an IMS program does through its PCBs.
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
from oliviadb_dli import Library, Runtime, Ssa
|
|
10
|
+
|
|
11
|
+
with Library.load().open("store") as system:
|
|
12
|
+
system.load_library("dli") # PARTDB.dbd, PARTPSB.psb
|
|
13
|
+
prog = system.schedule("PARTPSB", Runtime.ASCII_BE)
|
|
14
|
+
io = bytearray(prog.io_size(1))
|
|
15
|
+
status = prog.call(1, "GU", io, [Ssa("PART").qual("PARTNO", "=", b"P00001").build()])
|
|
16
|
+
print(status, bytes(io), prog.pcb(1).key_feedback)
|
|
17
|
+
prog.terminate() # commit; abort() backs out
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Licence
|
|
21
|
+
|
|
22
|
+
The Python code is Apache-2.0. The wheels for Linux (x86_64, aarch64) and macOS (arm64, x86_64)
|
|
23
|
+
also contain OliviaDB's DL/I library `liboliviadb_dli`, which is licensed under AGPL-3.0-only or
|
|
24
|
+
OliviaDB's commercial licence. A wheel as a whole is therefore
|
|
25
|
+
`Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)`: using it is using the
|
|
26
|
+
AGPL-licensed library, unless you have OliviaDB's commercial licence. The source distribution
|
|
27
|
+
contains no library.
|
|
28
|
+
|
|
29
|
+
## The library
|
|
30
|
+
|
|
31
|
+
Loaded from the file `OLIVIADB_DLI_LIB` names, else the wheel's copy, else the system's library
|
|
32
|
+
search path. It needs C ABI version 13 or later (OliviaDB 0.1.0).
|
|
33
|
+
|
|
34
|
+
## Character sets
|
|
35
|
+
|
|
36
|
+
`Program.call` and `Ssa` write names, function codes and operators in ASCII, for programs
|
|
37
|
+
scheduled with `Runtime.ASCII_BE` or `Runtime.ASCII_LE`. A program scheduled with
|
|
38
|
+
`Runtime.EBCDIC` makes its calls with `Program.call_bytes` and SSAs in EBCDIC bytes of its own.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# The wheels for Linux x86_64/aarch64 and macOS arm64/x86_64 carry liboliviadb_dli in
|
|
3
|
+
# oliviadb_dli/lib/ (tools/dli_wheels.py puts it there from the core's GitHub Release), so a
|
|
4
|
+
# wheel is "Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)"; the Python code
|
|
5
|
+
# is Apache-2.0. The sdist carries no library (it loads OLIVIADB_DLI_LIB).
|
|
6
|
+
[build-system]
|
|
7
|
+
requires = ["setuptools>=77"]
|
|
8
|
+
build-backend = "setuptools.build_meta"
|
|
9
|
+
|
|
10
|
+
[project]
|
|
11
|
+
name = "oliviadb-dli"
|
|
12
|
+
version = "0.1.0"
|
|
13
|
+
description = "DL/I calls from Python on OliviaDB: schedule programs on DBD/PSB definitions and make GU, GN, ISRT, REPL, DLET and the other calls"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
license = "Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)"
|
|
16
|
+
license-files = ["LICENSE", "*-native.md"]
|
|
17
|
+
requires-python = ">=3.10"
|
|
18
|
+
dependencies = []
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://olivia-db.com/"
|
|
22
|
+
Documentation = "https://docs.olivia-db.com/dli-quickstart/"
|
|
23
|
+
Source = "https://github.com/OliviaDB/oliviadb-python"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
oliviadb_dli = ["py.typed", "lib/*"]
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""DL/I calls from Python on OliviaDB's DL/I library (``liboliviadb_dli``, C ABI 13 or later).
|
|
3
|
+
|
|
4
|
+
Open a store, import DBDGEN and PSBGEN source, schedule a program on a PSB and make its calls
|
|
5
|
+
with I/O areas and segment search arguments, as an IMS program does through its PCBs::
|
|
6
|
+
|
|
7
|
+
from oliviadb_dli import Library, Runtime, Ssa
|
|
8
|
+
|
|
9
|
+
lib = Library.load()
|
|
10
|
+
with lib.open("store") as sys:
|
|
11
|
+
sys.load_library("dli") # PARTDB.dbd, PARTPSB.psb
|
|
12
|
+
prog = sys.schedule("PARTPSB", Runtime.ASCII_BE)
|
|
13
|
+
io = bytearray(prog.io_size(1))
|
|
14
|
+
status = prog.call(1, "GU", io, [Ssa("PART").qual("PARTNO", "=", b"P001").build()])
|
|
15
|
+
prog.terminate() # commit; abort() backs out
|
|
16
|
+
|
|
17
|
+
The library is loaded from the file ``OLIVIADB_DLI_LIB`` names, else from the copy the wheel
|
|
18
|
+
carries (``oliviadb_dli/lib/``), else through the system's library search path. The Python code
|
|
19
|
+
is Apache-2.0; the library is AGPL-3.0-only or OliviaDB's commercial licence, so a wheel that
|
|
20
|
+
carries it is ``Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)``.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import contextlib
|
|
26
|
+
import ctypes
|
|
27
|
+
import ctypes.util
|
|
28
|
+
import enum
|
|
29
|
+
import os
|
|
30
|
+
import pathlib
|
|
31
|
+
import sys
|
|
32
|
+
from collections.abc import Sequence
|
|
33
|
+
from typing import Any, ClassVar
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"MIN_ABI_VERSION",
|
|
37
|
+
"AbendError",
|
|
38
|
+
"ArgumentError",
|
|
39
|
+
"DliError",
|
|
40
|
+
"Library",
|
|
41
|
+
"LibraryError",
|
|
42
|
+
"LoadError",
|
|
43
|
+
"LockWaitError",
|
|
44
|
+
"Pcb",
|
|
45
|
+
"Program",
|
|
46
|
+
"Runtime",
|
|
47
|
+
"Ssa",
|
|
48
|
+
"Status",
|
|
49
|
+
"System",
|
|
50
|
+
"library_file_name",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
#: The lowest C ABI version this package works with: 13, OliviaDB 0.1.0.
|
|
54
|
+
MIN_ABI_VERSION = 13
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class DliError(Exception):
|
|
58
|
+
"""An error of this package."""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class LoadError(DliError):
|
|
62
|
+
"""The library could not be loaded, or is older than MIN_ABI_VERSION."""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class LibraryError(DliError):
|
|
66
|
+
"""A call of the library failed (its oliviadb_last_error text; a DL/I call's -1)."""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class AbendError(DliError):
|
|
70
|
+
"""The DL/I call ended the program abnormally (-2); ``code`` is the abend code (U0778, U0777).
|
|
71
|
+
The unit of work was backed out; end the program with Program.abort."""
|
|
72
|
+
|
|
73
|
+
def __init__(self, code: str) -> None:
|
|
74
|
+
super().__init__(f"the program ended abnormally: {code}")
|
|
75
|
+
self.code = code
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class LockWaitError(DliError):
|
|
79
|
+
"""The call needs a lock another program holds (-3); nothing was done, call again later."""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class ArgumentError(DliError):
|
|
83
|
+
"""An argument this package cannot pass."""
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class Runtime(enum.IntEnum):
|
|
87
|
+
"""How the program's storage represents characters and binary numbers."""
|
|
88
|
+
|
|
89
|
+
EBCDIC = 0 #: EBCDIC (code page 037), big-endian binary
|
|
90
|
+
ASCII_BE = 1 #: ASCII, big-endian binary
|
|
91
|
+
ASCII_LE = 2 #: ASCII, little-endian binary
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class Status:
|
|
95
|
+
"""A DL/I status code: two blanks on success, else two characters (GE, GB, II, ...)."""
|
|
96
|
+
|
|
97
|
+
__slots__ = ("code",)
|
|
98
|
+
|
|
99
|
+
def __init__(self, code: str) -> None:
|
|
100
|
+
self.code = code
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def _of(cls, rc: int) -> Status:
|
|
104
|
+
return cls(" " if rc == 0 else chr((rc >> 8) & 0xFF) + chr(rc & 0xFF))
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def blank(self) -> bool:
|
|
108
|
+
return self.code == " "
|
|
109
|
+
|
|
110
|
+
def __eq__(self, other: object) -> bool:
|
|
111
|
+
if isinstance(other, Status):
|
|
112
|
+
return self.code == other.code
|
|
113
|
+
if isinstance(other, str):
|
|
114
|
+
return self.code == other
|
|
115
|
+
return NotImplemented
|
|
116
|
+
|
|
117
|
+
def __hash__(self) -> int:
|
|
118
|
+
return hash(self.code)
|
|
119
|
+
|
|
120
|
+
def __str__(self) -> str:
|
|
121
|
+
return self.code
|
|
122
|
+
|
|
123
|
+
def __repr__(self) -> str:
|
|
124
|
+
return f"Status({self.code!r})"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class _Arg(ctypes.Structure):
|
|
128
|
+
_fields_ = [("ptr", ctypes.c_void_p), ("len", ctypes.c_size_t)]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def library_file_name() -> str:
|
|
132
|
+
"""The library's file name on this platform."""
|
|
133
|
+
if sys.platform == "darwin":
|
|
134
|
+
return "liboliviadb_dli.dylib"
|
|
135
|
+
if sys.platform == "win32":
|
|
136
|
+
return "oliviadb_dli.dll"
|
|
137
|
+
return "liboliviadb_dli.so"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
_P = ctypes.c_void_p
|
|
141
|
+
_SIGS: dict[str, tuple[Any, list[Any]]] = {
|
|
142
|
+
"oliviadb_abi_version": (ctypes.c_int, []),
|
|
143
|
+
"oliviadb_last_error": (ctypes.c_char_p, []),
|
|
144
|
+
"oliviadb_open": (_P, [ctypes.c_char_p, ctypes.c_int]),
|
|
145
|
+
"oliviadb_close": (None, [_P]),
|
|
146
|
+
"oliviadb_define": (ctypes.c_int, [_P, ctypes.c_char_p, ctypes.c_size_t]),
|
|
147
|
+
"oliviadb_load_library": (ctypes.c_int, [_P, ctypes.c_char_p]),
|
|
148
|
+
"oliviadb_map_database": (ctypes.c_int, [_P, ctypes.c_char_p, ctypes.c_char_p]),
|
|
149
|
+
"oliviadb_set_dd": (ctypes.c_int, [_P, ctypes.c_char_p, ctypes.c_char_p]),
|
|
150
|
+
"oliviadb_schedule": (_P, [_P, ctypes.c_char_p, ctypes.c_int]),
|
|
151
|
+
"oliviadb_pcb_count": (ctypes.c_int, [_P]),
|
|
152
|
+
"oliviadb_pcb_address": (_P, [_P, ctypes.c_int]),
|
|
153
|
+
"oliviadb_mask_len": (ctypes.c_size_t, [_P, ctypes.c_int]),
|
|
154
|
+
"oliviadb_io_size": (ctypes.c_size_t, [_P, ctypes.c_int]),
|
|
155
|
+
"oliviadb_call": (
|
|
156
|
+
ctypes.c_int,
|
|
157
|
+
[_P, ctypes.c_int, ctypes.c_char_p, _P, ctypes.c_size_t, ctypes.POINTER(_Arg), ctypes.c_int],
|
|
158
|
+
),
|
|
159
|
+
"oliviadb_abend_code": (ctypes.c_char_p, [_P]),
|
|
160
|
+
"oliviadb_sync": (ctypes.c_int, [_P]),
|
|
161
|
+
"oliviadb_backout": (ctypes.c_int, [_P]),
|
|
162
|
+
"oliviadb_terminate": (ctypes.c_int, [_P]),
|
|
163
|
+
"oliviadb_abort": (None, [_P]),
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _path(p: str | os.PathLike[str]) -> bytes:
|
|
168
|
+
s = os.fspath(p)
|
|
169
|
+
if "\0" in s:
|
|
170
|
+
raise ArgumentError(f"{s!r} contains a NUL character")
|
|
171
|
+
return s.encode()
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _name(s: str) -> bytes:
|
|
175
|
+
if "\0" in s:
|
|
176
|
+
raise ArgumentError(f"{s!r} contains a NUL character")
|
|
177
|
+
return s.encode()
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class Library:
|
|
181
|
+
"""The loaded liboliviadb_dli."""
|
|
182
|
+
|
|
183
|
+
def __init__(self, path: str) -> None:
|
|
184
|
+
try:
|
|
185
|
+
self._dll = ctypes.CDLL(path)
|
|
186
|
+
except OSError as e:
|
|
187
|
+
raise LoadError(f"{path}: {e}") from e
|
|
188
|
+
for name, (res, args) in _SIGS.items():
|
|
189
|
+
try:
|
|
190
|
+
f = getattr(self._dll, name)
|
|
191
|
+
except AttributeError as e:
|
|
192
|
+
raise LoadError(f"{path}: no {name}") from e
|
|
193
|
+
f.restype = res
|
|
194
|
+
f.argtypes = args
|
|
195
|
+
self.path = path
|
|
196
|
+
v = self.abi_version()
|
|
197
|
+
if v < MIN_ABI_VERSION:
|
|
198
|
+
raise LoadError(f"{path} has C ABI version {v}; this package needs {MIN_ABI_VERSION} or later")
|
|
199
|
+
|
|
200
|
+
@classmethod
|
|
201
|
+
def load(cls) -> Library:
|
|
202
|
+
"""From OLIVIADB_DLI_LIB, else the wheel's copy, else the system's library search path."""
|
|
203
|
+
env = os.environ.get("OLIVIADB_DLI_LIB")
|
|
204
|
+
if env:
|
|
205
|
+
return cls(env)
|
|
206
|
+
bundled = pathlib.Path(__file__).parent / "lib" / library_file_name()
|
|
207
|
+
if bundled.is_file():
|
|
208
|
+
return cls(str(bundled))
|
|
209
|
+
found = ctypes.util.find_library("oliviadb_dli")
|
|
210
|
+
if not found:
|
|
211
|
+
raise LoadError(
|
|
212
|
+
f"no {library_file_name()}: this installation carries none for {sys.platform}; "
|
|
213
|
+
"set OLIVIADB_DLI_LIB to the file"
|
|
214
|
+
)
|
|
215
|
+
return cls(found)
|
|
216
|
+
|
|
217
|
+
def abi_version(self) -> int:
|
|
218
|
+
return int(self._dll.oliviadb_abi_version())
|
|
219
|
+
|
|
220
|
+
def _error(self, what: str) -> LibraryError:
|
|
221
|
+
m = self._dll.oliviadb_last_error()
|
|
222
|
+
text = m.decode(errors="replace") if m else ""
|
|
223
|
+
return LibraryError(f"{what}: {text}" if text else what)
|
|
224
|
+
|
|
225
|
+
def open(self, directory: str | os.PathLike[str], sync: bool = True) -> System:
|
|
226
|
+
"""Open (or create) the databases stored in a directory; sync: commits are durable on return."""
|
|
227
|
+
h = self._dll.oliviadb_open(_path(directory), int(sync))
|
|
228
|
+
if not h:
|
|
229
|
+
raise self._error("open")
|
|
230
|
+
return System(self, h)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class System:
|
|
234
|
+
"""The databases of one store directory with their DBD and PSB definitions."""
|
|
235
|
+
|
|
236
|
+
def __init__(self, lib: Library, handle: int) -> None:
|
|
237
|
+
self._lib = lib
|
|
238
|
+
self._h: int | None = handle
|
|
239
|
+
|
|
240
|
+
def _handle(self) -> int:
|
|
241
|
+
if self._h is None:
|
|
242
|
+
raise ArgumentError("the system is closed")
|
|
243
|
+
return self._h
|
|
244
|
+
|
|
245
|
+
def _check(self, rc: int, what: str) -> None:
|
|
246
|
+
if rc != 0:
|
|
247
|
+
raise self._lib._error(what)
|
|
248
|
+
|
|
249
|
+
def define(self, source: str) -> None:
|
|
250
|
+
"""Import DBDGEN or PSBGEN source text."""
|
|
251
|
+
b = source.encode("latin-1")
|
|
252
|
+
self._check(self._lib._dll.oliviadb_define(self._handle(), b, len(b)), "define")
|
|
253
|
+
|
|
254
|
+
def load_library(self, directory: str | os.PathLike[str]) -> None:
|
|
255
|
+
"""Import every *.dbd and *.psb file of a directory."""
|
|
256
|
+
self._check(self._lib._dll.oliviadb_load_library(self._handle(), _path(directory)), "load library")
|
|
257
|
+
|
|
258
|
+
def map_database(self, dbd: str, path: str | os.PathLike[str]) -> None:
|
|
259
|
+
"""Keep database dbd (and its secondary indexes) in the store at path, before its first use."""
|
|
260
|
+
self._check(self._lib._dll.oliviadb_map_database(self._handle(), _name(dbd), _path(path)), "map database")
|
|
261
|
+
|
|
262
|
+
def set_dd(self, dd: str, dataset: str | os.PathLike[str] | None) -> None:
|
|
263
|
+
"""The data set of a GSAM or HSAM DD for programs scheduled afterwards; None: a dummy."""
|
|
264
|
+
ds = None if dataset is None else _path(dataset)
|
|
265
|
+
self._check(self._lib._dll.oliviadb_set_dd(self._handle(), _name(dd), ds), "set DD")
|
|
266
|
+
|
|
267
|
+
def schedule(self, psb: str, runtime: Runtime) -> Program:
|
|
268
|
+
"""Schedule a program with PSB psb; end it with terminate (commit) or abort (backout)."""
|
|
269
|
+
h = self._lib._dll.oliviadb_schedule(self._handle(), _name(psb), int(runtime))
|
|
270
|
+
if not h:
|
|
271
|
+
raise self._lib._error(f"schedule {psb}")
|
|
272
|
+
return Program(self, h, Runtime(runtime))
|
|
273
|
+
|
|
274
|
+
def close(self) -> None:
|
|
275
|
+
if self._h is not None:
|
|
276
|
+
self._lib._dll.oliviadb_close(self._h)
|
|
277
|
+
self._h = None
|
|
278
|
+
|
|
279
|
+
def __enter__(self) -> System:
|
|
280
|
+
return self
|
|
281
|
+
|
|
282
|
+
def __exit__(self, *exc: object) -> None:
|
|
283
|
+
self.close()
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
class Pcb:
|
|
287
|
+
"""A copy of a PCB mask as the last call left it. Offsets: IMS 15.5 Application Programming,
|
|
288
|
+
"Specifying the I/O PCB mask", Table 34 (page 208), and "Specifying the DB PCB mask",
|
|
289
|
+
Table 35 (page 212). Character fields are in the program's character set."""
|
|
290
|
+
|
|
291
|
+
def __init__(self, data: bytes, io: bool, big_endian: bool) -> None:
|
|
292
|
+
self.bytes = data
|
|
293
|
+
self.is_io_pcb = io
|
|
294
|
+
self._order: Any = "big" if big_endian else "little"
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def status(self) -> bytes:
|
|
298
|
+
"""Status code, bytes 11-12 of both masks (note 3)."""
|
|
299
|
+
return self.bytes[10:12]
|
|
300
|
+
|
|
301
|
+
def _db(self) -> bytes:
|
|
302
|
+
if self.is_io_pcb:
|
|
303
|
+
raise ArgumentError("the I/O PCB has no database fields")
|
|
304
|
+
return self.bytes
|
|
305
|
+
|
|
306
|
+
@property
|
|
307
|
+
def dbd_name(self) -> bytes:
|
|
308
|
+
return self._db()[0:8]
|
|
309
|
+
|
|
310
|
+
@property
|
|
311
|
+
def level(self) -> bytes:
|
|
312
|
+
return self._db()[8:10]
|
|
313
|
+
|
|
314
|
+
@property
|
|
315
|
+
def processing_options(self) -> bytes:
|
|
316
|
+
return self._db()[12:16]
|
|
317
|
+
|
|
318
|
+
@property
|
|
319
|
+
def segment_name(self) -> bytes:
|
|
320
|
+
return self._db()[20:28]
|
|
321
|
+
|
|
322
|
+
@property
|
|
323
|
+
def key_feedback_len(self) -> int:
|
|
324
|
+
return int.from_bytes(self._db()[28:32], self._order)
|
|
325
|
+
|
|
326
|
+
@property
|
|
327
|
+
def sensitive_segments(self) -> int:
|
|
328
|
+
return int.from_bytes(self._db()[32:36], self._order)
|
|
329
|
+
|
|
330
|
+
@property
|
|
331
|
+
def key_feedback(self) -> bytes:
|
|
332
|
+
n = min(self.key_feedback_len, max(len(self.bytes) - 36, 0))
|
|
333
|
+
return self._db()[36 : 36 + n]
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
class Program:
|
|
337
|
+
"""A scheduled program: its PCBs, its DL/I calls, its unit of work. One thread at a time."""
|
|
338
|
+
|
|
339
|
+
def __init__(self, system: System, handle: int, runtime: Runtime) -> None:
|
|
340
|
+
self._system = system
|
|
341
|
+
self._dll = system._lib._dll
|
|
342
|
+
self._h: int | None = handle
|
|
343
|
+
self.runtime = runtime
|
|
344
|
+
|
|
345
|
+
def _handle(self) -> int:
|
|
346
|
+
if self._h is None:
|
|
347
|
+
raise ArgumentError("the program has ended")
|
|
348
|
+
return self._h
|
|
349
|
+
|
|
350
|
+
def pcb_count(self) -> int:
|
|
351
|
+
"""The I/O PCB (0) and the PSB's PCBs (1..)."""
|
|
352
|
+
return max(int(self._dll.oliviadb_pcb_count(self._handle())), 0)
|
|
353
|
+
|
|
354
|
+
def io_size(self, pcb: int) -> int:
|
|
355
|
+
"""Bytes of the I/O area the library may read or write for calls on PCB pcb."""
|
|
356
|
+
return int(self._dll.oliviadb_io_size(self._handle(), pcb))
|
|
357
|
+
|
|
358
|
+
def pcb(self, pcb: int) -> Pcb:
|
|
359
|
+
"""A copy of PCB pcb's mask."""
|
|
360
|
+
self._pcb_index(pcb)
|
|
361
|
+
n = int(self._dll.oliviadb_mask_len(self._h, pcb))
|
|
362
|
+
addr = self._dll.oliviadb_pcb_address(self._h, pcb)
|
|
363
|
+
if not addr:
|
|
364
|
+
raise self._system._lib._error("PCB address")
|
|
365
|
+
return Pcb(ctypes.string_at(addr, n), pcb == 0, self.runtime != Runtime.ASCII_LE)
|
|
366
|
+
|
|
367
|
+
def _pcb_index(self, pcb: int) -> None:
|
|
368
|
+
n = self.pcb_count()
|
|
369
|
+
if not 0 <= pcb < n:
|
|
370
|
+
raise ArgumentError(f"PCB {pcb}: the program has {n} PCBs")
|
|
371
|
+
|
|
372
|
+
def call(self, pcb: int, func: str, io: bytearray, ssas: Sequence[bytes] = ()) -> Status:
|
|
373
|
+
"""A database call on PCB pcb: function (GU, GN, ISRT, ...; padded to 4), the I/O area
|
|
374
|
+
(written in place) and the SSAs. Names and function codes are ASCII: an EBCDIC program
|
|
375
|
+
uses call_bytes."""
|
|
376
|
+
if self.runtime == Runtime.EBCDIC:
|
|
377
|
+
raise ArgumentError("the function code of an EBCDIC program is EBCDIC bytes: use call_bytes")
|
|
378
|
+
if not (1 <= len(func) <= 4) or not func.isascii() or not func.isprintable() or " " in func:
|
|
379
|
+
raise ArgumentError(f"function code {func!r}: 1 to 4 ASCII characters")
|
|
380
|
+
return self.call_bytes(pcb, func.ljust(4).encode(), [io, *(bytearray(s) for s in ssas)])
|
|
381
|
+
|
|
382
|
+
def call_bytes(self, pcb: int, func: bytes, args: Sequence[bytearray]) -> Status:
|
|
383
|
+
"""A call with the function code as the program's 4 bytes and every argument after the
|
|
384
|
+
PCB: database calls the I/O area then the SSAs; system service calls on the I/O PCB (0)
|
|
385
|
+
their argument areas. The library writes into the areas it returns data in."""
|
|
386
|
+
self._pcb_index(pcb)
|
|
387
|
+
if len(func) != 4:
|
|
388
|
+
raise ArgumentError("the function code is 4 bytes")
|
|
389
|
+
bufs = [
|
|
390
|
+
(ctypes.c_char * max(len(a), 1)).from_buffer(a) if len(a) else ctypes.create_string_buffer(1) for a in args
|
|
391
|
+
]
|
|
392
|
+
arr = (_Arg * max(len(args), 1))()
|
|
393
|
+
for i, (a, b) in enumerate(zip(args, bufs, strict=True)):
|
|
394
|
+
arr[i].ptr = ctypes.addressof(b)
|
|
395
|
+
arr[i].len = len(a)
|
|
396
|
+
rc = int(self._dll.oliviadb_call(self._h, pcb, func, None, 0, arr, len(args)))
|
|
397
|
+
if rc == -1:
|
|
398
|
+
raise self._system._lib._error("call")
|
|
399
|
+
if rc == -2:
|
|
400
|
+
raise AbendError(self.abend_code())
|
|
401
|
+
if rc == -3:
|
|
402
|
+
raise LockWaitError("the call waits for a lock another program holds")
|
|
403
|
+
return Status._of(rc)
|
|
404
|
+
|
|
405
|
+
def abend_code(self) -> str:
|
|
406
|
+
c = self._dll.oliviadb_abend_code(self._handle())
|
|
407
|
+
return c.decode(errors="replace") if c else ""
|
|
408
|
+
|
|
409
|
+
def sync(self) -> None:
|
|
410
|
+
"""Sync point for a program that goes on: commit, release locks, positions reset."""
|
|
411
|
+
if self._dll.oliviadb_sync(self._handle()) != 0:
|
|
412
|
+
raise self._system._lib._error("sync")
|
|
413
|
+
|
|
414
|
+
def backout(self) -> None:
|
|
415
|
+
"""Back out the updates since the last sync point and go on."""
|
|
416
|
+
if self._dll.oliviadb_backout(self._handle()) != 0:
|
|
417
|
+
raise self._system._lib._error("backout")
|
|
418
|
+
|
|
419
|
+
def terminate(self) -> None:
|
|
420
|
+
"""End the program normally: its updates are committed."""
|
|
421
|
+
h = self._handle()
|
|
422
|
+
self._h = None
|
|
423
|
+
if self._dll.oliviadb_terminate(h) != 0:
|
|
424
|
+
raise self._system._lib._error("terminate")
|
|
425
|
+
|
|
426
|
+
def abort(self) -> None:
|
|
427
|
+
"""End the program abnormally: its uncommitted updates are discarded."""
|
|
428
|
+
if self._h is not None:
|
|
429
|
+
h, self._h = self._h, None
|
|
430
|
+
self._dll.oliviadb_abort(h)
|
|
431
|
+
|
|
432
|
+
def __del__(self) -> None:
|
|
433
|
+
# A program that was not ended backs out, as an abnormal end does (at interpreter
|
|
434
|
+
# shutdown the library may be gone already).
|
|
435
|
+
with contextlib.suppress(Exception):
|
|
436
|
+
self.abort()
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
class Ssa:
|
|
440
|
+
"""A segment search argument, by IMS 15.5 Application Programming, "SSA coding rules"
|
|
441
|
+
(page 222): the segment name in 8 bytes; byte 9 a blank when nothing follows, ``*`` before
|
|
442
|
+
command codes (the last followed by a blank or the qualification's left parenthesis); a
|
|
443
|
+
qualification in parentheses of statements (field name in 8 bytes, a 2-byte relational
|
|
444
|
+
operator of Table 38, the value as long as the field) joined by ``*`` (dependent AND),
|
|
445
|
+
``+`` (OR) or ``#`` (independent AND). Names are ASCII; values are the program's bytes."""
|
|
446
|
+
|
|
447
|
+
_OPS: ClassVar[dict[str, bytes]] = {
|
|
448
|
+
"=": b" =",
|
|
449
|
+
">": b" >",
|
|
450
|
+
"<": b" <",
|
|
451
|
+
"¬=": b"\xac=",
|
|
452
|
+
"=¬": b"=\xac",
|
|
453
|
+
**{o: o.encode() for o in (">=", "=>", "<=", "=<", "EQ", "GE", "LE", "GT", "LT", "NE")},
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
def __init__(self, segment: str) -> None:
|
|
457
|
+
self._segment = segment
|
|
458
|
+
self._codes = ""
|
|
459
|
+
self._quals: list[tuple[bytes, str, str, bytes]] = []
|
|
460
|
+
|
|
461
|
+
def command_codes(self, codes: str) -> Ssa:
|
|
462
|
+
self._codes += codes
|
|
463
|
+
return self
|
|
464
|
+
|
|
465
|
+
def qual(self, field: str, op: str, value: bytes) -> Ssa:
|
|
466
|
+
return self._push(b"", field, op, value)
|
|
467
|
+
|
|
468
|
+
def and_(self, field: str, op: str, value: bytes) -> Ssa:
|
|
469
|
+
return self._push(b"*", field, op, value)
|
|
470
|
+
|
|
471
|
+
def or_(self, field: str, op: str, value: bytes) -> Ssa:
|
|
472
|
+
return self._push(b"+", field, op, value)
|
|
473
|
+
|
|
474
|
+
def independent_and(self, field: str, op: str, value: bytes) -> Ssa:
|
|
475
|
+
return self._push(b"#", field, op, value)
|
|
476
|
+
|
|
477
|
+
def _push(self, join: bytes, field: str, op: str, value: bytes) -> Ssa:
|
|
478
|
+
self._quals.append((join, field, op, bytes(value)))
|
|
479
|
+
return self
|
|
480
|
+
|
|
481
|
+
@staticmethod
|
|
482
|
+
def _name8(name: str, what: str) -> bytes:
|
|
483
|
+
ok = 1 <= len(name) <= 8 and all(c.isascii() and (c.isalnum() or c in "@#$") for c in name)
|
|
484
|
+
if not ok:
|
|
485
|
+
raise ArgumentError(f"{what} {name!r}: 1 to 8 letters, digits, @, # or $")
|
|
486
|
+
return name.ljust(8).encode()
|
|
487
|
+
|
|
488
|
+
def build(self) -> bytes:
|
|
489
|
+
out = bytearray(self._name8(self._segment, "segment name"))
|
|
490
|
+
if self._codes:
|
|
491
|
+
if not all(c.isascii() and (c.isupper() or c == "-") for c in self._codes):
|
|
492
|
+
raise ArgumentError(f"command codes {self._codes!r}: letters A-Z and -")
|
|
493
|
+
out += b"*" + self._codes.encode()
|
|
494
|
+
if not self._quals:
|
|
495
|
+
return bytes(out + b" ")
|
|
496
|
+
out += b"("
|
|
497
|
+
for i, (join, field, op, value) in enumerate(self._quals):
|
|
498
|
+
if i == 0 and join:
|
|
499
|
+
raise ArgumentError("the first qualification statement comes from qual")
|
|
500
|
+
if i > 0 and not join:
|
|
501
|
+
raise ArgumentError("a further qualification statement takes and_, or_ or independent_and")
|
|
502
|
+
if op not in self._OPS:
|
|
503
|
+
raise ArgumentError(f"relational operator {op!r} is not one of Table 38")
|
|
504
|
+
out += join + self._name8(field, "field name") + self._OPS[op] + value
|
|
505
|
+
return bytes(out + b")")
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oliviadb-dli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DL/I calls from Python on OliviaDB: schedule programs on DBD/PSB definitions and make GU, GN, ISRT, REPL, DLET and the other calls
|
|
5
|
+
License-Expression: Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)
|
|
6
|
+
Project-URL: Homepage, https://olivia-db.com/
|
|
7
|
+
Project-URL: Documentation, https://docs.olivia-db.com/dli-quickstart/
|
|
8
|
+
Project-URL: Source, https://github.com/OliviaDB/oliviadb-python
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE-native.md
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
16
|
+
# oliviadb-dli
|
|
17
|
+
|
|
18
|
+
DL/I calls from Python on OliviaDB: open a store, import DBDGEN and PSBGEN source, schedule a
|
|
19
|
+
program on a PSB and make its calls (GU, GN, GNP, the hold forms, ISRT, REPL, DLET and the system
|
|
20
|
+
service calls) with I/O areas and segment search arguments, as an IMS program does through its PCBs.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from oliviadb_dli import Library, Runtime, Ssa
|
|
24
|
+
|
|
25
|
+
with Library.load().open("store") as system:
|
|
26
|
+
system.load_library("dli") # PARTDB.dbd, PARTPSB.psb
|
|
27
|
+
prog = system.schedule("PARTPSB", Runtime.ASCII_BE)
|
|
28
|
+
io = bytearray(prog.io_size(1))
|
|
29
|
+
status = prog.call(1, "GU", io, [Ssa("PART").qual("PARTNO", "=", b"P00001").build()])
|
|
30
|
+
print(status, bytes(io), prog.pcb(1).key_feedback)
|
|
31
|
+
prog.terminate() # commit; abort() backs out
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Licence
|
|
35
|
+
|
|
36
|
+
The Python code is Apache-2.0. The wheels for Linux (x86_64, aarch64) and macOS (arm64, x86_64)
|
|
37
|
+
also contain OliviaDB's DL/I library `liboliviadb_dli`, which is licensed under AGPL-3.0-only or
|
|
38
|
+
OliviaDB's commercial licence. A wheel as a whole is therefore
|
|
39
|
+
`Apache-2.0 AND (AGPL-3.0-only OR LicenseRef-OliviaDB-Commercial)`: using it is using the
|
|
40
|
+
AGPL-licensed library, unless you have OliviaDB's commercial licence. The source distribution
|
|
41
|
+
contains no library.
|
|
42
|
+
|
|
43
|
+
## The library
|
|
44
|
+
|
|
45
|
+
Loaded from the file `OLIVIADB_DLI_LIB` names, else the wheel's copy, else the system's library
|
|
46
|
+
search path. It needs C ABI version 13 or later (OliviaDB 0.1.0).
|
|
47
|
+
|
|
48
|
+
## Character sets
|
|
49
|
+
|
|
50
|
+
`Program.call` and `Ssa` write names, function codes and operators in ASCII, for programs
|
|
51
|
+
scheduled with `Runtime.ASCII_BE` or `Runtime.ASCII_LE`. A program scheduled with
|
|
52
|
+
`Runtime.EBCDIC` makes its calls with `Program.call_bytes` and SSAs in EBCDIC bytes of its own.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
NOTICE-native.md
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/oliviadb_dli/__init__.py
|
|
6
|
+
src/oliviadb_dli/py.typed
|
|
7
|
+
src/oliviadb_dli.egg-info/PKG-INFO
|
|
8
|
+
src/oliviadb_dli.egg-info/SOURCES.txt
|
|
9
|
+
src/oliviadb_dli.egg-info/dependency_links.txt
|
|
10
|
+
src/oliviadb_dli.egg-info/top_level.txt
|
|
11
|
+
tests/test_basic.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
oliviadb_dli
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""The scenario of the core's C ABI test tests/c/basic.c through this package, with the same
|
|
3
|
+
statuses and bytes: load a HIDAM database, LC for a root out of sequence (Messages and Codes,
|
|
4
|
+
Volume 4, "LC"), GU with a qualified SSA and its key feedback, GNP, a packed field compared
|
|
5
|
+
byte by byte (System Utilities, "FIELD statement", TYPE=), GN, GE and AC.
|
|
6
|
+
|
|
7
|
+
Needs the library: OLIVIADB_DLI_LIB names it, or the installed wheel carries it. Without it the
|
|
8
|
+
tests are skipped, said so, unless OLIVIADB_REQUIRE_DLI=1."""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import pathlib
|
|
14
|
+
import shutil
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
import tempfile
|
|
18
|
+
import unittest
|
|
19
|
+
|
|
20
|
+
import oliviadb_dli as dli
|
|
21
|
+
|
|
22
|
+
DBD = """ DBD NAME=BANKDB,ACCESS=(HIDAM,VSAM)
|
|
23
|
+
SEGM NAME=CUST,PARENT=0,BYTES=20
|
|
24
|
+
FIELD NAME=(CUSTNO,SEQ,U),BYTES=6,START=1,TYPE=C
|
|
25
|
+
FIELD NAME=CNAME,BYTES=10,START=7,TYPE=C
|
|
26
|
+
SEGM NAME=ACCT,PARENT=CUST,BYTES=12
|
|
27
|
+
FIELD NAME=(ACCTNO,SEQ,U),BYTES=4,START=1,TYPE=C
|
|
28
|
+
FIELD NAME=BAL,BYTES=4,START=5,TYPE=P
|
|
29
|
+
DBDGEN
|
|
30
|
+
FINISH
|
|
31
|
+
END
|
|
32
|
+
"""
|
|
33
|
+
PSBL = """ PCB TYPE=DB,DBDNAME=BANKDB,PROCOPT=L,KEYLEN=10
|
|
34
|
+
SENSEG NAME=CUST,PARENT=0
|
|
35
|
+
SENSEG NAME=ACCT,PARENT=CUST
|
|
36
|
+
PSBGEN LANG=COBOL,PSBNAME=LOADPSB,CMPAT=YES
|
|
37
|
+
END
|
|
38
|
+
"""
|
|
39
|
+
PSBA = """DBPCB PCB TYPE=DB,DBDNAME=BANKDB,PROCOPT=A,KEYLEN=10
|
|
40
|
+
SENSEG NAME=CUST,PARENT=0
|
|
41
|
+
SENSEG NAME=ACCT,PARENT=CUST
|
|
42
|
+
PSBGEN LANG=COBOL,PSBNAME=READPSB,CMPAT=YES
|
|
43
|
+
END
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def library() -> dli.Library:
|
|
48
|
+
try:
|
|
49
|
+
return dli.Library.load()
|
|
50
|
+
except dli.LoadError as e:
|
|
51
|
+
if os.environ.get("OLIVIADB_REQUIRE_DLI") == "1":
|
|
52
|
+
raise
|
|
53
|
+
raise unittest.SkipTest(f"SKIPPED: no DL/I library ({e})") from e
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class BasicScenario(unittest.TestCase):
|
|
57
|
+
def setUp(self) -> None:
|
|
58
|
+
self.lib = library()
|
|
59
|
+
self.dir = tempfile.mkdtemp(prefix="oliviadb-dli-py-")
|
|
60
|
+
self.addCleanup(shutil.rmtree, self.dir, True)
|
|
61
|
+
|
|
62
|
+
def test_basic_scenario(self) -> None:
|
|
63
|
+
self.assertGreaterEqual(self.lib.abi_version(), 13)
|
|
64
|
+
with self.lib.open(self.dir) as sys_:
|
|
65
|
+
sys_.define(DBD)
|
|
66
|
+
sys_.define(PSBL)
|
|
67
|
+
sys_.define(PSBA)
|
|
68
|
+
p = sys_.schedule("LOADPSB", dli.Runtime.ASCII_BE)
|
|
69
|
+
self.assertEqual(p.pcb_count(), 2)
|
|
70
|
+
self.assertEqual(p.pcb(1).dbd_name, b"BANKDB ", "PCB DBD name at program start")
|
|
71
|
+
cust, acct = dli.Ssa("CUST").build(), dli.Ssa("ACCT").build()
|
|
72
|
+
custs = [b"C00001ALPHA XXXX", b"C00002BRAVO XXXX", b"C00003CHARLIE XXXX"]
|
|
73
|
+
for c in custs:
|
|
74
|
+
self.assertEqual(p.call(1, "ISRT", bytearray(c), [cust]), " ", "load customer")
|
|
75
|
+
for a in range(2):
|
|
76
|
+
seg = bytearray(b"A00" + bytes([ord("1") + a]) + b"\x00\x01\x23\x4c ")
|
|
77
|
+
self.assertTrue(p.call(1, "ISRT", seg, [acct]).blank, "load account")
|
|
78
|
+
self.assertEqual(p.call(1, "ISRT", bytearray(custs[1]), [cust]), "LC")
|
|
79
|
+
p.terminate()
|
|
80
|
+
|
|
81
|
+
p = sys_.schedule("READPSB", dli.Runtime.ASCII_BE)
|
|
82
|
+
io = bytearray(b" " * 64)
|
|
83
|
+
q = dli.Ssa("CUST").qual("CUSTNO", "=", b"C00002").build()
|
|
84
|
+
self.assertEqual(q, b"CUST (CUSTNO =C00002)")
|
|
85
|
+
self.assertTrue(p.call(1, "GU", io, [q]).blank)
|
|
86
|
+
self.assertEqual(io[:11], b"C00002BRAVO")
|
|
87
|
+
pcb = p.pcb(1)
|
|
88
|
+
self.assertEqual(pcb.key_feedback[:6], b"C00002", "key feedback")
|
|
89
|
+
self.assertEqual(pcb.level, b"01")
|
|
90
|
+
self.assertEqual(pcb.segment_name, b"CUST ")
|
|
91
|
+
|
|
92
|
+
self.assertTrue(p.call(1, "GNP", io).blank)
|
|
93
|
+
self.assertEqual(io[:4], b"A001")
|
|
94
|
+
pcb = p.pcb(1)
|
|
95
|
+
self.assertEqual(pcb.key_feedback, b"C00002A001")
|
|
96
|
+
self.assertEqual(pcb.key_feedback_len, 10)
|
|
97
|
+
self.assertEqual(pcb.bytes[31], 10, "key feedback length, a big-endian fullword")
|
|
98
|
+
|
|
99
|
+
# A packed field is compared byte by byte: +1234 with sign F does not equal the
|
|
100
|
+
# stored +1234 with sign C; with sign C it does.
|
|
101
|
+
qp = dli.Ssa("CUST").qual("CUSTNO", "=", b"C00003").build()
|
|
102
|
+
qf = dli.Ssa("ACCT").qual("BAL", "=", b"\x00\x01\x23\x4f").build()
|
|
103
|
+
self.assertEqual(p.call(1, "GU", io, [qp, qf]), "GE")
|
|
104
|
+
qc = dli.Ssa("ACCT").qual("BAL", "=", b"\x00\x01\x23\x4c").build()
|
|
105
|
+
self.assertTrue(p.call(1, "GU", io, [qp, qc]).blank)
|
|
106
|
+
self.assertEqual(p.pcb(1).key_feedback, b"C00003A001")
|
|
107
|
+
|
|
108
|
+
self.assertTrue(p.call(1, "GN", io).blank)
|
|
109
|
+
self.assertEqual(io[:4], b"A002")
|
|
110
|
+
|
|
111
|
+
nf = dli.Ssa("CUST").qual("CUSTNO", "=", b"C00009").build()
|
|
112
|
+
self.assertEqual(p.call(1, "GU", io, [nf]), "GE")
|
|
113
|
+
self.assertEqual(p.call(1, "GU", io, [dli.Ssa("NOSUCH").build()]), "AC")
|
|
114
|
+
self.assertEqual(p.pcb(1).status, b"AC", "status in the PCB")
|
|
115
|
+
p.abort()
|
|
116
|
+
|
|
117
|
+
def test_commit_at_terminate_not_at_abort(self) -> None:
|
|
118
|
+
with self.lib.open(self.dir) as sys_:
|
|
119
|
+
sys_.define(DBD)
|
|
120
|
+
sys_.define(PSBA)
|
|
121
|
+
cust = dli.Ssa("CUST").build()
|
|
122
|
+
p = sys_.schedule("READPSB", dli.Runtime.ASCII_BE)
|
|
123
|
+
self.assertTrue(p.call(1, "ISRT", bytearray(b"C00001ALPHA XXXX"), [cust]).blank)
|
|
124
|
+
p.terminate()
|
|
125
|
+
p = sys_.schedule("READPSB", dli.Runtime.ASCII_BE)
|
|
126
|
+
self.assertTrue(p.call(1, "ISRT", bytearray(b"C00002BRAVO XXXX"), [cust]).blank)
|
|
127
|
+
p.abort()
|
|
128
|
+
p = sys_.schedule("READPSB", dli.Runtime.ASCII_BE)
|
|
129
|
+
io = bytearray(20)
|
|
130
|
+
self.assertTrue(p.call(1, "GN", io, [cust]).blank)
|
|
131
|
+
self.assertEqual(io, b"C00001ALPHA XXXX")
|
|
132
|
+
# Only the committed root: an unqualified GN reaches the end of the database, GB
|
|
133
|
+
# (Messages and Codes, Volume 4, IMS 15.5, "GB", page 156).
|
|
134
|
+
self.assertEqual(p.call(1, "GN", io), "GB")
|
|
135
|
+
p.terminate()
|
|
136
|
+
|
|
137
|
+
def test_errors(self) -> None:
|
|
138
|
+
with self.lib.open(self.dir) as sys_:
|
|
139
|
+
with self.assertRaises(dli.LibraryError):
|
|
140
|
+
sys_.define(" NOT A STATEMENT\n")
|
|
141
|
+
with self.assertRaises(dli.LibraryError):
|
|
142
|
+
sys_.schedule("NOSUCH", dli.Runtime.ASCII_BE)
|
|
143
|
+
sys_.define(DBD)
|
|
144
|
+
sys_.define(PSBA)
|
|
145
|
+
p = sys_.schedule("READPSB", dli.Runtime.ASCII_BE)
|
|
146
|
+
with self.assertRaises(dli.ArgumentError):
|
|
147
|
+
p.call(5, "GU", bytearray(20))
|
|
148
|
+
with self.assertRaises(dli.ArgumentError):
|
|
149
|
+
p.call(1, "TOOLONG", bytearray(20))
|
|
150
|
+
p.abort()
|
|
151
|
+
e = sys_.schedule("READPSB", dli.Runtime.EBCDIC)
|
|
152
|
+
with self.assertRaises(dli.ArgumentError):
|
|
153
|
+
e.call(1, "GU", bytearray(20))
|
|
154
|
+
e.abort()
|
|
155
|
+
with self.assertRaises(dli.LoadError):
|
|
156
|
+
dli.Library("/nonexistent/liboliviadb_dli.so")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class SsaForms(unittest.TestCase):
|
|
160
|
+
def test_forms(self) -> None:
|
|
161
|
+
self.assertEqual(dli.Ssa("PART").build(), b"PART ")
|
|
162
|
+
self.assertEqual(dli.Ssa("PART").command_codes("D").build(), b"PART *D ")
|
|
163
|
+
self.assertEqual(
|
|
164
|
+
dli.Ssa("A").qual("F", "<", b"1").and_("G", "¬=", b"2").independent_and("H", "NE", b"3").build(),
|
|
165
|
+
b"A (F <1*G \xac=2#H NE3)",
|
|
166
|
+
)
|
|
167
|
+
for bad in (
|
|
168
|
+
dli.Ssa("TOOLONGNAME"),
|
|
169
|
+
dli.Ssa("A").qual("F", "==", b"1"),
|
|
170
|
+
dli.Ssa("A").command_codes("d"),
|
|
171
|
+
dli.Ssa("A").and_("F", "=", b"1"),
|
|
172
|
+
):
|
|
173
|
+
with self.assertRaises(dli.ArgumentError):
|
|
174
|
+
bad.build()
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class Bundled(unittest.TestCase):
|
|
178
|
+
"""The wheel's copy (oliviadb_dli/lib/): a Python without OLIVIADB_DLI_LIB loads it.
|
|
179
|
+
check.sh puts the library there and sets OLIVIADB_REQUIRE_BUNDLED=1."""
|
|
180
|
+
|
|
181
|
+
def test_the_packages_copy_is_loaded(self) -> None:
|
|
182
|
+
pkg = pathlib.Path(dli.__file__).parent
|
|
183
|
+
bundled = pkg / "lib" / dli.library_file_name()
|
|
184
|
+
if not bundled.is_file():
|
|
185
|
+
if os.environ.get("OLIVIADB_REQUIRE_BUNDLED") == "1":
|
|
186
|
+
self.fail(f"OLIVIADB_REQUIRE_BUNDLED=1 but there is no {bundled}")
|
|
187
|
+
raise unittest.SkipTest(f"SKIPPED: no {bundled}")
|
|
188
|
+
env = {k: v for k, v in os.environ.items() if k != "OLIVIADB_DLI_LIB"}
|
|
189
|
+
code = "import oliviadb_dli as d; lib = d.Library.load(); print(lib.path, lib.abi_version())"
|
|
190
|
+
out = subprocess.run([sys.executable, "-c", code], env=env, capture_output=True, text=True, check=True)
|
|
191
|
+
path, abi = out.stdout.split()
|
|
192
|
+
self.assertEqual(pathlib.Path(path), bundled)
|
|
193
|
+
self.assertGreaterEqual(int(abi), 13)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if __name__ == "__main__":
|
|
197
|
+
unittest.main()
|