-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuctypes_.py
103 lines (98 loc) · 3.16 KB
/
uctypes_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
Generate `pyi` from corresponding `rst` docs.
"""
import rst
from rst2pyi import RST2PyI
__author__ = rst.__author__
__copyright__ = rst.__copyright__
__license__ = rst.__license__
__version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver
def uctypes(shed: RST2PyI) -> None:
shed.module(
name="uctypes",
old="access binary data in a structured way",
post_doc=f"""
from typing import Final
from uio import AnyReadableBuf
""",
end=r"Module contents",
)
rst_name = r".. class:: struct(addr, descriptor, layout_type=NATIVE, /)"
shed.class_(
pre_str="# noinspection PyPep8Naming", name="struct", end=rst_name,
)
shed.pyi.imports_vars_defs.extend(
[
"_ScalarProperty: Final = int",
'_RecursiveProperty: Final = tuple[int, "_property"]',
"_ArrayProperty: Final = tuple[int, int]",
'_ArrayOfAggregateProperty: Final = tuple[int, int, "_property"]',
"_PointerToAPrimitiveProperty: Final = tuple[int, int]",
'_PointerToAaAggregateProperty: Final = tuple[int, "_property"]',
"_BitfieldProperty: Final = int",
(
"_property: Final = _ScalarProperty"
" | _RecursiveProperty"
" | _ArrayProperty"
" | _ArrayOfAggregateProperty"
" | _PointerToAPrimitiveProperty"
" | _PointerToAaAggregateProperty"
" | _BitfieldProperty"
),
"_descriptor: Final = tuple[str, _property]",
]
)
shed.def_(
old=rst_name,
new="def __init__(self, addr: int, descriptor: _descriptor, layout_type: int = NATIVE, /)",
)
shed.vars(old=".. data:: LITTLE_ENDIAN", class_var=None)
shed.vars(old=".. data:: BIG_ENDIAN", class_var=None)
shed.vars(old=".. data:: NATIVE", class_var=None)
shed.def_(
pre_str="# noinspection PyShadowingNames",
old=r".. function:: sizeof(struct, layout_type=NATIVE, /)",
new="def sizeof(struct: struct | _descriptor, layout_type: int = NATIVE, /) -> int",
indent=0,
)
shed.def_(
old=r".. function:: addressof(obj)",
new="def addressof(obj: AnyReadableBuf, /) -> int",
indent=0,
)
shed.def_(
old=r".. function:: bytes_at(addr, size)",
new="def bytes_at(addr: int, size: int, /) -> bytes",
indent=0,
)
shed.def_(
old=r".. function:: bytearray_at(addr, size)",
new="def bytearray_at(addr: int, size: int, /) -> bytearray",
indent=0,
)
shed.vars(
old=[
".. data:: UINT8",
"INT8",
"UINT16",
"INT16",
"UINT32",
"INT32",
"UINT64",
"INT64",
],
class_var=None,
)
shed.vars(
old=[".. data:: FLOAT32", "FLOAT64"], class_var=None,
)
shed.vars(
old=".. data:: VOID", class_var=None,
)
shed.vars(
old=[".. data:: PTR", "ARRAY"],
class_var=None,
end="Structure descriptors and instantiating structure objects",
)
shed.extra_docs(end=None)
shed.write()