cutienator 0.0.1.dev0__py3-none-any.whl
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.
- cutienator/__init__.py +44 -0
- cutienator/_cpp_addr.py +84 -0
- cutienator/_cpp_box.py +23 -0
- cutienator/_cute_load_hook.py +159 -0
- cutienator/_cute_mixin.py +166 -0
- cutienator/_cute_overload.py +285 -0
- cutienator/_cute_space.py +727 -0
- cutienator/_header_descriptor.py +4 -0
- cutienator/_meta_cute.py +444 -0
- cutienator/_q_binding_storage.py +101 -0
- cutienator/_q_event.py +185 -0
- cutienator/_q_meta_object.py +118 -0
- cutienator/_q_object.py +582 -0
- cutienator/_q_thread.py +106 -0
- cutienator/_q_widget.py +80 -0
- cutienator/_ugly.py +296 -0
- cutienator/_wait.py +303 -0
- cutienator/_waiting_overload.py +261 -0
- cutienator/example/__init__.py +21 -0
- cutienator/example/__main__.py +67 -0
- cutienator/example/_calls.py +107 -0
- cutienator/occult/__init__.py +27 -0
- cutienator/occult/__main__.py +50 -0
- cutienator/occult/_base_meta_ugly.py +29 -0
- cutienator/occult/_build.py +561 -0
- cutienator/occult/_cognito_warning.py +35 -0
- cutienator/occult/_declaration.py +572 -0
- cutienator/occult/_header.py +710 -0
- cutienator/occult/_ritual.py +19 -0
- cutienator/occult/_rituals.py +594 -0
- cutienator/occult/_shared_object.py +292 -0
- cutienator/occult/_symbol.py +162 -0
- cutienator/occult/rituals/q_event.cpp +70 -0
- cutienator/occult/rituals/q_meta_object.cpp +173 -0
- cutienator/occult/rituals/q_object.cpp +178 -0
- cutienator/trial/__init__.py +25 -0
- cutienator/trial/__main__.py +59 -0
- cutienator/trial/_judge.py +589 -0
- cutienator/trial/_q_object_trials.py +38 -0
- cutienator/trial/_trial.py +495 -0
- cutienator/trial/_verdict.py +332 -0
- cutienator-0.0.1.dev0.dist-info/METADATA +33 -0
- cutienator-0.0.1.dev0.dist-info/RECORD +46 -0
- cutienator-0.0.1.dev0.dist-info/WHEEL +5 -0
- cutienator-0.0.1.dev0.dist-info/licenses/LICENSE +201 -0
- cutienator-0.0.1.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WaitingOverload is what a waiting signature leaves at a name in a class
|
|
3
|
+
body.
|
|
4
|
+
"""
|
|
5
|
+
# Apache-2.0 license
|
|
6
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from types import FunctionType
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
from worktoy.waitaminute import MissingVariable, TypeException
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING: # pragma: no cover, no mutate
|
|
15
|
+
from typing import Any, Callable, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class WaitingOverload:
|
|
19
|
+
"""
|
|
20
|
+
Holds one function of a class body together with a signature that
|
|
21
|
+
names a late class, until the late class is made. See 'WAIT' for the
|
|
22
|
+
whole story; this is step 3 and 4 of it.
|
|
23
|
+
|
|
24
|
+
You never make one yourself. 'CuteOverload' makes it where worktoy's
|
|
25
|
+
'overload' would have made its own record, and 'CuteSpace' takes it
|
|
26
|
+
out of the class body as it is bound:
|
|
27
|
+
|
|
28
|
+
QThread = WAIT['QThread']
|
|
29
|
+
|
|
30
|
+
@overload(QThread) # 'CuteOverload' in a cute body
|
|
31
|
+
def moveToThread(self, thread): ... # the name is bound to a
|
|
32
|
+
# 'WaitingOverload' here
|
|
33
|
+
|
|
34
|
+
Terms
|
|
35
|
+
-----
|
|
36
|
+
|
|
37
|
+
- A signature entry is one thing between the brackets of
|
|
38
|
+
'@overload(...)': a class, 'THIS', or a 'WAIT'.
|
|
39
|
+
- A method kind is 'classmethod' or 'staticmethod'. A function with
|
|
40
|
+
neither is an instance method.
|
|
41
|
+
|
|
42
|
+
Provided by 'CuteOverload'
|
|
43
|
+
--------------------------
|
|
44
|
+
|
|
45
|
+
- 'setSignatureEntries': what stood between the brackets. Required.
|
|
46
|
+
- 'setFunction': the function under the decorator. Required.
|
|
47
|
+
- 'setMethodKinds': each '@classmethod' or '@staticmethod' written
|
|
48
|
+
between the decorator and the function. Required, also when there
|
|
49
|
+
is none.
|
|
50
|
+
|
|
51
|
+
What to expect
|
|
52
|
+
--------------
|
|
53
|
+
|
|
54
|
+
- It only holds. It checks nothing about the signature and calls
|
|
55
|
+
nothing.
|
|
56
|
+
- It is no function and cannot be called. One left on a class would
|
|
57
|
+
mean that a body other than a cute one used 'CuteOverload'.
|
|
58
|
+
- 'CuteSpace' replaces the entries as late classes are made, through
|
|
59
|
+
'setSignatureEntries', until no 'WAIT' is left among them.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
63
|
+
# STATIC METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
64
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
65
|
+
|
|
66
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
67
|
+
# NAMESPACE # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
68
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
69
|
+
|
|
70
|
+
# Class Variables
|
|
71
|
+
|
|
72
|
+
# Fallback Variables
|
|
73
|
+
|
|
74
|
+
# Private Variables
|
|
75
|
+
__signature_entries__: Optional[Tuple[Any, ...]] = None
|
|
76
|
+
__waiting_function__: Optional[Callable] = None
|
|
77
|
+
__method_kinds__: Optional[Tuple[Any, ...]] = None
|
|
78
|
+
|
|
79
|
+
# Public Variables
|
|
80
|
+
|
|
81
|
+
# Virtual Variables
|
|
82
|
+
|
|
83
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
84
|
+
# GETTERS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
85
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
86
|
+
|
|
87
|
+
def getSignatureEntries(self) -> Tuple[Any, ...]:
|
|
88
|
+
"""
|
|
89
|
+
Gives the entries of the waiting signature, in the order they were
|
|
90
|
+
written: classes, 'THIS', and at least one 'WAIT' until the last
|
|
91
|
+
late class among them is made.
|
|
92
|
+
|
|
93
|
+
Provided through 'setSignatureEntries'.
|
|
94
|
+
|
|
95
|
+
Raises
|
|
96
|
+
------
|
|
97
|
+
|
|
98
|
+
MissingVariable
|
|
99
|
+
'setSignatureEntries' has not been called.
|
|
100
|
+
"""
|
|
101
|
+
if self.__signature_entries__ is None:
|
|
102
|
+
raise MissingVariable(self, '__signature_entries__', tuple)
|
|
103
|
+
return self.__signature_entries__
|
|
104
|
+
|
|
105
|
+
def getFunction(self) -> Callable:
|
|
106
|
+
"""
|
|
107
|
+
Gives the function the waiting signature belongs to, without any
|
|
108
|
+
'classmethod' or 'staticmethod' around it.
|
|
109
|
+
|
|
110
|
+
Provided through 'setFunction'.
|
|
111
|
+
|
|
112
|
+
Raises
|
|
113
|
+
------
|
|
114
|
+
|
|
115
|
+
MissingVariable
|
|
116
|
+
'setFunction' has not been called.
|
|
117
|
+
"""
|
|
118
|
+
if self.__waiting_function__ is None:
|
|
119
|
+
raise MissingVariable(self, '__waiting_function__', FunctionType)
|
|
120
|
+
return self.__waiting_function__
|
|
121
|
+
|
|
122
|
+
def getMethodKinds(self) -> Tuple[Any, ...]:
|
|
123
|
+
"""
|
|
124
|
+
Gives the method kinds written between the decorator and the
|
|
125
|
+
function, outermost first. It is empty for an instance method.
|
|
126
|
+
|
|
127
|
+
Provided through 'setMethodKinds'.
|
|
128
|
+
|
|
129
|
+
Raises
|
|
130
|
+
------
|
|
131
|
+
|
|
132
|
+
MissingVariable
|
|
133
|
+
'setMethodKinds' has not been called.
|
|
134
|
+
"""
|
|
135
|
+
if self.__method_kinds__ is None:
|
|
136
|
+
raise MissingVariable(self, '__method_kinds__', tuple)
|
|
137
|
+
return self.__method_kinds__
|
|
138
|
+
|
|
139
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
140
|
+
# SETTERS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
141
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
142
|
+
|
|
143
|
+
def setSignatureEntries(self, *signatureEntries: Any) -> None:
|
|
144
|
+
"""
|
|
145
|
+
Tells which entries the waiting signature has.
|
|
146
|
+
|
|
147
|
+
Required. Calling it again replaces the entries, which is how
|
|
148
|
+
'CuteSpace' puts a class in the place of its 'WAIT'.
|
|
149
|
+
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
|
|
153
|
+
*signatureEntries : Any
|
|
154
|
+
One or more entries, in the order they were written.
|
|
155
|
+
|
|
156
|
+
Raises
|
|
157
|
+
------
|
|
158
|
+
|
|
159
|
+
ValueError
|
|
160
|
+
Called with no entry at all. A signature without entries names no
|
|
161
|
+
late class and has no reason to wait.
|
|
162
|
+
"""
|
|
163
|
+
if not signatureEntries:
|
|
164
|
+
infoSpec = """A waiting signature has at least one entry, and none
|
|
165
|
+
was given."""
|
|
166
|
+
raise ValueError(' '.join(infoSpec.split()))
|
|
167
|
+
self.__signature_entries__ = (*signatureEntries,)
|
|
168
|
+
|
|
169
|
+
def setFunction(self, function: Callable) -> None:
|
|
170
|
+
"""
|
|
171
|
+
Tells which function the waiting signature belongs to.
|
|
172
|
+
|
|
173
|
+
Required. Calling it again replaces the function given before.
|
|
174
|
+
|
|
175
|
+
Parameters
|
|
176
|
+
----------
|
|
177
|
+
|
|
178
|
+
function : Callable
|
|
179
|
+
The function itself, taken out of any 'classmethod' or
|
|
180
|
+
'staticmethod' around it.
|
|
181
|
+
|
|
182
|
+
Raises
|
|
183
|
+
------
|
|
184
|
+
|
|
185
|
+
TypeException
|
|
186
|
+
'function' cannot be called.
|
|
187
|
+
"""
|
|
188
|
+
if not callable(function):
|
|
189
|
+
raise TypeException('function', function, FunctionType)
|
|
190
|
+
self.__waiting_function__ = function
|
|
191
|
+
|
|
192
|
+
def setMethodKinds(self, *methodKinds: Any) -> None:
|
|
193
|
+
"""
|
|
194
|
+
Tells which method kinds were written between the decorator and the
|
|
195
|
+
function.
|
|
196
|
+
|
|
197
|
+
Required, also with nothing to give: no kind means an instance
|
|
198
|
+
method. Calling it again replaces the kinds given before.
|
|
199
|
+
|
|
200
|
+
Parameters
|
|
201
|
+
----------
|
|
202
|
+
|
|
203
|
+
*methodKinds : Any
|
|
204
|
+
Each 'classmethod' or 'staticmethod', outermost first.
|
|
205
|
+
|
|
206
|
+
Raises
|
|
207
|
+
------
|
|
208
|
+
|
|
209
|
+
TypeException
|
|
210
|
+
An entry is neither 'classmethod' nor 'staticmethod'.
|
|
211
|
+
"""
|
|
212
|
+
for methodKind in methodKinds:
|
|
213
|
+
if methodKind is not classmethod and methodKind is not staticmethod:
|
|
214
|
+
raise TypeException('methodKind', methodKind, type)
|
|
215
|
+
self.__method_kinds__ = (*methodKinds,)
|
|
216
|
+
|
|
217
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
218
|
+
# NOTIFIERS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
219
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
220
|
+
|
|
221
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
222
|
+
# Python API # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
223
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
224
|
+
|
|
225
|
+
def __str__(self) -> str:
|
|
226
|
+
"""Says which function waits, and for which signature."""
|
|
227
|
+
clsName = type(self).__name__
|
|
228
|
+
if self.__waiting_function__ is None:
|
|
229
|
+
return '<%s with no function yet>' % clsName
|
|
230
|
+
name = getattr(self.__waiting_function__, '__name__', '?')
|
|
231
|
+
entries = self.__signature_entries__ or ()
|
|
232
|
+
shown = ', '.join(
|
|
233
|
+
getattr(entry, '__name__', None) or str(entry) for entry in entries
|
|
234
|
+
)
|
|
235
|
+
return "<%s of '%s', waiting as (%s)>" % (clsName, name, shown)
|
|
236
|
+
|
|
237
|
+
__repr__ = __str__
|
|
238
|
+
|
|
239
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
240
|
+
# CONSTRUCTORS # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
241
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
242
|
+
|
|
243
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
244
|
+
# DOMAIN SPECIFIC # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
245
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
246
|
+
|
|
247
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
248
|
+
# OPTIONAL METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
249
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
250
|
+
|
|
251
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
252
|
+
# REQUIRED METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
253
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
254
|
+
|
|
255
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
256
|
+
# PARENT METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
257
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
258
|
+
|
|
259
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
260
|
+
# PUBLIC METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
261
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The 'cutienator.example' package shows the whole way from a Qt class to
|
|
3
|
+
Python once, for eleven of QObject's functions: the ritual files giving them
|
|
4
|
+
plain names, the class compiling those into a shared object, and the
|
|
5
|
+
calls into it.
|
|
6
|
+
|
|
7
|
+
python -m cutienator.example builds, then calls every function
|
|
8
|
+
"""
|
|
9
|
+
# Apache-2.0 license
|
|
10
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from ..occult import Build
|
|
14
|
+
from ._calls import SIGNATURES, openExample, readText
|
|
15
|
+
|
|
16
|
+
__all__ = (
|
|
17
|
+
'Build',
|
|
18
|
+
'SIGNATURES',
|
|
19
|
+
'openExample',
|
|
20
|
+
'readText',
|
|
21
|
+
)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Builds the example, then calls each of its functions and prints."""
|
|
2
|
+
# Apache-2.0 license
|
|
3
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from . import Build, openExample, readText
|
|
10
|
+
|
|
11
|
+
def main() -> int:
|
|
12
|
+
"""
|
|
13
|
+
Builds the shared object and calls every function it offers.
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
-------
|
|
17
|
+
|
|
18
|
+
int
|
|
19
|
+
The exit code, 0.
|
|
20
|
+
"""
|
|
21
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
22
|
+
build = Build()
|
|
23
|
+
build.setRitualFiles(
|
|
24
|
+
os.path.join(here, 'q_object.cpp'),
|
|
25
|
+
os.path.join(here, 'q_byte_array.cpp'),
|
|
26
|
+
)
|
|
27
|
+
build.setTargetFile(os.path.join(here, 'libexample.so'))
|
|
28
|
+
qtFolder = build.getQtSharedObjectFolder()
|
|
29
|
+
build.setQtSharedObjects(os.path.join(qtFolder, 'libQt6Core.so.6'))
|
|
30
|
+
print(build)
|
|
31
|
+
print('The command:')
|
|
32
|
+
print(' %s' % ' '.join(build.getCommand()))
|
|
33
|
+
print('Built: %s' % build.run())
|
|
34
|
+
ours = openExample(build.getTargetFile())
|
|
35
|
+
|
|
36
|
+
mother = ours.QObject_new(None)
|
|
37
|
+
child = ours.QObject_new(mother)
|
|
38
|
+
print('mother is at %s, child at %s' % (hex(mother), hex(child)))
|
|
39
|
+
|
|
40
|
+
same = ours.QObject_parent(child) == mother
|
|
41
|
+
print('child.parent() is mother: %s' % same)
|
|
42
|
+
print('mother.parent(): %s' % ours.QObject_parent(mother))
|
|
43
|
+
print('child.isWidgetType(): %s' % ours.QObject_isWidgetType(child))
|
|
44
|
+
|
|
45
|
+
before = ours.QObject_blockSignals(child, True)
|
|
46
|
+
print('child.blockSignals(True) gave the old state: %s' % before)
|
|
47
|
+
print('child.signalsBlocked(): %s' % ours.QObject_signalsBlocked(child))
|
|
48
|
+
|
|
49
|
+
for className in (b'QObject', b'QWidget'):
|
|
50
|
+
answer = ours.QObject_inherits(child, className)
|
|
51
|
+
print('child.inherits(%r): %s' % (className, answer))
|
|
52
|
+
|
|
53
|
+
ours.QObject_setObjectName(child, 'småkage'.encode('utf-8'))
|
|
54
|
+
name = readText(ours, ours.QObject_objectName(child))
|
|
55
|
+
print('child.objectName(): %r' % name)
|
|
56
|
+
|
|
57
|
+
ours.QObject_setParent(child, None)
|
|
58
|
+
print('after child.setParent(None): %s' % ours.QObject_parent(child))
|
|
59
|
+
|
|
60
|
+
ours.QObject_delete(child)
|
|
61
|
+
ours.QObject_delete(mother)
|
|
62
|
+
print('Both deleted, and Python is still alive.')
|
|
63
|
+
return 0
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == '__main__':
|
|
67
|
+
sys.exit(main())
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Opens the shared object of the example and readies its functions."""
|
|
2
|
+
# Apache-2.0 license
|
|
3
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import ctypes
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING: # pragma: no cover, no mutate
|
|
10
|
+
from typing import Any, Dict, Tuple
|
|
11
|
+
|
|
12
|
+
# The four kinds of value that cross between Python and C++ here.
|
|
13
|
+
ADDRESS = ctypes.c_void_p # where a C++ object is
|
|
14
|
+
FLAG = ctypes.c_bool # True or False
|
|
15
|
+
TEXT = ctypes.c_char_p # UTF-8 bytes handed to C++
|
|
16
|
+
COUNT = ctypes.c_longlong # a whole number
|
|
17
|
+
|
|
18
|
+
# For each function of the shared object: what comes back, then what
|
|
19
|
+
# goes in. This must say the same as the ritual files do, and nothing
|
|
20
|
+
# checks that it does.
|
|
21
|
+
SIGNATURES = {
|
|
22
|
+
'QObject_new': (ADDRESS, ADDRESS),
|
|
23
|
+
'QObject_delete': (None, ADDRESS),
|
|
24
|
+
'QObject_parent': (ADDRESS, ADDRESS),
|
|
25
|
+
'QObject_setParent': (None, ADDRESS, ADDRESS),
|
|
26
|
+
'QObject_isWidgetType': (FLAG, ADDRESS),
|
|
27
|
+
'QObject_signalsBlocked': (FLAG, ADDRESS),
|
|
28
|
+
'QObject_blockSignals': (FLAG, ADDRESS, FLAG),
|
|
29
|
+
'QObject_inherits': (FLAG, ADDRESS, TEXT),
|
|
30
|
+
'QObject_deleteLater': (None, ADDRESS),
|
|
31
|
+
'QObject_setObjectName': (None, ADDRESS, TEXT),
|
|
32
|
+
'QObject_objectName': (ADDRESS, ADDRESS),
|
|
33
|
+
'QByteArray_constData': (ADDRESS, ADDRESS),
|
|
34
|
+
'QByteArray_size': (COUNT, ADDRESS),
|
|
35
|
+
'QByteArray_delete': (None, ADDRESS),
|
|
36
|
+
} # type: Dict[str, Tuple[Any, ...]]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def openExample(path: str) -> ctypes.CDLL:
|
|
40
|
+
"""
|
|
41
|
+
Opens the shared object and tells 'ctypes' what goes in and out of
|
|
42
|
+
each function listed in 'SIGNATURES'.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
|
|
47
|
+
path : str
|
|
48
|
+
The path of the shared object, as 'Build.run' returns it.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
|
|
53
|
+
ctypes.CDLL
|
|
54
|
+
The opened shared object; each function is an attribute of it.
|
|
55
|
+
|
|
56
|
+
Raises
|
|
57
|
+
------
|
|
58
|
+
|
|
59
|
+
FileNotFoundError
|
|
60
|
+
There is no shared object at the path; 'Build.run' makes it.
|
|
61
|
+
|
|
62
|
+
LookupError
|
|
63
|
+
The shared object offers no function of a listed name.
|
|
64
|
+
"""
|
|
65
|
+
try:
|
|
66
|
+
ours = ctypes.CDLL(path)
|
|
67
|
+
except OSError as osError:
|
|
68
|
+
infoSpec = """There is no shared object at '%s' to open. 'Build.run'
|
|
69
|
+
makes it."""
|
|
70
|
+
info = ' '.join((infoSpec % path).split())
|
|
71
|
+
raise FileNotFoundError(info) from osError
|
|
72
|
+
for name, (gives, *takes) in SIGNATURES.items():
|
|
73
|
+
try:
|
|
74
|
+
function = getattr(ours, name)
|
|
75
|
+
except AttributeError as attributeError:
|
|
76
|
+
infoSpec = """'%s' offers no function named '%s'."""
|
|
77
|
+
raise LookupError(infoSpec % (path, name)) from attributeError
|
|
78
|
+
function.restype = gives
|
|
79
|
+
function.argtypes = takes
|
|
80
|
+
return ours
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def readText(ours: ctypes.CDLL, held: int) -> str:
|
|
84
|
+
"""
|
|
85
|
+
Reads the text of a QByteArray and deletes the QByteArray.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
|
|
90
|
+
ours : ctypes.CDLL
|
|
91
|
+
The opened shared object.
|
|
92
|
+
|
|
93
|
+
held : int
|
|
94
|
+
The address of the QByteArray, as a function returning text gives.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
|
|
99
|
+
str
|
|
100
|
+
The text.
|
|
101
|
+
"""
|
|
102
|
+
start = ours.QByteArray_constData(held)
|
|
103
|
+
size = ours.QByteArray_size(held)
|
|
104
|
+
try:
|
|
105
|
+
return ctypes.string_at(start, size).decode('utf-8')
|
|
106
|
+
finally:
|
|
107
|
+
ours.QByteArray_delete(held)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The 'cutienator.occult' package contains the [REDACTED] classes to
|
|
3
|
+
facility access to the other side.
|
|
4
|
+
"""
|
|
5
|
+
# Apache-2.0 license
|
|
6
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from ._cognito_warning import CognitoWarning
|
|
10
|
+
from ._base_meta_ugly import BaseMetaUgly
|
|
11
|
+
from ._symbol import Symbol
|
|
12
|
+
from ._shared_object import SharedObject
|
|
13
|
+
from ._build import Build
|
|
14
|
+
from ._rituals import Rituals
|
|
15
|
+
from ._declaration import Declaration
|
|
16
|
+
from ._header import Header
|
|
17
|
+
|
|
18
|
+
__all__ = (
|
|
19
|
+
'CognitoWarning',
|
|
20
|
+
'BaseMetaUgly',
|
|
21
|
+
'Symbol',
|
|
22
|
+
'SharedObject',
|
|
23
|
+
'Build',
|
|
24
|
+
'Rituals',
|
|
25
|
+
'Declaration',
|
|
26
|
+
'Header',
|
|
27
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Prints what a shared object offers.
|
|
3
|
+
|
|
4
|
+
python -m cutienator.occult FILE how many names FILE offers
|
|
5
|
+
python -m cutienator.occult FILE TEXT each function containing TEXT,
|
|
6
|
+
readable spelling, a tab, then
|
|
7
|
+
the stored spelling
|
|
8
|
+
"""
|
|
9
|
+
# Apache-2.0 license
|
|
10
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
from . import SharedObject
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main(*args: str) -> int:
|
|
19
|
+
"""
|
|
20
|
+
Prints what the shared object named by the arguments offers.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
|
|
25
|
+
*args : str
|
|
26
|
+
The path of the file, optionally followed by the text to look for.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
|
|
31
|
+
int
|
|
32
|
+
The exit code: 0, or 2 when the arguments are not one or two.
|
|
33
|
+
"""
|
|
34
|
+
if len(args) not in (1, 2):
|
|
35
|
+
print(__doc__.strip(), file=sys.stderr)
|
|
36
|
+
return 2
|
|
37
|
+
sharedObject = SharedObject(args[0])
|
|
38
|
+
if len(args) == 1:
|
|
39
|
+
infoSpec = """'%s' offers %d names, %d of them functions."""
|
|
40
|
+
counts = (len(sharedObject), len(sharedObject.functions()))
|
|
41
|
+
print(infoSpec % (sharedObject.path, *counts))
|
|
42
|
+
return 0
|
|
43
|
+
for symbol in sharedObject.search(args[1]):
|
|
44
|
+
if symbol.isFunction():
|
|
45
|
+
print('%s\t%s' % (symbol.readable, symbol.mangled))
|
|
46
|
+
return 0
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == '__main__':
|
|
50
|
+
sys.exit(main(*sys.argv[1:]))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
BaseMetaUgly provides a base metaclass for metaclasses assigned to a
|
|
3
|
+
particular shared library.
|
|
4
|
+
"""
|
|
5
|
+
# Apache-2.0 license
|
|
6
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
from worktoy.mcls import BaseMeta
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING: # pragma: no cover, no mutate
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BaseMetaUgly(BaseMeta):
|
|
18
|
+
"""
|
|
19
|
+
BaseMetaUgly provides a base metaclass for metaclasses assigned to a
|
|
20
|
+
particular shared library.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def getSharedObject(mcls, ) -> str:
|
|
25
|
+
"""
|
|
26
|
+
Subclasses *must* implement this method to return the shared object
|
|
27
|
+
file relevant for this sub metaclass.
|
|
28
|
+
"""
|
|
29
|
+
raise NotImplementedError
|