matrix-sdk-python 0.18.0a1__cp314-cp314-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.
@@ -0,0 +1,942 @@
1
+ # This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ # Trust me, you don't want to mess with it!
3
+
4
+ # Common helper code.
5
+ #
6
+ # Ideally this would live in a separate .py file where it can be unittested etc
7
+ # in isolation, and perhaps even published as a re-useable package.
8
+ #
9
+ # However, it's important that the details of how this helper code works (e.g. the
10
+ # way that different builtin types are passed across the FFI) exactly match what's
11
+ # expected by the rust code on the other side of the interface. In practice right
12
+ # now that means coming from the exact some version of `uniffi` that was used to
13
+ # compile the rust component. The easiest way to ensure this is to bundle the Python
14
+ # helpers directly inline like we're doing here.
15
+
16
+ from __future__ import annotations
17
+ import os
18
+ import sys
19
+ import ctypes
20
+ from dataclasses import dataclass
21
+ import enum
22
+ import struct
23
+ import contextlib
24
+ import datetime
25
+ import threading
26
+ import itertools
27
+ import traceback
28
+ import typing
29
+ import platform
30
+
31
+
32
+ # Used for default argument values
33
+ _DEFAULT = object() # type: typing.Any
34
+
35
+
36
+ class _UniffiRustBuffer(ctypes.Structure):
37
+ _fields_ = [
38
+ ("capacity", ctypes.c_uint64),
39
+ ("len", ctypes.c_uint64),
40
+ ("data", ctypes.POINTER(ctypes.c_char)),
41
+ ]
42
+
43
+ @staticmethod
44
+ def default():
45
+ return _UniffiRustBuffer(0, 0, None)
46
+
47
+ @staticmethod
48
+ def alloc(size):
49
+ return _uniffi_rust_call(_UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_alloc, size)
50
+
51
+ @staticmethod
52
+ def reserve(rbuf, additional):
53
+ return _uniffi_rust_call(_UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_reserve, rbuf, additional)
54
+
55
+ def free(self):
56
+ return _uniffi_rust_call(_UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_free, self)
57
+
58
+ def __str__(self):
59
+ return "_UniffiRustBuffer(capacity={}, len={}, data={})".format(
60
+ self.capacity,
61
+ self.len,
62
+ self.data[0:self.len]
63
+ )
64
+
65
+ @contextlib.contextmanager
66
+ def alloc_with_builder(*args):
67
+ """Context-manger to allocate a buffer using a _UniffiRustBufferBuilder.
68
+
69
+ The allocated buffer will be automatically freed if an error occurs, ensuring that
70
+ we don't accidentally leak it.
71
+ """
72
+ builder = _UniffiRustBufferBuilder()
73
+ try:
74
+ yield builder
75
+ except:
76
+ builder.discard()
77
+ raise
78
+
79
+ @contextlib.contextmanager
80
+ def consume_with_stream(self):
81
+ """Context-manager to consume a buffer using a _UniffiRustBufferStream.
82
+
83
+ The _UniffiRustBuffer will be freed once the context-manager exits, ensuring that we don't
84
+ leak it even if an error occurs.
85
+ """
86
+ try:
87
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
88
+ yield s
89
+ if s.remaining() != 0:
90
+ raise RuntimeError(f"junk data left in buffer at end of consume_with_stream {s.remaining()}")
91
+ finally:
92
+ self.free()
93
+
94
+ @contextlib.contextmanager
95
+ def read_with_stream(self):
96
+ """Context-manager to read a buffer using a _UniffiRustBufferStream.
97
+
98
+ This is like consume_with_stream, but doesn't free the buffer afterwards.
99
+ It should only be used with borrowed `_UniffiRustBuffer` data.
100
+ """
101
+ s = _UniffiRustBufferStream.from_rust_buffer(self)
102
+ yield s
103
+ if s.remaining() != 0:
104
+ raise RuntimeError(f"junk data left in buffer at end of read_with_stream {s.remaining()}")
105
+
106
+ class _UniffiForeignBytes(ctypes.Structure):
107
+ _fields_ = [
108
+ ("len", ctypes.c_int32),
109
+ ("data", ctypes.POINTER(ctypes.c_char)),
110
+ ]
111
+
112
+ def __str__(self):
113
+ return "_UniffiForeignBytes(len={}, data={})".format(self.len, self.data[0:self.len])
114
+
115
+
116
+ class _UniffiRustBufferStream:
117
+ """
118
+ Helper for structured reading of bytes from a _UniffiRustBuffer
119
+ """
120
+
121
+ def __init__(self, data, len):
122
+ self.data = data
123
+ self.len = len
124
+ self.offset = 0
125
+
126
+ @classmethod
127
+ def from_rust_buffer(cls, buf):
128
+ return cls(buf.data, buf.len)
129
+
130
+ def remaining(self):
131
+ return self.len - self.offset
132
+
133
+ def _unpack_from(self, size, format):
134
+ if self.offset + size > self.len:
135
+ raise InternalError("read past end of rust buffer")
136
+ value = struct.unpack(format, self.data[self.offset:self.offset+size])[0]
137
+ self.offset += size
138
+ return value
139
+
140
+ def read(self, size):
141
+ if self.offset + size > self.len:
142
+ raise InternalError("read past end of rust buffer")
143
+ data = self.data[self.offset:self.offset+size]
144
+ self.offset += size
145
+ return data
146
+
147
+ def read_i8(self):
148
+ return self._unpack_from(1, ">b")
149
+
150
+ def read_u8(self):
151
+ return self._unpack_from(1, ">B")
152
+
153
+ def read_i16(self):
154
+ return self._unpack_from(2, ">h")
155
+
156
+ def read_u16(self):
157
+ return self._unpack_from(2, ">H")
158
+
159
+ def read_i32(self):
160
+ return self._unpack_from(4, ">i")
161
+
162
+ def read_u32(self):
163
+ return self._unpack_from(4, ">I")
164
+
165
+ def read_i64(self):
166
+ return self._unpack_from(8, ">q")
167
+
168
+ def read_u64(self):
169
+ return self._unpack_from(8, ">Q")
170
+
171
+ def read_float(self):
172
+ v = self._unpack_from(4, ">f")
173
+ return v
174
+
175
+ def read_double(self):
176
+ return self._unpack_from(8, ">d")
177
+
178
+ class _UniffiRustBufferBuilder:
179
+ """
180
+ Helper for structured writing of bytes into a _UniffiRustBuffer.
181
+ """
182
+
183
+ def __init__(self):
184
+ self.rbuf = _UniffiRustBuffer.alloc(16)
185
+ self.rbuf.len = 0
186
+
187
+ def finalize(self):
188
+ rbuf = self.rbuf
189
+ self.rbuf = None
190
+ return rbuf
191
+
192
+ def discard(self):
193
+ if self.rbuf is not None:
194
+ rbuf = self.finalize()
195
+ rbuf.free()
196
+
197
+ @contextlib.contextmanager
198
+ def _reserve(self, num_bytes):
199
+ if self.rbuf.len + num_bytes > self.rbuf.capacity:
200
+ self.rbuf = _UniffiRustBuffer.reserve(self.rbuf, num_bytes)
201
+ yield None
202
+ self.rbuf.len += num_bytes
203
+
204
+ def _pack_into(self, size, format, value):
205
+ with self._reserve(size):
206
+ # XXX TODO: I feel like I should be able to use `struct.pack_into` here but can't figure it out.
207
+ for i, byte in enumerate(struct.pack(format, value)):
208
+ self.rbuf.data[self.rbuf.len + i] = byte
209
+
210
+ def write(self, value):
211
+ with self._reserve(len(value)):
212
+ for i, byte in enumerate(value):
213
+ self.rbuf.data[self.rbuf.len + i] = byte
214
+
215
+ def write_i8(self, v):
216
+ self._pack_into(1, ">b", v)
217
+
218
+ def write_u8(self, v):
219
+ self._pack_into(1, ">B", v)
220
+
221
+ def write_i16(self, v):
222
+ self._pack_into(2, ">h", v)
223
+
224
+ def write_u16(self, v):
225
+ self._pack_into(2, ">H", v)
226
+
227
+ def write_i32(self, v):
228
+ self._pack_into(4, ">i", v)
229
+
230
+ def write_u32(self, v):
231
+ self._pack_into(4, ">I", v)
232
+
233
+ def write_i64(self, v):
234
+ self._pack_into(8, ">q", v)
235
+
236
+ def write_u64(self, v):
237
+ self._pack_into(8, ">Q", v)
238
+
239
+ def write_float(self, v):
240
+ self._pack_into(4, ">f", v)
241
+
242
+ def write_double(self, v):
243
+ self._pack_into(8, ">d", v)
244
+
245
+ def write_c_size_t(self, v):
246
+ self._pack_into(ctypes.sizeof(ctypes.c_size_t) , "@N", v)
247
+ # A handful of classes and functions to support the generated data structures.
248
+ # This would be a good candidate for isolating in its own ffi-support lib.
249
+
250
+ class InternalError(Exception):
251
+ pass
252
+
253
+ class _UniffiRustCallStatus(ctypes.Structure):
254
+ """
255
+ Error runtime.
256
+ """
257
+ _fields_ = [
258
+ ("code", ctypes.c_int8),
259
+ ("error_buf", _UniffiRustBuffer),
260
+ ]
261
+
262
+ # These match the values from the uniffi::rustcalls module
263
+ CALL_SUCCESS = 0
264
+ CALL_ERROR = 1
265
+ CALL_UNEXPECTED_ERROR = 2
266
+
267
+ @staticmethod
268
+ def default():
269
+ return _UniffiRustCallStatus(code=_UniffiRustCallStatus.CALL_SUCCESS, error_buf=_UniffiRustBuffer.default())
270
+
271
+ def __str__(self):
272
+ if self.code == _UniffiRustCallStatus.CALL_SUCCESS:
273
+ return "_UniffiRustCallStatus(CALL_SUCCESS)"
274
+ elif self.code == _UniffiRustCallStatus.CALL_ERROR:
275
+ return "_UniffiRustCallStatus(CALL_ERROR)"
276
+ elif self.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
277
+ return "_UniffiRustCallStatus(CALL_UNEXPECTED_ERROR)"
278
+ else:
279
+ return "_UniffiRustCallStatus(<invalid code>)"
280
+
281
+ def _uniffi_rust_call(fn, *args):
282
+ # Call a rust function
283
+ return _uniffi_rust_call_with_error(None, fn, *args)
284
+
285
+ def _uniffi_rust_call_with_error(error_ffi_converter, fn, *args):
286
+ # Call a rust function and handle any errors
287
+ #
288
+ # This function is used for rust calls that return Result<> and therefore can set the CALL_ERROR status code.
289
+ # error_ffi_converter must be set to the _UniffiConverter for the error class that corresponds to the result.
290
+ call_status = _UniffiRustCallStatus.default()
291
+
292
+ args_with_error = args + (ctypes.byref(call_status),)
293
+ result = fn(*args_with_error)
294
+ _uniffi_check_call_status(error_ffi_converter, call_status)
295
+ return result
296
+
297
+ def _uniffi_check_call_status(error_ffi_converter, call_status):
298
+ if call_status.code == _UniffiRustCallStatus.CALL_SUCCESS:
299
+ pass
300
+ elif call_status.code == _UniffiRustCallStatus.CALL_ERROR:
301
+ if error_ffi_converter is None:
302
+ call_status.error_buf.free()
303
+ raise InternalError("_uniffi_rust_call_with_error: CALL_ERROR, but error_ffi_converter is None")
304
+ else:
305
+ raise error_ffi_converter.lift(call_status.error_buf)
306
+ elif call_status.code == _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR:
307
+ # When the rust code sees a panic, it tries to construct a _UniffiRustBuffer
308
+ # with the message. But if that code panics, then it just sends back
309
+ # an empty buffer.
310
+ if call_status.error_buf.len > 0:
311
+ msg = _UniffiFfiConverterString.lift(call_status.error_buf)
312
+ else:
313
+ msg = "Unknown rust panic"
314
+ raise InternalError(msg)
315
+ else:
316
+ raise InternalError("Invalid _UniffiRustCallStatus code: {}".format(
317
+ call_status.code))
318
+
319
+ def _uniffi_trait_interface_call(call_status, make_call, write_return_value):
320
+ try:
321
+ return write_return_value(make_call())
322
+ except Exception as e:
323
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
324
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
325
+
326
+ def _uniffi_trait_interface_call_with_error(call_status, make_call, write_return_value, error_type, lower_error):
327
+ try:
328
+ try:
329
+ return write_return_value(make_call())
330
+ except error_type as e:
331
+ call_status.code = _UniffiRustCallStatus.CALL_ERROR
332
+ call_status.error_buf = lower_error(e)
333
+ except Exception as e:
334
+ call_status.code = _UniffiRustCallStatus.CALL_UNEXPECTED_ERROR
335
+ call_status.error_buf = _UniffiFfiConverterString.lower(repr(e))
336
+ # Initial value and increment amount for handles.
337
+ # These ensure that Python-generated handles always have the lowest bit set
338
+ _UNIFFI_HANDLEMAP_INITIAL = 1
339
+ _UNIFFI_HANDLEMAP_DELTA = 2
340
+
341
+ class _UniffiHandleMap:
342
+ """
343
+ A map where inserting, getting and removing data is synchronized with a lock.
344
+ """
345
+
346
+ def __init__(self):
347
+ # type Handle = int
348
+ self._map = {} # type: Dict[Handle, Any]
349
+ self._lock = threading.Lock()
350
+ self._counter = _UNIFFI_HANDLEMAP_INITIAL
351
+
352
+ def insert(self, obj):
353
+ with self._lock:
354
+ return self._insert(obj)
355
+
356
+ """Low-level insert, this assumes `self._lock` is held."""
357
+ def _insert(self, obj):
358
+ handle = self._counter
359
+ self._counter += _UNIFFI_HANDLEMAP_DELTA
360
+ self._map[handle] = obj
361
+ return handle
362
+
363
+ def get(self, handle):
364
+ try:
365
+ with self._lock:
366
+ return self._map[handle]
367
+ except KeyError:
368
+ raise InternalError(f"_UniffiHandleMap.get: Invalid handle {handle}")
369
+
370
+ def clone(self, handle):
371
+ try:
372
+ with self._lock:
373
+ obj = self._map[handle]
374
+ return self._insert(obj)
375
+ except KeyError:
376
+ raise InternalError(f"_UniffiHandleMap.clone: Invalid handle {handle}")
377
+
378
+ def remove(self, handle):
379
+ try:
380
+ with self._lock:
381
+ return self._map.pop(handle)
382
+ except KeyError:
383
+ raise InternalError(f"_UniffiHandleMap.remove: Invalid handle: {handle}")
384
+
385
+ def __len__(self):
386
+ return len(self._map)
387
+ # Types conforming to `_UniffiConverterPrimitive` pass themselves directly over the FFI.
388
+ class _UniffiConverterPrimitive:
389
+ @classmethod
390
+ def lift(cls, value):
391
+ return value
392
+
393
+ @classmethod
394
+ def lower(cls, value):
395
+ return value
396
+
397
+ class _UniffiConverterPrimitiveInt(_UniffiConverterPrimitive):
398
+ @classmethod
399
+ def check_lower(cls, value):
400
+ try:
401
+ value = value.__index__()
402
+ except Exception:
403
+ raise TypeError("'{}' object cannot be interpreted as an integer".format(type(value).__name__))
404
+ if not isinstance(value, int):
405
+ raise TypeError("__index__ returned non-int (type {})".format(type(value).__name__))
406
+ if not cls.VALUE_MIN <= value < cls.VALUE_MAX:
407
+ raise ValueError("{} requires {} <= value < {}".format(cls.CLASS_NAME, cls.VALUE_MIN, cls.VALUE_MAX))
408
+
409
+ class _UniffiConverterPrimitiveFloat(_UniffiConverterPrimitive):
410
+ @classmethod
411
+ def check_lower(cls, value):
412
+ try:
413
+ value = value.__float__()
414
+ except Exception:
415
+ raise TypeError("must be real number, not {}".format(type(value).__name__))
416
+ if not isinstance(value, float):
417
+ raise TypeError("__float__ returned non-float (type {})".format(type(value).__name__))
418
+
419
+ # Helper class for wrapper types that will always go through a _UniffiRustBuffer.
420
+ # Classes should inherit from this and implement the `read` and `write` static methods.
421
+ class _UniffiConverterRustBuffer:
422
+ @classmethod
423
+ def lift(cls, rbuf):
424
+ with rbuf.consume_with_stream() as stream:
425
+ return cls.read(stream)
426
+
427
+ @classmethod
428
+ def lower(cls, value):
429
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
430
+ cls.write(value, builder)
431
+ return builder.finalize()
432
+
433
+ # Contains loading, initialization code, and the FFI Function declarations.
434
+ # Define some ctypes FFI types that we use in the library
435
+
436
+ """
437
+ Function pointer for a Rust task, which a callback function that takes a opaque pointer
438
+ """
439
+ _UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8)
440
+
441
+ def _uniffi_future_callback_t(return_type):
442
+ """
443
+ Factory function to create callback function types for async functions
444
+ """
445
+ return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus)
446
+
447
+ def _uniffi_load_indirect():
448
+ """
449
+ This is how we find and load the dynamic library provided by the component.
450
+ For now we just look it up by name.
451
+ """
452
+ if sys.platform == "darwin":
453
+ libname = "lib{}.dylib"
454
+ elif sys.platform.startswith("win"):
455
+ # As of python3.8, ctypes does not seem to search $PATH when loading DLLs.
456
+ # We could use `os.add_dll_directory` to configure the search path, but
457
+ # it doesn't feel right to mess with application-wide settings. Let's
458
+ # assume that the `.dll` is next to the `.py` file and load by full path.
459
+ libname = os.path.join(
460
+ os.path.dirname(__file__),
461
+ "{}.dll",
462
+ )
463
+ else:
464
+ # Anything else must be an ELF platform - Linux, *BSD, Solaris/illumos
465
+ libname = "lib{}.so"
466
+
467
+ libname = libname.format("matrix_sdk_ffi")
468
+ path = os.path.join(os.path.dirname(__file__), libname)
469
+ lib = ctypes.cdll.LoadLibrary(path)
470
+ return lib
471
+
472
+ def _uniffi_check_contract_api_version(lib):
473
+ # Get the bindings contract version from our ComponentInterface
474
+ bindings_contract_version = 30
475
+ # Get the scaffolding contract version by calling the into the dylib
476
+ scaffolding_contract_version = lib.ffi_matrix_sdk_contentscanner_uniffi_contract_version()
477
+ if bindings_contract_version != scaffolding_contract_version:
478
+ raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
479
+
480
+ def _uniffi_check_api_checksums(lib):
481
+ pass
482
+
483
+ # A ctypes library to expose the extern-C FFI definitions.
484
+ # This is an implementation detail which will be called internally by the public API.
485
+
486
+ _UniffiLib = _uniffi_load_indirect()
487
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_alloc.argtypes = (
488
+ ctypes.c_uint64,
489
+ ctypes.POINTER(_UniffiRustCallStatus),
490
+ )
491
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_alloc.restype = _UniffiRustBuffer
492
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_from_bytes.argtypes = (
493
+ _UniffiForeignBytes,
494
+ ctypes.POINTER(_UniffiRustCallStatus),
495
+ )
496
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_from_bytes.restype = _UniffiRustBuffer
497
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_free.argtypes = (
498
+ _UniffiRustBuffer,
499
+ ctypes.POINTER(_UniffiRustCallStatus),
500
+ )
501
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_free.restype = None
502
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_reserve.argtypes = (
503
+ _UniffiRustBuffer,
504
+ ctypes.c_uint64,
505
+ ctypes.POINTER(_UniffiRustCallStatus),
506
+ )
507
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rustbuffer_reserve.restype = _UniffiRustBuffer
508
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,ctypes.c_int8,
509
+ )
510
+ _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK = ctypes.CFUNCTYPE(None,ctypes.c_uint64,
511
+ )
512
+ class _UniffiForeignFutureDroppedCallbackStruct(ctypes.Structure):
513
+ _fields_ = [
514
+ ("handle", ctypes.c_uint64),
515
+ ("free", _UNIFFI_FOREIGN_FUTURE_DROPPED_CALLBACK),
516
+ ]
517
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u8.argtypes = (
518
+ ctypes.c_uint64,
519
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
520
+ ctypes.c_uint64,
521
+ )
522
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u8.restype = None
523
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u8.argtypes = (
524
+ ctypes.c_uint64,
525
+ )
526
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u8.restype = None
527
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u8.argtypes = (
528
+ ctypes.c_uint64,
529
+ ctypes.POINTER(_UniffiRustCallStatus),
530
+ )
531
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u8.restype = ctypes.c_uint8
532
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u8.argtypes = (
533
+ ctypes.c_uint64,
534
+ )
535
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u8.restype = None
536
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i8.argtypes = (
537
+ ctypes.c_uint64,
538
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
539
+ ctypes.c_uint64,
540
+ )
541
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i8.restype = None
542
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i8.argtypes = (
543
+ ctypes.c_uint64,
544
+ )
545
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i8.restype = None
546
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i8.argtypes = (
547
+ ctypes.c_uint64,
548
+ ctypes.POINTER(_UniffiRustCallStatus),
549
+ )
550
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i8.restype = ctypes.c_int8
551
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i8.argtypes = (
552
+ ctypes.c_uint64,
553
+ )
554
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i8.restype = None
555
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u16.argtypes = (
556
+ ctypes.c_uint64,
557
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
558
+ ctypes.c_uint64,
559
+ )
560
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u16.restype = None
561
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u16.argtypes = (
562
+ ctypes.c_uint64,
563
+ )
564
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u16.restype = None
565
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u16.argtypes = (
566
+ ctypes.c_uint64,
567
+ ctypes.POINTER(_UniffiRustCallStatus),
568
+ )
569
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u16.restype = ctypes.c_uint16
570
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u16.argtypes = (
571
+ ctypes.c_uint64,
572
+ )
573
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u16.restype = None
574
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i16.argtypes = (
575
+ ctypes.c_uint64,
576
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
577
+ ctypes.c_uint64,
578
+ )
579
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i16.restype = None
580
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i16.argtypes = (
581
+ ctypes.c_uint64,
582
+ )
583
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i16.restype = None
584
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i16.argtypes = (
585
+ ctypes.c_uint64,
586
+ ctypes.POINTER(_UniffiRustCallStatus),
587
+ )
588
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i16.restype = ctypes.c_int16
589
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i16.argtypes = (
590
+ ctypes.c_uint64,
591
+ )
592
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i16.restype = None
593
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u32.argtypes = (
594
+ ctypes.c_uint64,
595
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
596
+ ctypes.c_uint64,
597
+ )
598
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u32.restype = None
599
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u32.argtypes = (
600
+ ctypes.c_uint64,
601
+ )
602
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u32.restype = None
603
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u32.argtypes = (
604
+ ctypes.c_uint64,
605
+ ctypes.POINTER(_UniffiRustCallStatus),
606
+ )
607
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u32.restype = ctypes.c_uint32
608
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u32.argtypes = (
609
+ ctypes.c_uint64,
610
+ )
611
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u32.restype = None
612
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i32.argtypes = (
613
+ ctypes.c_uint64,
614
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
615
+ ctypes.c_uint64,
616
+ )
617
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i32.restype = None
618
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i32.argtypes = (
619
+ ctypes.c_uint64,
620
+ )
621
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i32.restype = None
622
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i32.argtypes = (
623
+ ctypes.c_uint64,
624
+ ctypes.POINTER(_UniffiRustCallStatus),
625
+ )
626
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i32.restype = ctypes.c_int32
627
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i32.argtypes = (
628
+ ctypes.c_uint64,
629
+ )
630
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i32.restype = None
631
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u64.argtypes = (
632
+ ctypes.c_uint64,
633
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
634
+ ctypes.c_uint64,
635
+ )
636
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_u64.restype = None
637
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u64.argtypes = (
638
+ ctypes.c_uint64,
639
+ )
640
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_u64.restype = None
641
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u64.argtypes = (
642
+ ctypes.c_uint64,
643
+ ctypes.POINTER(_UniffiRustCallStatus),
644
+ )
645
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_u64.restype = ctypes.c_uint64
646
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u64.argtypes = (
647
+ ctypes.c_uint64,
648
+ )
649
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_u64.restype = None
650
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i64.argtypes = (
651
+ ctypes.c_uint64,
652
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
653
+ ctypes.c_uint64,
654
+ )
655
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_i64.restype = None
656
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i64.argtypes = (
657
+ ctypes.c_uint64,
658
+ )
659
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_i64.restype = None
660
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i64.argtypes = (
661
+ ctypes.c_uint64,
662
+ ctypes.POINTER(_UniffiRustCallStatus),
663
+ )
664
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_i64.restype = ctypes.c_int64
665
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i64.argtypes = (
666
+ ctypes.c_uint64,
667
+ )
668
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_i64.restype = None
669
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_f32.argtypes = (
670
+ ctypes.c_uint64,
671
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
672
+ ctypes.c_uint64,
673
+ )
674
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_f32.restype = None
675
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_f32.argtypes = (
676
+ ctypes.c_uint64,
677
+ )
678
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_f32.restype = None
679
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_f32.argtypes = (
680
+ ctypes.c_uint64,
681
+ ctypes.POINTER(_UniffiRustCallStatus),
682
+ )
683
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_f32.restype = ctypes.c_float
684
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_f32.argtypes = (
685
+ ctypes.c_uint64,
686
+ )
687
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_f32.restype = None
688
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_f64.argtypes = (
689
+ ctypes.c_uint64,
690
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
691
+ ctypes.c_uint64,
692
+ )
693
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_f64.restype = None
694
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_f64.argtypes = (
695
+ ctypes.c_uint64,
696
+ )
697
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_f64.restype = None
698
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_f64.argtypes = (
699
+ ctypes.c_uint64,
700
+ ctypes.POINTER(_UniffiRustCallStatus),
701
+ )
702
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_f64.restype = ctypes.c_double
703
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_f64.argtypes = (
704
+ ctypes.c_uint64,
705
+ )
706
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_f64.restype = None
707
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_rust_buffer.argtypes = (
708
+ ctypes.c_uint64,
709
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
710
+ ctypes.c_uint64,
711
+ )
712
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_rust_buffer.restype = None
713
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_rust_buffer.argtypes = (
714
+ ctypes.c_uint64,
715
+ )
716
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_rust_buffer.restype = None
717
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_rust_buffer.argtypes = (
718
+ ctypes.c_uint64,
719
+ ctypes.POINTER(_UniffiRustCallStatus),
720
+ )
721
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_rust_buffer.restype = _UniffiRustBuffer
722
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_rust_buffer.argtypes = (
723
+ ctypes.c_uint64,
724
+ )
725
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_rust_buffer.restype = None
726
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_void.argtypes = (
727
+ ctypes.c_uint64,
728
+ _UNIFFI_RUST_FUTURE_CONTINUATION_CALLBACK,
729
+ ctypes.c_uint64,
730
+ )
731
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_poll_void.restype = None
732
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_void.argtypes = (
733
+ ctypes.c_uint64,
734
+ )
735
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_cancel_void.restype = None
736
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_void.argtypes = (
737
+ ctypes.c_uint64,
738
+ ctypes.POINTER(_UniffiRustCallStatus),
739
+ )
740
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_complete_void.restype = None
741
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_void.argtypes = (
742
+ ctypes.c_uint64,
743
+ )
744
+ _UniffiLib.ffi_matrix_sdk_contentscanner_rust_future_free_void.restype = None
745
+ _UniffiLib.ffi_matrix_sdk_contentscanner_uniffi_contract_version.argtypes = (
746
+ )
747
+ _UniffiLib.ffi_matrix_sdk_contentscanner_uniffi_contract_version.restype = ctypes.c_uint32
748
+
749
+ _uniffi_check_contract_api_version(_UniffiLib)
750
+ # _uniffi_check_api_checksums(_UniffiLib)
751
+
752
+
753
+
754
+ # Public interface members begin here.
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+ class ErrorReason(enum.Enum):
763
+ """
764
+ The reason for the content scanner error.
765
+ """
766
+
767
+ MCS_MALFORMED_JSON = 0
768
+ """
769
+ The JSON file is malformed.
770
+ """
771
+
772
+ MCS_MEDIA_FAILED_TO_DECRYPT = 1
773
+ """
774
+ The media could not be decrypted.
775
+ """
776
+
777
+ M_MISSING_TOKEN = 2
778
+ """
779
+ No access token was provided.
780
+ """
781
+
782
+ M_UNKNOWN_TOKEN = 3
783
+ """
784
+ The access token provided is invalid.
785
+ """
786
+
787
+ M_NOT_FOUND = 4
788
+ """
789
+ The media was not found.
790
+ """
791
+
792
+ MCS_MEDIA_NOT_CLEAN = 5
793
+ """
794
+ The media has some potentially dangerous content.
795
+ """
796
+
797
+ MCS_MIME_TYPE_FORBIDDEN = 6
798
+ """
799
+ The media has been blocked by the server because of its mime type.
800
+ """
801
+
802
+ MCS_BAD_DECRYPTION = 7
803
+ """
804
+ The used public key is wrong.
805
+ """
806
+
807
+ M_UNKNOWN = 8
808
+ """
809
+ An unknown error occurred.
810
+ """
811
+
812
+ MCS_MEDIA_REQUEST_FAILED = 9
813
+ """
814
+ The server failed to request media from the media repo.
815
+ """
816
+
817
+
818
+
819
+ class _UniffiFfiConverterTypeErrorReason(_UniffiConverterRustBuffer):
820
+ @staticmethod
821
+ def read(buf):
822
+ variant = buf.read_i32()
823
+ if variant == 1:
824
+ return ErrorReason.MCS_MALFORMED_JSON
825
+ if variant == 2:
826
+ return ErrorReason.MCS_MEDIA_FAILED_TO_DECRYPT
827
+ if variant == 3:
828
+ return ErrorReason.M_MISSING_TOKEN
829
+ if variant == 4:
830
+ return ErrorReason.M_UNKNOWN_TOKEN
831
+ if variant == 5:
832
+ return ErrorReason.M_NOT_FOUND
833
+ if variant == 6:
834
+ return ErrorReason.MCS_MEDIA_NOT_CLEAN
835
+ if variant == 7:
836
+ return ErrorReason.MCS_MIME_TYPE_FORBIDDEN
837
+ if variant == 8:
838
+ return ErrorReason.MCS_BAD_DECRYPTION
839
+ if variant == 9:
840
+ return ErrorReason.M_UNKNOWN
841
+ if variant == 10:
842
+ return ErrorReason.MCS_MEDIA_REQUEST_FAILED
843
+ raise InternalError("Raw enum value doesn't match any cases")
844
+
845
+ @staticmethod
846
+ def check_lower(value):
847
+ if value == ErrorReason.MCS_MALFORMED_JSON:
848
+ return
849
+ if value == ErrorReason.MCS_MEDIA_FAILED_TO_DECRYPT:
850
+ return
851
+ if value == ErrorReason.M_MISSING_TOKEN:
852
+ return
853
+ if value == ErrorReason.M_UNKNOWN_TOKEN:
854
+ return
855
+ if value == ErrorReason.M_NOT_FOUND:
856
+ return
857
+ if value == ErrorReason.MCS_MEDIA_NOT_CLEAN:
858
+ return
859
+ if value == ErrorReason.MCS_MIME_TYPE_FORBIDDEN:
860
+ return
861
+ if value == ErrorReason.MCS_BAD_DECRYPTION:
862
+ return
863
+ if value == ErrorReason.M_UNKNOWN:
864
+ return
865
+ if value == ErrorReason.MCS_MEDIA_REQUEST_FAILED:
866
+ return
867
+ raise ValueError(value)
868
+
869
+ @staticmethod
870
+ def write(value, buf):
871
+ if value == ErrorReason.MCS_MALFORMED_JSON:
872
+ buf.write_i32(1)
873
+ if value == ErrorReason.MCS_MEDIA_FAILED_TO_DECRYPT:
874
+ buf.write_i32(2)
875
+ if value == ErrorReason.M_MISSING_TOKEN:
876
+ buf.write_i32(3)
877
+ if value == ErrorReason.M_UNKNOWN_TOKEN:
878
+ buf.write_i32(4)
879
+ if value == ErrorReason.M_NOT_FOUND:
880
+ buf.write_i32(5)
881
+ if value == ErrorReason.MCS_MEDIA_NOT_CLEAN:
882
+ buf.write_i32(6)
883
+ if value == ErrorReason.MCS_MIME_TYPE_FORBIDDEN:
884
+ buf.write_i32(7)
885
+ if value == ErrorReason.MCS_BAD_DECRYPTION:
886
+ buf.write_i32(8)
887
+ if value == ErrorReason.M_UNKNOWN:
888
+ buf.write_i32(9)
889
+ if value == ErrorReason.MCS_MEDIA_REQUEST_FAILED:
890
+ buf.write_i32(10)
891
+
892
+
893
+
894
+ class _UniffiFfiConverterUInt8(_UniffiConverterPrimitiveInt):
895
+ CLASS_NAME = "u8"
896
+ VALUE_MIN = 0
897
+ VALUE_MAX = 2**8
898
+
899
+ @staticmethod
900
+ def read(buf):
901
+ return buf.read_u8()
902
+
903
+ @staticmethod
904
+ def write(value, buf):
905
+ buf.write_u8(value)
906
+
907
+ class _UniffiFfiConverterString:
908
+ @staticmethod
909
+ def check_lower(value):
910
+ if not isinstance(value, str):
911
+ raise TypeError("argument must be str, not {}".format(type(value).__name__))
912
+ return value
913
+
914
+ @staticmethod
915
+ def read(buf):
916
+ size = buf.read_i32()
917
+ if size < 0:
918
+ raise InternalError("Unexpected negative string length")
919
+ utf8_bytes = buf.read(size)
920
+ return utf8_bytes.decode("utf-8")
921
+
922
+ @staticmethod
923
+ def write(value, buf):
924
+ utf8_bytes = value.encode("utf-8")
925
+ buf.write_i32(len(utf8_bytes))
926
+ buf.write(utf8_bytes)
927
+
928
+ @staticmethod
929
+ def lift(buf):
930
+ with buf.consume_with_stream() as stream:
931
+ return stream.read(stream.remaining()).decode("utf-8")
932
+
933
+ @staticmethod
934
+ def lower(value):
935
+ with _UniffiRustBuffer.alloc_with_builder() as builder:
936
+ builder.write(value.encode("utf-8"))
937
+ return builder.finalize()
938
+
939
+ __all__ = [
940
+ "InternalError",
941
+ "ErrorReason",
942
+ ]