faster-eth-abi 5.2.3__cp310-cp310-win_amd64.whl → 5.2.19__cp310-cp310-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.

Potentially problematic release.


This version of faster-eth-abi might be problematic. Click here for more details.

Files changed (43) hide show
  1. faster_eth_abi/_codec.cp310-win_amd64.pyd +0 -0
  2. faster_eth_abi/_codec.py +83 -0
  3. faster_eth_abi/_decoding.cp310-win_amd64.pyd +0 -0
  4. faster_eth_abi/_decoding.py +299 -0
  5. faster_eth_abi/_encoding.cp310-win_amd64.pyd +0 -0
  6. faster_eth_abi/_encoding.py +251 -0
  7. faster_eth_abi/_grammar.cp310-win_amd64.pyd +0 -0
  8. faster_eth_abi/_grammar.py +375 -0
  9. faster_eth_abi/abi.cp310-win_amd64.pyd +0 -0
  10. faster_eth_abi/base.py +5 -1
  11. faster_eth_abi/codec.py +2694 -52
  12. faster_eth_abi/constants.cp310-win_amd64.pyd +0 -0
  13. faster_eth_abi/decoding.py +263 -242
  14. faster_eth_abi/encoding.py +201 -154
  15. faster_eth_abi/exceptions.py +26 -14
  16. faster_eth_abi/from_type_str.cp310-win_amd64.pyd +0 -0
  17. faster_eth_abi/from_type_str.py +7 -1
  18. faster_eth_abi/grammar.py +30 -325
  19. faster_eth_abi/io.py +5 -1
  20. faster_eth_abi/packed.cp310-win_amd64.pyd +0 -0
  21. faster_eth_abi/packed.py +4 -0
  22. faster_eth_abi/registry.py +201 -83
  23. faster_eth_abi/tools/__init__.cp310-win_amd64.pyd +0 -0
  24. faster_eth_abi/tools/_strategies.cp310-win_amd64.pyd +0 -0
  25. faster_eth_abi/tools/_strategies.py +12 -6
  26. faster_eth_abi/typing.py +4627 -0
  27. faster_eth_abi/utils/__init__.cp310-win_amd64.pyd +0 -0
  28. faster_eth_abi/utils/numeric.cp310-win_amd64.pyd +0 -0
  29. faster_eth_abi/utils/numeric.py +51 -20
  30. faster_eth_abi/utils/padding.cp310-win_amd64.pyd +0 -0
  31. faster_eth_abi/utils/string.cp310-win_amd64.pyd +0 -0
  32. faster_eth_abi/utils/validation.cp310-win_amd64.pyd +0 -0
  33. faster_eth_abi/utils/validation.py +1 -5
  34. faster_eth_abi-5.2.19.dist-info/METADATA +136 -0
  35. faster_eth_abi-5.2.19.dist-info/RECORD +46 -0
  36. faster_eth_abi-5.2.19.dist-info/top_level.txt +2 -0
  37. faster_eth_abi__mypyc.cp310-win_amd64.pyd +0 -0
  38. a1f8aa123fabc88e2b56__mypyc.cp310-win_amd64.pyd +0 -0
  39. faster_eth_abi-5.2.3.dist-info/METADATA +0 -95
  40. faster_eth_abi-5.2.3.dist-info/RECORD +0 -38
  41. faster_eth_abi-5.2.3.dist-info/licenses/LICENSE +0 -21
  42. faster_eth_abi-5.2.3.dist-info/top_level.txt +0 -3
  43. {faster_eth_abi-5.2.3.dist-info → faster_eth_abi-5.2.19.dist-info}/WHEEL +0 -0
@@ -0,0 +1,375 @@
1
+ """
2
+ Private helpers for ABI type string grammar and parsing, intended for C compilation.
3
+
4
+ This file exists because the original grammar.py is not ready to be fully compiled to C.
5
+ This module contains functions and logic that we do wish to compile.
6
+ """
7
+ import re
8
+ from typing import (
9
+ Any,
10
+ Final,
11
+ Generic,
12
+ Literal,
13
+ NewType,
14
+ NoReturn,
15
+ Optional,
16
+ Tuple,
17
+ TypeVar,
18
+ Union,
19
+ cast,
20
+ final,
21
+ )
22
+
23
+ from eth_typing.abi import (
24
+ TypeStr,
25
+ )
26
+ from parsimonious.nodes import (
27
+ Node,
28
+ )
29
+ from typing_extensions import (
30
+ Self,
31
+ )
32
+
33
+ from faster_eth_abi.exceptions import (
34
+ ABITypeError,
35
+ )
36
+
37
+ TYPE_ALIASES: Final = {
38
+ "int": "int256",
39
+ "uint": "uint256",
40
+ "fixed": "fixed128x18",
41
+ "ufixed": "ufixed128x18",
42
+ "function": "bytes24",
43
+ "byte": "bytes1",
44
+ }
45
+
46
+ TYPE_ALIAS_RE: Final = re.compile(
47
+ rf"\b({'|'.join(map(re.escape, TYPE_ALIASES.keys()))})\b"
48
+ )
49
+
50
+
51
+ Arrlist = Tuple[Union[int, Tuple[int, ...]], ...]
52
+ IntSubtype = NewType("IntSubtype", int)
53
+ FixedSubtype = NewType("FixedSubtype", Tuple[int, int])
54
+ Subtype = Union[IntSubtype, FixedSubtype]
55
+ TSub = TypeVar("TSub", IntSubtype, FixedSubtype, Literal[None])
56
+
57
+
58
+ class ABIType:
59
+ """
60
+ Base class for results of type string parsing operations.
61
+
62
+ Notes
63
+ -----
64
+ Users are unable to subclass this class. If your use case requires subclassing,
65
+ you will need to stick to the original `eth-abi`.
66
+
67
+ """
68
+
69
+ arrlist: Final[Optional[Arrlist]]
70
+ node: Final[Optional[Node]]
71
+
72
+ __slots__ = ("arrlist", "node")
73
+
74
+ def __init__(
75
+ self, arrlist: Optional[Arrlist] = None, node: Optional[Node] = None
76
+ ) -> None:
77
+ self.arrlist = arrlist
78
+ """
79
+ The list of array dimensions for a parsed type. Equal to ``None`` if
80
+ type string has no array dimensions.
81
+ """
82
+
83
+ self.node = node
84
+ """
85
+ The parsimonious ``Node`` instance associated with this parsed type.
86
+ Used to generate error messages for invalid types.
87
+ """
88
+
89
+ def __repr__(self) -> str: # pragma: no cover
90
+ return f"<{type(self).__qualname__} {self.to_type_str()!r}>"
91
+
92
+ def __eq__(self, other: Any) -> bool:
93
+ # Two ABI types are equal if their string representations are equal
94
+ return type(self) is type(other) and self.to_type_str() == other.to_type_str()
95
+
96
+ def to_type_str(self) -> TypeStr: # pragma: no cover
97
+ """
98
+ Returns the string representation of an ABI type. This will be equal to
99
+ the type string from which it was created.
100
+ """
101
+ raise NotImplementedError("Must implement `to_type_str`")
102
+
103
+ @property
104
+ def item_type(self) -> Self:
105
+ """
106
+ If this type is an array type, equal to an appropriate
107
+ :class:`~faster_eth_abi.grammar.ABIType` instance for the array's items.
108
+ """
109
+ raise NotImplementedError("Must implement `item_type`")
110
+
111
+ def validate(self) -> None: # pragma: no cover
112
+ """
113
+ Validates the properties of an ABI type against the solidity ABI spec:
114
+
115
+ https://solidity.readthedocs.io/en/develop/abi-spec.html
116
+
117
+ Raises :class:`~faster_eth_abi.exceptions.ABITypeError` if validation fails.
118
+ """
119
+ raise NotImplementedError("Must implement `validate`")
120
+
121
+ @final
122
+ def invalidate(self, error_msg: str) -> NoReturn:
123
+ # Invalidates an ABI type with the given error message. Expects that a
124
+ # parsimonious node was provided from the original parsing operation
125
+ # that yielded this type.
126
+ node = self.node
127
+
128
+ raise ABITypeError(
129
+ f"For '{node.text}' type at column {node.start + 1} "
130
+ f"in '{node.full_text}': {error_msg}"
131
+ )
132
+
133
+ @final
134
+ @property
135
+ def is_array(self) -> bool:
136
+ """
137
+ Equal to ``True`` if a type is an array type (i.e. if it has an array
138
+ dimension list). Otherwise, equal to ``False``.
139
+ """
140
+ return self.arrlist is not None
141
+
142
+ @property
143
+ def is_dynamic(self) -> bool:
144
+ """
145
+ Equal to ``True`` if a type has a dynamically sized encoding.
146
+ Otherwise, equal to ``False``.
147
+ """
148
+ raise NotImplementedError("Must implement `is_dynamic`")
149
+
150
+ @final
151
+ @property
152
+ def _has_dynamic_arrlist(self) -> bool:
153
+ return self.is_array and any(len(dim) == 0 for dim in self.arrlist)
154
+
155
+
156
+ TComp = TypeVar("TComp", bound=ABIType)
157
+
158
+
159
+ class TupleType(ABIType):
160
+ """
161
+ Represents the result of parsing a tuple type string e.g. "(int,bool)".
162
+
163
+ Notes
164
+ -----
165
+ Users are unable to subclass this class. If your use case requires subclassing,
166
+ you will need to stick to the original `eth-abi`.
167
+
168
+ """
169
+
170
+ __slots__ = ("components",)
171
+
172
+ def __init__(
173
+ self,
174
+ components: Tuple[TComp, ...],
175
+ arrlist: Optional[Arrlist] = None,
176
+ *,
177
+ node: Optional[Node] = None,
178
+ ) -> None:
179
+ super().__init__(arrlist, node)
180
+
181
+ self.components: Final = components
182
+ """
183
+ A tuple of :class:`~faster_eth_abi.grammar.ABIType` instances for each of the
184
+ tuple type's components.
185
+ """
186
+
187
+ def to_type_str(self) -> TypeStr:
188
+ components = f"({','.join(c.to_type_str() for c in self.components)})"
189
+
190
+ if isinstance(arrlist := self.arrlist, tuple):
191
+ return components + "".join(map(repr, map(list, arrlist)))
192
+ else:
193
+ return components
194
+
195
+ @property
196
+ def item_type(self) -> Self:
197
+ if not self.is_array:
198
+ raise ValueError(
199
+ f"Cannot determine item type for non-array type '{self.to_type_str()}'"
200
+ )
201
+
202
+ arrlist = cast(Arrlist, self.arrlist)[:-1] or None
203
+ cls = type(self)
204
+ if cls is TupleType:
205
+ return cast(Self, TupleType(self.components, arrlist, node=self.node))
206
+ else:
207
+ return cls(self.components, arrlist, node=self.node)
208
+
209
+ def validate(self) -> None:
210
+ for c in self.components:
211
+ c.validate()
212
+
213
+ @property
214
+ def is_dynamic(self) -> bool:
215
+ if self._has_dynamic_arrlist:
216
+ return True
217
+
218
+ return any(c.is_dynamic for c in self.components)
219
+
220
+
221
+ class BasicType(ABIType, Generic[TSub]):
222
+ """
223
+ Represents the result of parsing a basic type string e.g. "uint", "address",
224
+ "ufixed128x19[][2]".
225
+
226
+ Notes
227
+ -----
228
+ Users are unable to subclass this class. If your use case requires subclassing,
229
+ you will need to stick to the original `eth-abi`.
230
+
231
+ """
232
+
233
+ __slots__ = ("base", "sub")
234
+
235
+ def __init__(
236
+ self,
237
+ base: str,
238
+ sub: Optional[TSub] = None,
239
+ arrlist: Optional[Arrlist] = None,
240
+ *,
241
+ node: Optional[Node] = None,
242
+ ) -> None:
243
+ super().__init__(arrlist, node)
244
+
245
+ self.base: Final = base
246
+ """The base of a basic type e.g. "uint" for "uint256" etc."""
247
+
248
+ self.sub: Final = sub
249
+ """
250
+ The sub type of a basic type e.g. ``256`` for "uint256" or ``(128, 18)``
251
+ for "ufixed128x18" etc. Equal to ``None`` if type string has no sub
252
+ type.
253
+ """
254
+
255
+ def to_type_str(self) -> TypeStr:
256
+ sub, arrlist = self.sub, self.arrlist
257
+
258
+ if isinstance(sub, int):
259
+ substr = str(sub)
260
+ elif isinstance(sub, tuple):
261
+ substr = "x".join(map(str, sub))
262
+ else:
263
+ substr = ""
264
+
265
+ if isinstance(arrlist, tuple):
266
+ return self.base + substr + "".join(map(repr, map(list, arrlist)))
267
+ else:
268
+ return self.base + substr
269
+
270
+ @property
271
+ def item_type(self) -> Self:
272
+ if not self.is_array:
273
+ raise ValueError(
274
+ f"Cannot determine item type for non-array type '{self.to_type_str()}'"
275
+ )
276
+
277
+ cls = type(self)
278
+ arrlist = cast(Arrlist, self.arrlist)[:-1] or None
279
+ if cls is BasicType:
280
+ return cast(Self, BasicType(self.base, self.sub, arrlist, node=self.node))
281
+ else:
282
+ return cls(self.base, self.sub, arrlist, node=self.node)
283
+
284
+ @property
285
+ def is_dynamic(self) -> bool:
286
+ if self._has_dynamic_arrlist:
287
+ return True
288
+
289
+ base = self.base
290
+ if base == "string":
291
+ return True
292
+
293
+ if base == "bytes" and self.sub is None:
294
+ return True
295
+
296
+ return False
297
+
298
+ def validate(self) -> None:
299
+ base, sub = self.base, self.sub
300
+
301
+ # Check validity of string type
302
+ if base == "string":
303
+ if sub is not None:
304
+ self.invalidate("string type cannot have suffix")
305
+
306
+ # Check validity of bytes type
307
+ elif base == "bytes":
308
+ if not (sub is None or isinstance(sub, int)):
309
+ self.invalidate(
310
+ "bytes type must have either no suffix or a numerical suffix"
311
+ )
312
+
313
+ if isinstance(sub, int) and sub > 32:
314
+ self.invalidate("maximum 32 bytes for fixed-length bytes")
315
+
316
+ # Check validity of integer type
317
+ elif base in ("int", "uint"):
318
+ if not isinstance(sub, int):
319
+ self.invalidate("integer type must have numerical suffix")
320
+
321
+ if sub < 8 or sub > 256:
322
+ self.invalidate("integer size out of bounds (max 256 bits)")
323
+
324
+ if sub % 8 != 0:
325
+ self.invalidate("integer size must be multiple of 8")
326
+
327
+ # Check validity of fixed type
328
+ elif base in ("fixed", "ufixed"):
329
+ if not isinstance(sub, tuple):
330
+ self.invalidate(
331
+ "fixed type must have suffix of form <bits>x<exponent>, "
332
+ "e.g. 128x19",
333
+ )
334
+
335
+ bits, minus_e = sub
336
+
337
+ if bits < 8 or bits > 256:
338
+ self.invalidate("fixed size out of bounds (max 256 bits)")
339
+
340
+ if bits % 8 != 0:
341
+ self.invalidate("fixed size must be multiple of 8")
342
+
343
+ if minus_e < 1 or minus_e > 80:
344
+ self.invalidate(
345
+ f"fixed exponent size out of bounds, {minus_e} must be in 1-80"
346
+ )
347
+
348
+ # Check validity of hash type
349
+ elif base == "hash":
350
+ if not isinstance(sub, int):
351
+ self.invalidate("hash type must have numerical suffix")
352
+
353
+ # Check validity of address type
354
+ elif base == "address":
355
+ if sub is not None:
356
+ self.invalidate("address cannot have suffix")
357
+
358
+
359
+ BytesType = BasicType[IntSubtype]
360
+ FixedType = BasicType[FixedSubtype]
361
+
362
+
363
+ def normalize(type_str: TypeStr) -> TypeStr:
364
+ """
365
+ Normalizes a type string into its canonical version e.g. the type string
366
+ 'int' becomes 'int256', etc.
367
+
368
+ :param type_str: The type string to be normalized.
369
+ :returns: The canonical version of the input type string.
370
+ """
371
+ return TYPE_ALIAS_RE.sub(__normalize, type_str)
372
+
373
+
374
+ def __normalize(match: "re.Match[str]") -> str:
375
+ return TYPE_ALIASES[match.group(0)]
Binary file
faster_eth_abi/base.py CHANGED
@@ -1,3 +1,7 @@
1
+ """Base classes for encoder and decoder implementations.
2
+
3
+ Defines the foundational interface and validation logic for all coder classes.
4
+ """
1
5
  from typing import (
2
6
  Any,
3
7
  )
@@ -29,7 +33,7 @@ class BaseCoder:
29
33
  # Validate given combination of kwargs
30
34
  self.validate()
31
35
 
32
- def validate(self):
36
+ def validate(self) -> None:
33
37
  pass
34
38
 
35
39
  @classmethod