faster-eth-abi 5.2.22__cp313-cp313-macosx_11_0_arm64.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.
Files changed (46) hide show
  1. faster_eth_abi/__init__.py +12 -0
  2. faster_eth_abi/_codec.cpython-313-darwin.so +0 -0
  3. faster_eth_abi/_codec.py +83 -0
  4. faster_eth_abi/_decoding.cpython-313-darwin.so +0 -0
  5. faster_eth_abi/_decoding.py +299 -0
  6. faster_eth_abi/_encoding.cpython-313-darwin.so +0 -0
  7. faster_eth_abi/_encoding.py +354 -0
  8. faster_eth_abi/_grammar.cpython-313-darwin.so +0 -0
  9. faster_eth_abi/_grammar.py +375 -0
  10. faster_eth_abi/abi.cpython-313-darwin.so +0 -0
  11. faster_eth_abi/abi.py +17 -0
  12. faster_eth_abi/base.py +45 -0
  13. faster_eth_abi/codec.py +2809 -0
  14. faster_eth_abi/constants.cpython-313-darwin.so +0 -0
  15. faster_eth_abi/constants.py +7 -0
  16. faster_eth_abi/decoding.py +584 -0
  17. faster_eth_abi/encoding.py +746 -0
  18. faster_eth_abi/exceptions.py +127 -0
  19. faster_eth_abi/from_type_str.cpython-313-darwin.so +0 -0
  20. faster_eth_abi/from_type_str.py +141 -0
  21. faster_eth_abi/grammar.py +172 -0
  22. faster_eth_abi/io.py +107 -0
  23. faster_eth_abi/packed.cpython-313-darwin.so +0 -0
  24. faster_eth_abi/packed.py +19 -0
  25. faster_eth_abi/py.typed +0 -0
  26. faster_eth_abi/registry.py +758 -0
  27. faster_eth_abi/tools/__init__.cpython-313-darwin.so +0 -0
  28. faster_eth_abi/tools/__init__.py +3 -0
  29. faster_eth_abi/tools/_strategies.cpython-313-darwin.so +0 -0
  30. faster_eth_abi/tools/_strategies.py +243 -0
  31. faster_eth_abi/typing.py +4627 -0
  32. faster_eth_abi/utils/__init__.cpython-313-darwin.so +0 -0
  33. faster_eth_abi/utils/__init__.py +0 -0
  34. faster_eth_abi/utils/numeric.cpython-313-darwin.so +0 -0
  35. faster_eth_abi/utils/numeric.py +117 -0
  36. faster_eth_abi/utils/padding.cpython-313-darwin.so +0 -0
  37. faster_eth_abi/utils/padding.py +22 -0
  38. faster_eth_abi/utils/string.cpython-313-darwin.so +0 -0
  39. faster_eth_abi/utils/string.py +19 -0
  40. faster_eth_abi/utils/validation.cpython-313-darwin.so +0 -0
  41. faster_eth_abi/utils/validation.py +18 -0
  42. faster_eth_abi-5.2.22.dist-info/METADATA +136 -0
  43. faster_eth_abi-5.2.22.dist-info/RECORD +46 -0
  44. faster_eth_abi-5.2.22.dist-info/WHEEL +6 -0
  45. faster_eth_abi-5.2.22.dist-info/top_level.txt +2 -0
  46. faster_eth_abi__mypyc.cpython-313-darwin.so +0 -0
@@ -0,0 +1,3 @@
1
+ from ._strategies import (
2
+ get_abi_strategy,
3
+ )
@@ -0,0 +1,243 @@
1
+ from typing import (
2
+ Callable,
3
+ Final,
4
+ Optional,
5
+ Tuple,
6
+ Union,
7
+ cast,
8
+ )
9
+
10
+ from cchecksum import (
11
+ to_checksum_address,
12
+ )
13
+ from eth_typing.abi import (
14
+ TypeStr,
15
+ )
16
+ from hypothesis import (
17
+ strategies as st,
18
+ )
19
+
20
+ from faster_eth_abi._grammar import (
21
+ ABIType,
22
+ Arrlist,
23
+ BasicType,
24
+ TupleType,
25
+ normalize,
26
+ )
27
+ from faster_eth_abi.grammar import (
28
+ parse,
29
+ )
30
+ from faster_eth_abi.registry import (
31
+ BaseEquals,
32
+ BaseRegistry,
33
+ Lookup,
34
+ PredicateMapping,
35
+ has_arrlist,
36
+ is_base_tuple,
37
+ )
38
+ from faster_eth_abi.utils.numeric import (
39
+ scale_places,
40
+ )
41
+
42
+ StrategyFactory = Callable[[ABIType, "StrategyRegistry"], st.SearchStrategy]
43
+ StrategyRegistration = Union[st.SearchStrategy, StrategyFactory]
44
+
45
+
46
+ class StrategyRegistry(BaseRegistry):
47
+ def __init__(self) -> None:
48
+ self._strategies = PredicateMapping("strategy registry")
49
+
50
+ def register_strategy(
51
+ self,
52
+ lookup: Lookup,
53
+ registration: StrategyRegistration,
54
+ label: Optional[str] = None,
55
+ ) -> None:
56
+ self._register(self._strategies, lookup, registration, label=label)
57
+
58
+ def unregister_strategy(self, lookup_or_label: Lookup) -> None:
59
+ self._unregister(self._strategies, lookup_or_label)
60
+
61
+ def get_strategy(self, type_str: TypeStr) -> st.SearchStrategy:
62
+ """
63
+ Returns a hypothesis strategy for the given ABI type.
64
+
65
+ :param type_str: The canonical string representation of the ABI type
66
+ for which a hypothesis strategy should be returned.
67
+
68
+ :returns: A hypothesis strategy for generating Python values that are
69
+ encodable as values of the given ABI type.
70
+ """
71
+ registration = self._get_registration(self._strategies, type_str)
72
+
73
+ if isinstance(registration, st.SearchStrategy):
74
+ # If a hypothesis strategy was registered, just return it
75
+ return registration
76
+ else:
77
+ # Otherwise, assume the factory is a callable. Call it with the abi
78
+ # type to get an appropriate hypothesis strategy.
79
+ normalized_type_str = normalize(type_str)
80
+ abi_type = parse(normalized_type_str)
81
+ strategy = registration(abi_type, self)
82
+
83
+ return strategy
84
+
85
+
86
+ def get_uint_strategy(
87
+ abi_type: BasicType, registry: StrategyRegistry
88
+ ) -> st.SearchStrategy:
89
+ bits = cast(int, abi_type.sub)
90
+
91
+ return st.integers(
92
+ min_value=0,
93
+ max_value=2**bits - 1,
94
+ )
95
+
96
+
97
+ def get_int_strategy(
98
+ abi_type: BasicType, registry: StrategyRegistry
99
+ ) -> st.SearchStrategy:
100
+ bits = cast(int, abi_type.sub)
101
+
102
+ return st.integers(
103
+ min_value=-(2 ** (bits - 1)),
104
+ max_value=2 ** (bits - 1) - 1,
105
+ )
106
+
107
+
108
+ address_strategy: Final = st.binary(min_size=20, max_size=20).map(to_checksum_address)
109
+ bool_strategy: Final = st.booleans()
110
+
111
+
112
+ def get_ufixed_strategy(
113
+ abi_type: BasicType, registry: StrategyRegistry
114
+ ) -> st.SearchStrategy:
115
+ bits, places = cast(Tuple[int, int], abi_type.sub)
116
+
117
+ return st.decimals(
118
+ min_value=0,
119
+ max_value=2**bits - 1,
120
+ places=0,
121
+ ).map(scale_places(places))
122
+
123
+
124
+ def get_fixed_strategy(
125
+ abi_type: BasicType, registry: StrategyRegistry
126
+ ) -> st.SearchStrategy:
127
+ bits, places = cast(Tuple[int, int], abi_type.sub)
128
+
129
+ return st.decimals(
130
+ min_value=-(2 ** (bits - 1)),
131
+ max_value=2 ** (bits - 1) - 1,
132
+ places=0,
133
+ ).map(scale_places(places))
134
+
135
+
136
+ def get_bytes_strategy(
137
+ abi_type: BasicType, registry: StrategyRegistry
138
+ ) -> st.SearchStrategy:
139
+ num_bytes = abi_type.sub
140
+
141
+ return st.binary(
142
+ min_size=num_bytes,
143
+ max_size=num_bytes,
144
+ )
145
+
146
+
147
+ bytes_strategy: Final = st.binary(min_size=0, max_size=4096)
148
+ string_strategy: Final = st.text()
149
+
150
+
151
+ def get_array_strategy(
152
+ abi_type: ABIType, registry: StrategyRegistry
153
+ ) -> st.SearchStrategy:
154
+ item_type = abi_type.item_type
155
+ item_type_str = item_type.to_type_str()
156
+ item_strategy = registry.get_strategy(item_type_str)
157
+
158
+ arrlist = cast(Arrlist, abi_type.arrlist)
159
+ last_dim = cast(Tuple[int, ...], arrlist[-1])
160
+ if len(last_dim) == 0:
161
+ # Is dynamic list. Don't restrict length.
162
+ return st.lists(item_strategy)
163
+ else:
164
+ # Is static list. Restrict length.
165
+ dim_size = last_dim[0]
166
+ return st.lists(item_strategy, min_size=dim_size, max_size=dim_size)
167
+
168
+
169
+ def get_tuple_strategy(
170
+ abi_type: TupleType, registry: StrategyRegistry
171
+ ) -> st.SearchStrategy:
172
+ component_strategies = [
173
+ registry.get_strategy(comp_abi_type.to_type_str())
174
+ for comp_abi_type in abi_type.components
175
+ ]
176
+
177
+ return st.tuples(*component_strategies)
178
+
179
+
180
+ strategy_registry: Final = StrategyRegistry()
181
+
182
+ strategy_registry.register_strategy(
183
+ BaseEquals("uint"),
184
+ get_uint_strategy,
185
+ label="uint",
186
+ )
187
+ strategy_registry.register_strategy(
188
+ BaseEquals("int"),
189
+ get_int_strategy,
190
+ label="int",
191
+ )
192
+ strategy_registry.register_strategy(
193
+ BaseEquals("address", with_sub=False),
194
+ address_strategy,
195
+ label="address",
196
+ )
197
+ strategy_registry.register_strategy(
198
+ BaseEquals("bool", with_sub=False),
199
+ bool_strategy,
200
+ label="bool",
201
+ )
202
+ strategy_registry.register_strategy(
203
+ BaseEquals("ufixed"),
204
+ get_ufixed_strategy,
205
+ label="ufixed",
206
+ )
207
+ strategy_registry.register_strategy(
208
+ BaseEquals("fixed"),
209
+ get_fixed_strategy,
210
+ label="fixed",
211
+ )
212
+ strategy_registry.register_strategy(
213
+ BaseEquals("bytes", with_sub=True),
214
+ get_bytes_strategy,
215
+ label="bytes<M>",
216
+ )
217
+ strategy_registry.register_strategy(
218
+ BaseEquals("bytes", with_sub=False),
219
+ bytes_strategy,
220
+ label="bytes",
221
+ )
222
+ strategy_registry.register_strategy(
223
+ BaseEquals("function", with_sub=False),
224
+ get_bytes_strategy,
225
+ label="function",
226
+ )
227
+ strategy_registry.register_strategy(
228
+ BaseEquals("string", with_sub=False),
229
+ string_strategy,
230
+ label="string",
231
+ )
232
+ strategy_registry.register_strategy(
233
+ has_arrlist,
234
+ get_array_strategy,
235
+ label="has_arrlist",
236
+ )
237
+ strategy_registry.register_strategy(
238
+ is_base_tuple,
239
+ get_tuple_strategy,
240
+ label="is_base_tuple",
241
+ )
242
+
243
+ get_abi_strategy: Final = strategy_registry.get_strategy