openvireo 1.2.1__py3-none-win_amd64.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.
- openvireo/__init__.py +42 -0
- openvireo/__init__.pyi +298 -0
- openvireo/_compat.py +130 -0
- openvireo/_core/__init__.py +1 -0
- openvireo/_core/ov_ffi.dll +0 -0
- openvireo/_core/ov_ffi.py +26621 -0
- openvireo/_core/ov_ffi.pyi +2571 -0
- openvireo/hosts.py +740 -0
- openvireo/py.typed +0 -0
- openvireo-1.2.1.dist-info/METADATA +144 -0
- openvireo-1.2.1.dist-info/RECORD +13 -0
- openvireo-1.2.1.dist-info/WHEEL +4 -0
- openvireo-1.2.1.dist-info/sboms/ov-ffi.cyclonedx.json +5939 -0
openvireo/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""OpenVireo for Python: the openvireo-core library (accounts, vaults, sync, share links, KDBX).
|
|
2
|
+
|
|
3
|
+
Everything the core exports is here: ``OvClient``, ``Account``, ``Vault``, ``ServiceAccount``,
|
|
4
|
+
``SelfHosted``, ``EventStream``, the records (``ClientConfig``, ``EntryInput`` …), the Host
|
|
5
|
+
interfaces (``HttpTransport``, ``SecureStore``, ``BlobCache``, ``Clock``, ``LogSink``), the crypto
|
|
6
|
+
helpers and ``OvError``. :mod:`openvireo.hosts` has ready-made Host parts.
|
|
7
|
+
|
|
8
|
+
Every network or storage call is a coroutine; run it on an asyncio loop. Each takes an optional
|
|
9
|
+
``cancel=CancelToken()`` as its last argument; leave it out unless you want to cancel the call from
|
|
10
|
+
elsewhere (``token.cancel()`` ends it with ``OvErrorCode.ABORTED``). Cancelling the asyncio task
|
|
11
|
+
drops the call too.
|
|
12
|
+
|
|
13
|
+
Errors are ``OvError`` (the single variant ``OvError.Failure``) with ``code`` (an ``OvErrorCode``),
|
|
14
|
+
``wire_code``, ``message``, ``status``, ``retry_after``, ``details`` and ``server_code``::
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
await account.login(openvireo.LoginInput(...))
|
|
18
|
+
except openvireo.OvError as e:
|
|
19
|
+
if e.code == openvireo.OvErrorCode.UNAUTHORIZED:
|
|
20
|
+
...
|
|
21
|
+
|
|
22
|
+
The module itself is generated by UniFFI from ``bindings/ov-ffi`` (``openvireo._core``).
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from . import _core, hosts
|
|
26
|
+
from ._compat import make_cancel_optional as _make_cancel_optional
|
|
27
|
+
from ._core import ov_ffi as _ov_ffi
|
|
28
|
+
|
|
29
|
+
# Every call that takes a CancelToken gets ``cancel: CancelToken | None = None`` (see _compat.py).
|
|
30
|
+
# Done before the star import so the re-exported free functions are the wrapped ones.
|
|
31
|
+
_CANCEL_OPTIONAL: list[str] = _make_cancel_optional(_ov_ffi, _ov_ffi.CancelToken)
|
|
32
|
+
for _name in _CANCEL_OPTIONAL:
|
|
33
|
+
if "." not in _name:
|
|
34
|
+
setattr(_core, _name, getattr(_ov_ffi, _name))
|
|
35
|
+
|
|
36
|
+
from ._core import * # noqa: E402, F403
|
|
37
|
+
from ._core.ov_ffi import uniffi_set_event_loop, version # noqa: E402
|
|
38
|
+
|
|
39
|
+
#: The core's version (the wheel's version too).
|
|
40
|
+
__version__: str = version()
|
|
41
|
+
|
|
42
|
+
__all__ = [*_ov_ffi.__all__, "hosts", "uniffi_set_event_loop", "__version__"]
|
openvireo/__init__.pyi
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# Generated by bindings/python/scripts/gen_stubs.py from the UniFFI module; don't edit.
|
|
2
|
+
# Regenerate with `cargo xtask python --stubs`.
|
|
3
|
+
|
|
4
|
+
from . import hosts as hosts
|
|
5
|
+
from ._core.ov_ffi import *
|
|
6
|
+
from ._core.ov_ffi import uniffi_set_event_loop as uniffi_set_event_loop
|
|
7
|
+
|
|
8
|
+
__version__: str
|
|
9
|
+
_CANCEL_OPTIONAL: list[str]
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"InternalError",
|
|
13
|
+
"Platform",
|
|
14
|
+
"OrgRole",
|
|
15
|
+
"DeletionOutcome",
|
|
16
|
+
"VaultRole",
|
|
17
|
+
"EntryExpiry",
|
|
18
|
+
"Method",
|
|
19
|
+
"OvErrorCode",
|
|
20
|
+
"OvError",
|
|
21
|
+
"ConflictKind",
|
|
22
|
+
"KdbxKdf",
|
|
23
|
+
"ExportFormat",
|
|
24
|
+
"LocalImportMode",
|
|
25
|
+
"ChangeType",
|
|
26
|
+
"CreateMode",
|
|
27
|
+
"SyncOutcome",
|
|
28
|
+
"VersionDifference",
|
|
29
|
+
"KdbxKdfKind",
|
|
30
|
+
"MemberStatus",
|
|
31
|
+
"TransportError",
|
|
32
|
+
"ShareLinkPolicy",
|
|
33
|
+
"ExpiryChange",
|
|
34
|
+
"TotpAlgorithm",
|
|
35
|
+
"AadKind",
|
|
36
|
+
"SignedOutReason",
|
|
37
|
+
"AccountEvent",
|
|
38
|
+
"Argon2Variant",
|
|
39
|
+
"Grantee",
|
|
40
|
+
"ImportMode",
|
|
41
|
+
"Level",
|
|
42
|
+
"LoginStep",
|
|
43
|
+
"ParkedCheck",
|
|
44
|
+
"SessionState",
|
|
45
|
+
"VaultClaim",
|
|
46
|
+
"AccessClaims",
|
|
47
|
+
"AppleEligibility",
|
|
48
|
+
"PlanLimit",
|
|
49
|
+
"Billing",
|
|
50
|
+
"Plan",
|
|
51
|
+
"AppleTransactionResult",
|
|
52
|
+
"AttachmentInfo",
|
|
53
|
+
"AuditEvent",
|
|
54
|
+
"AuditPage",
|
|
55
|
+
"FieldRecord",
|
|
56
|
+
"EntryRecord",
|
|
57
|
+
"AutoFillEdit",
|
|
58
|
+
"AutoFillEdits",
|
|
59
|
+
"BlobMeta",
|
|
60
|
+
"CachedVault",
|
|
61
|
+
"DeviceInfo",
|
|
62
|
+
"OpaqueConfig",
|
|
63
|
+
"KdfMin",
|
|
64
|
+
"ServerConfig",
|
|
65
|
+
"ClientConfig",
|
|
66
|
+
"PublicKeys",
|
|
67
|
+
"ServiceAccountInfo",
|
|
68
|
+
"CreatedServiceAccount",
|
|
69
|
+
"CreatedShare",
|
|
70
|
+
"DecodedJwt",
|
|
71
|
+
"DeletionCandidate",
|
|
72
|
+
"DeletionOrg",
|
|
73
|
+
"DeletionShare",
|
|
74
|
+
"DeletionVault",
|
|
75
|
+
"DeletionSubscription",
|
|
76
|
+
"DeletionPreview",
|
|
77
|
+
"Device",
|
|
78
|
+
"EmergencyKit",
|
|
79
|
+
"FieldInput",
|
|
80
|
+
"EntryInput",
|
|
81
|
+
"EntrySummary",
|
|
82
|
+
"GrantResult",
|
|
83
|
+
"GroupInfo",
|
|
84
|
+
"HttpHeader",
|
|
85
|
+
"HttpRequest",
|
|
86
|
+
"HttpResponse",
|
|
87
|
+
"SyncConflict",
|
|
88
|
+
"KdbxCredentials",
|
|
89
|
+
"MergeChange",
|
|
90
|
+
"ImportSummary",
|
|
91
|
+
"ImportPreview",
|
|
92
|
+
"ImportTarget",
|
|
93
|
+
"VaultInfo",
|
|
94
|
+
"SetFieldsResult",
|
|
95
|
+
"SyncOptions",
|
|
96
|
+
"SyncReport",
|
|
97
|
+
"ImportOutcome",
|
|
98
|
+
"Injected",
|
|
99
|
+
"Invitation",
|
|
100
|
+
"IssuedSecret",
|
|
101
|
+
"Jwk",
|
|
102
|
+
"Jwks",
|
|
103
|
+
"JwtVerifyOptions",
|
|
104
|
+
"KdbxHeaderInfo",
|
|
105
|
+
"KdfOverrides",
|
|
106
|
+
"KdfParams",
|
|
107
|
+
"Keyset",
|
|
108
|
+
"LoginInput",
|
|
109
|
+
"Member",
|
|
110
|
+
"NewAccount",
|
|
111
|
+
"VaultGrantRequest",
|
|
112
|
+
"NewServiceAccount",
|
|
113
|
+
"OpaqueIds",
|
|
114
|
+
"OpaqueLoginFinish",
|
|
115
|
+
"OpaqueLoginStart",
|
|
116
|
+
"OpaqueRegistrationFinish",
|
|
117
|
+
"OpaqueRegistrationStart",
|
|
118
|
+
"ShareField",
|
|
119
|
+
"SharePayload",
|
|
120
|
+
"OpenedShare",
|
|
121
|
+
"OpenedStream",
|
|
122
|
+
"Org",
|
|
123
|
+
"OrgMembership",
|
|
124
|
+
"PairingCode",
|
|
125
|
+
"ParsedSaToken",
|
|
126
|
+
"Profile",
|
|
127
|
+
"PublicKeysJson",
|
|
128
|
+
"ReconnectResult",
|
|
129
|
+
"RecoveryReset",
|
|
130
|
+
"RecoveryStatus",
|
|
131
|
+
"RegisterInput",
|
|
132
|
+
"RememberedAccount",
|
|
133
|
+
"RotationFailure",
|
|
134
|
+
"RotationReport",
|
|
135
|
+
"SaSecretInfo",
|
|
136
|
+
"SaSecretMaterial",
|
|
137
|
+
"SaVault",
|
|
138
|
+
"SelfHostedSyncResult",
|
|
139
|
+
"ServiceAccountUpdate",
|
|
140
|
+
"ShareInfo",
|
|
141
|
+
"ShareLinkParts",
|
|
142
|
+
"ShareRef",
|
|
143
|
+
"ShareListing",
|
|
144
|
+
"ShareOptions",
|
|
145
|
+
"ShareRecipient",
|
|
146
|
+
"ShareableField",
|
|
147
|
+
"StoredSession",
|
|
148
|
+
"TotpCode",
|
|
149
|
+
"TotpParams",
|
|
150
|
+
"TotpSetup",
|
|
151
|
+
"Unlocked",
|
|
152
|
+
"VaultKdbxSyncResult",
|
|
153
|
+
"VaultMember",
|
|
154
|
+
"VaultVersion",
|
|
155
|
+
"WrappedKeysetJson",
|
|
156
|
+
"aead_decrypt",
|
|
157
|
+
"aead_encrypt",
|
|
158
|
+
"argon2",
|
|
159
|
+
"argon2id32",
|
|
160
|
+
"auk_from_stretched",
|
|
161
|
+
"b64u_decode",
|
|
162
|
+
"b64u_encode",
|
|
163
|
+
"build_sa_token",
|
|
164
|
+
"check_kdf_params",
|
|
165
|
+
"constant_time_eq",
|
|
166
|
+
"decode_jwt",
|
|
167
|
+
"decrypt_vault_name",
|
|
168
|
+
"default_share_fields",
|
|
169
|
+
"deletion_expired",
|
|
170
|
+
"derive_auk",
|
|
171
|
+
"ed25519_public_key",
|
|
172
|
+
"ed25519_sign",
|
|
173
|
+
"ed25519_verify",
|
|
174
|
+
"encrypt_vault_name",
|
|
175
|
+
"entry_totp_uri",
|
|
176
|
+
"envelope_aad",
|
|
177
|
+
"envelope_seal",
|
|
178
|
+
"envelope_seal_derived_key",
|
|
179
|
+
"envelope_unseal",
|
|
180
|
+
"envelope_unwrap",
|
|
181
|
+
"envelope_wrap",
|
|
182
|
+
"error_code_from_wire",
|
|
183
|
+
"error_code_wire",
|
|
184
|
+
"format_secret_key",
|
|
185
|
+
"generate_keyset",
|
|
186
|
+
"generate_secret_key",
|
|
187
|
+
"hkdf_sha256",
|
|
188
|
+
"is_jwt",
|
|
189
|
+
"item_share_payload",
|
|
190
|
+
"kdbx_peek_header",
|
|
191
|
+
"kdf_minimum",
|
|
192
|
+
"keyset_from_secrets",
|
|
193
|
+
"make_ov_error",
|
|
194
|
+
"new_kdf_params",
|
|
195
|
+
"new_kdf_params_with",
|
|
196
|
+
"new_refresh_token",
|
|
197
|
+
"new_sa_secret",
|
|
198
|
+
"new_share_key",
|
|
199
|
+
"opaque_context",
|
|
200
|
+
"opaque_finish_login",
|
|
201
|
+
"opaque_finish_registration",
|
|
202
|
+
"opaque_has_test_server",
|
|
203
|
+
"opaque_ids",
|
|
204
|
+
"opaque_start_login",
|
|
205
|
+
"opaque_start_registration",
|
|
206
|
+
"parse_sa_token",
|
|
207
|
+
"parse_secret_key",
|
|
208
|
+
"parse_share_link",
|
|
209
|
+
"parse_totp_uri",
|
|
210
|
+
"password_bytes",
|
|
211
|
+
"public_key_fingerprint",
|
|
212
|
+
"public_keys_from_json",
|
|
213
|
+
"public_keys_to_json",
|
|
214
|
+
"random_bytes",
|
|
215
|
+
"refresh_token_hash",
|
|
216
|
+
"reseal_vault_key",
|
|
217
|
+
"restore_proof",
|
|
218
|
+
"restore_proof_message",
|
|
219
|
+
"restore_self_hosted",
|
|
220
|
+
"sa_secret_hash",
|
|
221
|
+
"sa_secret_prefix",
|
|
222
|
+
"seal_sa_master",
|
|
223
|
+
"seal_vault_key",
|
|
224
|
+
"sha256",
|
|
225
|
+
"share_auth",
|
|
226
|
+
"share_auth_hash",
|
|
227
|
+
"share_content_key",
|
|
228
|
+
"share_decrypt",
|
|
229
|
+
"share_decrypt_ref",
|
|
230
|
+
"share_encrypt",
|
|
231
|
+
"share_encrypt_ref",
|
|
232
|
+
"share_key_from_hash",
|
|
233
|
+
"share_link",
|
|
234
|
+
"share_max_ciphertext",
|
|
235
|
+
"share_pad",
|
|
236
|
+
"share_pad_block",
|
|
237
|
+
"share_passcode_key",
|
|
238
|
+
"share_ref_key",
|
|
239
|
+
"share_unpad",
|
|
240
|
+
"shareable_fields",
|
|
241
|
+
"stretch_password",
|
|
242
|
+
"text_share_payload",
|
|
243
|
+
"totp_code",
|
|
244
|
+
"trusted_public_keys",
|
|
245
|
+
"unseal_sa_master",
|
|
246
|
+
"unseal_vault_key",
|
|
247
|
+
"unwrap_keyset",
|
|
248
|
+
"unwrap_sa_master",
|
|
249
|
+
"vault_name_key",
|
|
250
|
+
"verify_jwt",
|
|
251
|
+
"verify_public_keys",
|
|
252
|
+
"verify_restore_proof",
|
|
253
|
+
"version",
|
|
254
|
+
"wrap_keyset",
|
|
255
|
+
"wrap_sa_master",
|
|
256
|
+
"x25519_public_key",
|
|
257
|
+
"x25519_random_secret",
|
|
258
|
+
"x25519_shared",
|
|
259
|
+
"CancelToken",
|
|
260
|
+
"CancelTokenProtocol",
|
|
261
|
+
"Vault",
|
|
262
|
+
"VaultProtocol",
|
|
263
|
+
"OpaqueLoginState",
|
|
264
|
+
"OpaqueLoginStateProtocol",
|
|
265
|
+
"OpaqueRegistrationState",
|
|
266
|
+
"OpaqueRegistrationStateProtocol",
|
|
267
|
+
"ByteStreamImpl",
|
|
268
|
+
"ByteStream",
|
|
269
|
+
"TotpChallenge",
|
|
270
|
+
"TotpChallengeProtocol",
|
|
271
|
+
"EventStream",
|
|
272
|
+
"EventStreamProtocol",
|
|
273
|
+
"Account",
|
|
274
|
+
"AccountProtocol",
|
|
275
|
+
"BlobCacheImpl",
|
|
276
|
+
"BlobCache",
|
|
277
|
+
"ClockImpl",
|
|
278
|
+
"Clock",
|
|
279
|
+
"Host",
|
|
280
|
+
"HostProtocol",
|
|
281
|
+
"HttpTransportImpl",
|
|
282
|
+
"HttpTransport",
|
|
283
|
+
"JwksRefetcherImpl",
|
|
284
|
+
"JwksRefetcher",
|
|
285
|
+
"LogSinkImpl",
|
|
286
|
+
"LogSink",
|
|
287
|
+
"OvClient",
|
|
288
|
+
"OvClientProtocol",
|
|
289
|
+
"SecureStoreImpl",
|
|
290
|
+
"SecureStore",
|
|
291
|
+
"SelfHosted",
|
|
292
|
+
"SelfHostedProtocol",
|
|
293
|
+
"ServiceAccount",
|
|
294
|
+
"ServiceAccountProtocol",
|
|
295
|
+
"hosts",
|
|
296
|
+
"uniffi_set_event_loop",
|
|
297
|
+
"__version__",
|
|
298
|
+
]
|
openvireo/_compat.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Makes the ``CancelToken`` argument optional on every generated call.
|
|
2
|
+
|
|
3
|
+
UniFFI can't give an object argument a default, so every async method of the generated module
|
|
4
|
+
(``openvireo._core``) takes a required ``CancelToken``. At import time this module rewraps each
|
|
5
|
+
generated function or method that has a parameter annotated ``CancelToken`` so that the parameter
|
|
6
|
+
becomes ``cancel: CancelToken | None = None``; when it's omitted (or ``None``), a fresh
|
|
7
|
+
``CancelToken()`` is passed. The parameter keeps its position (it's always the last one), so
|
|
8
|
+
passing a token positionally still works, and so does ``cancel=token``.
|
|
9
|
+
|
|
10
|
+
The wrappers are found by type annotation, not by hand: a new core method gets the same treatment
|
|
11
|
+
without touching this file. ``tests/test_optional_cancel.py`` checks that nothing was missed.
|
|
12
|
+
|
|
13
|
+
Cancelling the asyncio task that awaits a call still drops the Rust future (the wrapper only awaits
|
|
14
|
+
the generated coroutine); a token that's passed and cancelled still ends the call with ``ABORTED``.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import functools
|
|
20
|
+
import inspect
|
|
21
|
+
import types
|
|
22
|
+
import typing
|
|
23
|
+
from collections.abc import Callable, Coroutine
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
#: The public keyword for the token on every wrapped call.
|
|
27
|
+
CANCEL = "cancel"
|
|
28
|
+
|
|
29
|
+
#: Set on every wrapper this module makes (so applying it twice is a no-op, and tests can find them).
|
|
30
|
+
MARKER = "__ov_optional_cancel__"
|
|
31
|
+
|
|
32
|
+
_Fn = Callable[..., Any]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _cancel_param(fn: _Fn, token_type: type, namespace: dict[str, Any]) -> inspect.Parameter | None:
|
|
36
|
+
"""The parameter of ``fn`` typed ``CancelToken``, if any. The generated module uses
|
|
37
|
+
``from __future__ import annotations``, so annotations are strings resolved against it."""
|
|
38
|
+
try:
|
|
39
|
+
hints = typing.get_type_hints(fn, globalns=namespace)
|
|
40
|
+
except Exception: # an annotation that doesn't resolve: fall back to the raw strings
|
|
41
|
+
hints = {}
|
|
42
|
+
for p in inspect.signature(fn).parameters.values():
|
|
43
|
+
hint = hints.get(p.name, p.annotation)
|
|
44
|
+
if hint is token_type or hint == token_type.__name__:
|
|
45
|
+
return p
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _wrap(fn: _Fn, token_type: type, namespace: dict[str, Any]) -> _Fn | None:
|
|
50
|
+
"""``fn`` with its ``CancelToken`` parameter optional, or ``None`` when it has none."""
|
|
51
|
+
if getattr(fn, MARKER, False):
|
|
52
|
+
return None
|
|
53
|
+
param = _cancel_param(fn, token_type, namespace)
|
|
54
|
+
if param is None:
|
|
55
|
+
return None
|
|
56
|
+
sig = inspect.signature(fn)
|
|
57
|
+
params = list(sig.parameters.values())
|
|
58
|
+
index = params.index(param)
|
|
59
|
+
if any(p.default is inspect.Parameter.empty for p in params[index + 1 :]):
|
|
60
|
+
raise TypeError(f"{fn.__qualname__}: required parameters after `{param.name}`; can't default it")
|
|
61
|
+
name = param.name
|
|
62
|
+
|
|
63
|
+
def fill(args: tuple[Any, ...], kwargs: dict[str, Any]) -> tuple[tuple[Any, ...], dict[str, Any]]:
|
|
64
|
+
if name != CANCEL and CANCEL in kwargs:
|
|
65
|
+
kwargs[name] = kwargs.pop(CANCEL)
|
|
66
|
+
if len(args) > index:
|
|
67
|
+
if args[index] is None:
|
|
68
|
+
args = (*args[:index], token_type(), *args[index + 1 :])
|
|
69
|
+
elif kwargs.get(name) is None:
|
|
70
|
+
kwargs[name] = token_type()
|
|
71
|
+
return args, kwargs
|
|
72
|
+
|
|
73
|
+
wrapper: _Fn
|
|
74
|
+
if inspect.iscoroutinefunction(fn):
|
|
75
|
+
|
|
76
|
+
@functools.wraps(fn)
|
|
77
|
+
async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
78
|
+
args, kwargs = fill(args, kwargs)
|
|
79
|
+
coro: Coroutine[Any, Any, Any] = fn(*args, **kwargs)
|
|
80
|
+
return await coro
|
|
81
|
+
|
|
82
|
+
wrapper = async_wrapper
|
|
83
|
+
else:
|
|
84
|
+
|
|
85
|
+
@functools.wraps(fn)
|
|
86
|
+
def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
87
|
+
args, kwargs = fill(args, kwargs)
|
|
88
|
+
return fn(*args, **kwargs)
|
|
89
|
+
|
|
90
|
+
wrapper = sync_wrapper
|
|
91
|
+
|
|
92
|
+
new = param.replace(name=CANCEL, default=None, annotation=f"{token_type.__name__} | None")
|
|
93
|
+
params[index] = new
|
|
94
|
+
setattr(wrapper, "__signature__", sig.replace(parameters=params)) # noqa: B010
|
|
95
|
+
annotations = dict(getattr(fn, "__annotations__", {}))
|
|
96
|
+
annotations.pop(name, None)
|
|
97
|
+
annotations[CANCEL] = new.annotation
|
|
98
|
+
wrapper.__annotations__ = annotations
|
|
99
|
+
setattr(wrapper, MARKER, True)
|
|
100
|
+
return wrapper
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _is_protocol(cls: type) -> bool:
|
|
104
|
+
return bool(cls.__dict__.get("_is_protocol", False))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def make_cancel_optional(module: types.ModuleType, token_type: type) -> list[str]:
|
|
108
|
+
"""Rewraps, in place, every function of ``module.__all__`` and every method of its classes
|
|
109
|
+
(not the ``typing.Protocol`` ones, which only describe them) that takes a ``token_type``.
|
|
110
|
+
Returns the qualified names wrapped."""
|
|
111
|
+
namespace = vars(module)
|
|
112
|
+
done: list[str] = []
|
|
113
|
+
for export in getattr(module, "__all__", []):
|
|
114
|
+
obj = getattr(module, export)
|
|
115
|
+
if inspect.isclass(obj):
|
|
116
|
+
if obj.__module__ != module.__name__ or _is_protocol(obj):
|
|
117
|
+
continue
|
|
118
|
+
for attr, raw in list(vars(obj).items()):
|
|
119
|
+
if isinstance(raw, (classmethod, staticmethod)):
|
|
120
|
+
inner = raw.__func__
|
|
121
|
+
if inspect.isfunction(inner) and (w := _wrap(inner, token_type, namespace)):
|
|
122
|
+
setattr(obj, attr, type(raw)(w))
|
|
123
|
+
done.append(f"{export}.{attr}")
|
|
124
|
+
elif inspect.isfunction(raw) and (w := _wrap(raw, token_type, namespace)):
|
|
125
|
+
setattr(obj, attr, w)
|
|
126
|
+
done.append(f"{export}.{attr}")
|
|
127
|
+
elif inspect.isfunction(obj) and (w := _wrap(obj, token_type, namespace)):
|
|
128
|
+
setattr(module, export, w)
|
|
129
|
+
done.append(export)
|
|
130
|
+
return done
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .ov_ffi import * # NOQA
|
|
Binary file
|