|
| 1 | +from typing import ( |
| 2 | + Any, |
| 3 | + List, |
| 4 | + Union, |
| 5 | + TypeVar, |
| 6 | + Callable, |
| 7 | + overload, |
| 8 | +) |
| 9 | + |
| 10 | +_T = TypeVar('_T') |
| 11 | +_PyBuffer = Any |
| 12 | + |
| 13 | + |
| 14 | +class FFI: |
| 15 | + |
| 16 | + class CType: |
| 17 | + cname: str |
| 18 | + kind: str |
| 19 | + item: ffi.CType |
| 20 | + |
| 21 | + class CData: |
| 22 | + def __getitem__(self, item: int) -> Any: ... |
| 23 | + def __setitem__(self, item: int, value: Any) -> None: ... |
| 24 | + |
| 25 | + class buffer: |
| 26 | + @overload |
| 27 | + def __init__(self, cdata: ffi.CData) -> None: ... |
| 28 | + @overload |
| 29 | + def __init__(self, cdata: ffi.CData, size: int) -> None: ... |
| 30 | + |
| 31 | + class error(Exception): |
| 32 | + pass |
| 33 | + |
| 34 | + NULL: CData |
| 35 | + |
| 36 | + errno: int |
| 37 | + |
| 38 | + @staticmethod |
| 39 | + def new(cdecl: Any, init: Any = ...) -> CData: ... |
| 40 | + |
| 41 | + @overload |
| 42 | + @staticmethod |
| 43 | + def cast(ctype: str, value: Any) -> CData: ... |
| 44 | + @overload |
| 45 | + @staticmethod |
| 46 | + def cast(ctype: CType, value: Any) -> CData: ... |
| 47 | + |
| 48 | + @overload |
| 49 | + @staticmethod |
| 50 | + def string(cdata: CData) -> bytes: ... |
| 51 | + @overload |
| 52 | + @staticmethod |
| 53 | + def string(cdata: CData, maxlen: int) -> bytes: ... |
| 54 | + |
| 55 | + @staticmethod |
| 56 | + def unpack(cdata: CData, lenght: int) -> Union[bytes, str, List[Any]]: ... |
| 57 | + |
| 58 | + @overload |
| 59 | + @staticmethod |
| 60 | + def from_buffer(cdecl: str, python_buffer: _PyBuffer, require_writable: bool = ...) -> CData: ... |
| 61 | + @overload |
| 62 | + @staticmethod |
| 63 | + def from_buffer(cdecl: CType, python_buffer: _PyBuffer, require_writable: bool = ...) -> CData: ... |
| 64 | + @overload |
| 65 | + @staticmethod |
| 66 | + def from_buffer(python_buffer: _PyBuffer, require_writable: bool = ...) -> CData: ... |
| 67 | + |
| 68 | + @staticmethod |
| 69 | + def memmove(dest: CData, src: CData, n: int) -> None: ... |
| 70 | + |
| 71 | + @overload |
| 72 | + @staticmethod |
| 73 | + def typeof(ctype: str) -> CType: ... |
| 74 | + @overload |
| 75 | + @staticmethod |
| 76 | + def typeof(cdata: CData) -> CType: ... |
| 77 | + |
| 78 | + @overload |
| 79 | + @staticmethod |
| 80 | + def sizeof(ctype: str) -> int: ... |
| 81 | + @overload |
| 82 | + @staticmethod |
| 83 | + def sizeof(ctype: CType) -> int: ... |
| 84 | + @overload |
| 85 | + @staticmethod |
| 86 | + def sizeof(cdata: CData) -> int: ... |
| 87 | + |
| 88 | + @overload |
| 89 | + @staticmethod |
| 90 | + def alignof(ctype: str) -> int: ... |
| 91 | + @overload |
| 92 | + @staticmethod |
| 93 | + def alignof(ctype: CType) -> int: ... |
| 94 | + @overload |
| 95 | + @staticmethod |
| 96 | + def alignof(cdata: CData) -> int: ... |
| 97 | + |
| 98 | + @overload |
| 99 | + @staticmethod |
| 100 | + def offsetof(ctype: str, *args: Union[int, str]) -> int: ... |
| 101 | + @overload |
| 102 | + @staticmethod |
| 103 | + def offsetof(ctype: CType, *args: Union[int, str]) -> int: ... |
| 104 | + |
| 105 | + @staticmethod |
| 106 | + def addressof(cdata: CData, *args: Union[int, str]) -> CData: ... |
| 107 | + |
| 108 | + @staticmethod |
| 109 | + def gc( |
| 110 | + cdata: CData, |
| 111 | + destructor: Callable[[CData], None], |
| 112 | + size: int = ... |
| 113 | + ) -> CData: ... |
| 114 | + |
| 115 | + @staticmethod |
| 116 | + def new_handle(python_object: Any) -> CData: ... |
| 117 | + |
| 118 | + @staticmethod |
| 119 | + def from_handle(cdata: CData) -> Any: ... |
| 120 | + |
| 121 | + @staticmethod |
| 122 | + def new_allocator( |
| 123 | + malloc: Callable[[int], CData], |
| 124 | + free: Callable[[CData], None], |
| 125 | + should_clear_after_alloc: bool = ..., |
| 126 | + ) -> Callable[..., CData]: ... |
| 127 | + |
| 128 | + @overload |
| 129 | + @staticmethod |
| 130 | + def release(cdata: CData) -> None: ... |
| 131 | + @overload |
| 132 | + @staticmethod |
| 133 | + def release(cdata: ffi.buffer) -> None: ... |
| 134 | + |
| 135 | + @staticmethod |
| 136 | + def init_once(function: Callable[[], _T], tag: str) -> _T: ... |
| 137 | + |
| 138 | + @overload |
| 139 | + @staticmethod |
| 140 | + def getctype(ctype: str, extra: str = ...) -> str: ... |
| 141 | + @overload |
| 142 | + @staticmethod |
| 143 | + def getctype(ctype: CType, extra: str = ...) -> str: ... |
| 144 | + |
| 145 | + |
| 146 | +class Lib: |
| 147 | + def __getattr__(self, attr: str) -> Any: ... |
| 148 | + def __setattr__(self, attr: str, value: Any) -> None: ... |
| 149 | + |
| 150 | + |
| 151 | +ffi = FFI |
| 152 | +lib: Lib = ... |
0 commit comments