faster-eth-abi 5.2.3__cp314-cp314t-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 (38) hide show
  1. a1f8aa123fabc88e2b56__mypyc.cpython-314t-darwin.so +0 -0
  2. faster_eth_abi/__init__.py +12 -0
  3. faster_eth_abi/abi.cpython-314t-darwin.so +0 -0
  4. faster_eth_abi/abi.py +17 -0
  5. faster_eth_abi/base.py +41 -0
  6. faster_eth_abi/codec.py +167 -0
  7. faster_eth_abi/constants.cpython-314t-darwin.so +0 -0
  8. faster_eth_abi/constants.py +7 -0
  9. faster_eth_abi/decoding.py +563 -0
  10. faster_eth_abi/encoding.py +699 -0
  11. faster_eth_abi/exceptions.py +115 -0
  12. faster_eth_abi/from_type_str.cpython-314t-darwin.so +0 -0
  13. faster_eth_abi/from_type_str.py +135 -0
  14. faster_eth_abi/grammar.py +467 -0
  15. faster_eth_abi/io.py +103 -0
  16. faster_eth_abi/packed.cpython-314t-darwin.so +0 -0
  17. faster_eth_abi/packed.py +15 -0
  18. faster_eth_abi/py.typed +0 -0
  19. faster_eth_abi/registry.py +640 -0
  20. faster_eth_abi/tools/__init__.cpython-314t-darwin.so +0 -0
  21. faster_eth_abi/tools/__init__.py +3 -0
  22. faster_eth_abi/tools/_strategies.cpython-314t-darwin.so +0 -0
  23. faster_eth_abi/tools/_strategies.py +237 -0
  24. faster_eth_abi/utils/__init__.cpython-314t-darwin.so +0 -0
  25. faster_eth_abi/utils/__init__.py +0 -0
  26. faster_eth_abi/utils/numeric.cpython-314t-darwin.so +0 -0
  27. faster_eth_abi/utils/numeric.py +86 -0
  28. faster_eth_abi/utils/padding.cpython-314t-darwin.so +0 -0
  29. faster_eth_abi/utils/padding.py +22 -0
  30. faster_eth_abi/utils/string.cpython-314t-darwin.so +0 -0
  31. faster_eth_abi/utils/string.py +19 -0
  32. faster_eth_abi/utils/validation.cpython-314t-darwin.so +0 -0
  33. faster_eth_abi/utils/validation.py +22 -0
  34. faster_eth_abi-5.2.3.dist-info/METADATA +95 -0
  35. faster_eth_abi-5.2.3.dist-info/RECORD +38 -0
  36. faster_eth_abi-5.2.3.dist-info/WHEEL +6 -0
  37. faster_eth_abi-5.2.3.dist-info/licenses/LICENSE +21 -0
  38. faster_eth_abi-5.2.3.dist-info/top_level.txt +3 -0
@@ -0,0 +1,115 @@
1
+ import parsimonious
2
+
3
+
4
+ class EncodingError(Exception):
5
+ """
6
+ Base exception for any error that occurs during encoding.
7
+ """
8
+
9
+
10
+ class EncodingTypeError(EncodingError):
11
+ """
12
+ Raised when trying to encode a python value whose type is not supported for
13
+ the output ABI type.
14
+ """
15
+
16
+
17
+ class IllegalValue(EncodingError):
18
+ """
19
+ Raised when trying to encode a python value with the correct type but with
20
+ a value that is not considered legal for the output ABI type.
21
+
22
+ .. code-block:: python
23
+
24
+ fixed128x19_encoder(Decimal('NaN')) # cannot encode NaN
25
+
26
+ """
27
+
28
+
29
+ class ValueOutOfBounds(IllegalValue):
30
+ """
31
+ Raised when trying to encode a python value with the correct type but with
32
+ a value that appears outside the range of valid values for the output ABI
33
+ type.
34
+
35
+ .. code-block:: python
36
+
37
+ ufixed8x1_encoder(Decimal('25.6')) # out of bounds
38
+
39
+ """
40
+
41
+
42
+ class DecodingError(Exception):
43
+ """
44
+ Base exception for any error that occurs during decoding.
45
+ """
46
+
47
+
48
+ class InsufficientDataBytes(DecodingError):
49
+ """
50
+ Raised when there are insufficient data to decode a value for a given ABI type.
51
+ """
52
+
53
+
54
+ class NonEmptyPaddingBytes(DecodingError):
55
+ """
56
+ Raised when the padding bytes of an ABI value are malformed.
57
+ """
58
+
59
+
60
+ class InvalidPointer(DecodingError):
61
+ """
62
+ Raised when the pointer to a value in the ABI encoding is invalid.
63
+ """
64
+
65
+
66
+ class ParseError(parsimonious.ParseError): # type: ignore[misc] # subclasses Any
67
+ """
68
+ Raised when an ABI type string cannot be parsed.
69
+ """
70
+
71
+ def __str__(self) -> str:
72
+ return (
73
+ f"Parse error at '{self.text[self.pos : self.pos + 5]}' "
74
+ f"(column {self.column()}) in type string '{self.text}'"
75
+ )
76
+
77
+
78
+ class ABITypeError(ValueError):
79
+ """
80
+ Raised when a parsed ABI type has inconsistent properties; for example,
81
+ when trying to parse the type string ``'uint7'`` (which has a bit-width
82
+ that is not congruent with zero modulo eight).
83
+ """
84
+
85
+
86
+ class PredicateMappingError(Exception):
87
+ """
88
+ Raised when an error occurs in a registry's internal mapping.
89
+ """
90
+
91
+
92
+ class NoEntriesFound(ValueError, PredicateMappingError):
93
+ """
94
+ Raised when no registration is found for a type string in a registry's
95
+ internal mapping.
96
+
97
+ .. warning::
98
+
99
+ In a future version of ``faster-eth-abi``, this error class will no longer
100
+ inherit from ``ValueError``.
101
+ """
102
+
103
+
104
+ class MultipleEntriesFound(ValueError, PredicateMappingError):
105
+ """
106
+ Raised when multiple registrations are found for a type string in a
107
+ registry's internal mapping. This error is non-recoverable and indicates
108
+ that a registry was configured incorrectly. Registrations are expected to
109
+ cover completely distinct ranges of type strings.
110
+
111
+ .. warning::
112
+
113
+ In a future version of ``faster-eth-abi``, this error class will no longer
114
+ inherit from ``ValueError``.
115
+ """
@@ -0,0 +1,135 @@
1
+ import functools
2
+ from typing import (
3
+ TYPE_CHECKING,
4
+ Any,
5
+ Callable,
6
+ Optional,
7
+ Type,
8
+ TypeVar,
9
+ )
10
+
11
+ from eth_typing import (
12
+ TypeStr,
13
+ )
14
+
15
+ from .grammar import (
16
+ ABIType,
17
+ BasicType,
18
+ TupleType,
19
+ normalize,
20
+ parse,
21
+ )
22
+
23
+ if TYPE_CHECKING:
24
+ from .base import (
25
+ BaseCoder,
26
+ )
27
+
28
+
29
+ TType = TypeVar("TType", bound=Type["BaseCoder"])
30
+ OldFromTypeStr = Callable[["BaseCoder", ABIType, Any], TType]
31
+ if TYPE_CHECKING:
32
+ NewFromTypeStr = classmethod[TType, [TypeStr, Any], TType]
33
+
34
+
35
+ def parse_type_str(
36
+ expected_base: Optional[str] = None,
37
+ with_arrlist: bool = False,
38
+ ) -> Callable[[OldFromTypeStr[TType]], "NewFromTypeStr[TType]"]:
39
+ """
40
+ Used by BaseCoder subclasses as a convenience for implementing the
41
+ ``from_type_str`` method required by ``ABIRegistry``. Useful if normalizing
42
+ then parsing a type string with an (optional) expected base is required in
43
+ that method.
44
+ """
45
+
46
+ def decorator(old_from_type_str: OldFromTypeStr[TType]) -> "NewFromTypeStr[TType]":
47
+ @functools.wraps(old_from_type_str)
48
+ def new_from_type_str(cls: TType, type_str: TypeStr, registry: Any) -> TType:
49
+ normalized_type_str = normalize(type_str)
50
+ abi_type = parse(normalized_type_str)
51
+
52
+ type_str_repr = repr(type_str)
53
+ if type_str != normalized_type_str:
54
+ type_str_repr = (
55
+ f"{type_str_repr} (normalized to {normalized_type_str!r})"
56
+ )
57
+
58
+ if expected_base is not None:
59
+ if not isinstance(abi_type, BasicType):
60
+ raise ValueError(
61
+ "Cannot create {} for non-basic type {}".format(
62
+ cls.__name__,
63
+ type_str_repr,
64
+ )
65
+ )
66
+ if abi_type.base != expected_base:
67
+ raise ValueError(
68
+ "Cannot create {} for type {}: expected type with "
69
+ "base '{}'".format(
70
+ cls.__name__,
71
+ type_str_repr,
72
+ expected_base,
73
+ )
74
+ )
75
+
76
+ if not with_arrlist and abi_type.arrlist is not None:
77
+ raise ValueError(
78
+ "Cannot create {} for type {}: expected type with "
79
+ "no array dimension list".format(
80
+ cls.__name__,
81
+ type_str_repr,
82
+ )
83
+ )
84
+ if with_arrlist and abi_type.arrlist is None:
85
+ raise ValueError(
86
+ "Cannot create {} for type {}: expected type with "
87
+ "array dimension list".format(
88
+ cls.__name__,
89
+ type_str_repr,
90
+ )
91
+ )
92
+
93
+ # Perform general validation of default solidity types
94
+ abi_type.validate()
95
+
96
+ return old_from_type_str(cls, abi_type, registry)
97
+
98
+ return classmethod(new_from_type_str)
99
+
100
+ return decorator
101
+
102
+
103
+ def parse_tuple_type_str(
104
+ old_from_type_str: OldFromTypeStr[TType],
105
+ ) -> "NewFromTypeStr[TType]":
106
+ """
107
+ Used by BaseCoder subclasses as a convenience for implementing the
108
+ ``from_type_str`` method required by ``ABIRegistry``. Useful if normalizing
109
+ then parsing a tuple type string is required in that method.
110
+ """
111
+
112
+ @functools.wraps(old_from_type_str)
113
+ def new_from_type_str(cls: TType, type_str: TypeStr, registry: Any) -> TType:
114
+ normalized_type_str = normalize(type_str)
115
+ abi_type = parse(normalized_type_str)
116
+
117
+ if not isinstance(abi_type, TupleType):
118
+ type_str_repr = repr(type_str)
119
+ if type_str != normalized_type_str:
120
+ type_str_repr = "{} (normalized to {})".format(
121
+ type_str_repr,
122
+ repr(normalized_type_str),
123
+ )
124
+ raise ValueError(
125
+ "Cannot create {} for non-tuple type {}".format(
126
+ cls.__name__,
127
+ type_str_repr,
128
+ )
129
+ )
130
+
131
+ abi_type.validate()
132
+
133
+ return old_from_type_str(cls, abi_type, registry)
134
+
135
+ return classmethod(new_from_type_str)