faster-eth-utils 4.1.7__cp314-cp314t-win_amd64.whl → 5.3.22__cp314-cp314t-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-utils might be problematic. Click here for more details.
- faster_eth_utils/__init__.py +19 -1
- faster_eth_utils/abi.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/abi.py +834 -34
- faster_eth_utils/address.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/address.py +19 -43
- faster_eth_utils/applicators.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/applicators.py +109 -64
- faster_eth_utils/conversions.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/conversions.py +36 -29
- faster_eth_utils/crypto.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/crypto.py +3 -8
- faster_eth_utils/currency.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/currency.py +55 -21
- faster_eth_utils/curried/__init__.py +91 -67
- faster_eth_utils/debug.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/decorators.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/decorators.py +65 -29
- faster_eth_utils/encoding.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/encoding.py +1 -1
- faster_eth_utils/exceptions.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/exceptions.py +8 -1
- faster_eth_utils/functional.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/functional.py +10 -12
- faster_eth_utils/hexadecimal.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/hexadecimal.py +19 -16
- faster_eth_utils/humanize.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/humanize.py +35 -23
- faster_eth_utils/logging.py +54 -61
- faster_eth_utils/module_loading.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/network.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/network.py +2 -3
- faster_eth_utils/numeric.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/pydantic.py +103 -0
- faster_eth_utils/toolz.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/types.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils/types.py +20 -17
- faster_eth_utils/units.cp314t-win_amd64.pyd +0 -0
- {faster_eth_utils-4.1.7.dist-info → faster_eth_utils-5.3.22.dist-info}/METADATA +59 -17
- faster_eth_utils-5.3.22.dist-info/RECORD +53 -0
- {faster_eth_utils-4.1.7.dist-info → faster_eth_utils-5.3.22.dist-info}/licenses/LICENSE +1 -1
- faster_eth_utils-5.3.22.dist-info/top_level.txt +3 -0
- faster_eth_utils__mypyc.cp314t-win_amd64.pyd +0 -0
- 99c07adba6ff961eaf3e__mypyc.cp314t-win_amd64.pyd +0 -0
- faster_eth_utils-4.1.7.dist-info/RECORD +0 -52
- faster_eth_utils-4.1.7.dist-info/top_level.txt +0 -3
- {faster_eth_utils-4.1.7.dist-info → faster_eth_utils-5.3.22.dist-info}/WHEEL +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from collections.abc import Callable, Generator, Sequence
|
|
1
3
|
from typing import (
|
|
4
|
+
TYPE_CHECKING,
|
|
2
5
|
Any,
|
|
3
|
-
Callable,
|
|
4
|
-
Dict,
|
|
5
|
-
Generator,
|
|
6
6
|
Optional,
|
|
7
|
-
|
|
8
|
-
Tuple,
|
|
7
|
+
TypeGuard,
|
|
9
8
|
TypeVar,
|
|
10
9
|
Union,
|
|
11
10
|
overload,
|
|
12
11
|
)
|
|
13
12
|
|
|
14
13
|
from faster_eth_utils import (
|
|
14
|
+
CamelModel,
|
|
15
15
|
ExtendedDebugLogger,
|
|
16
16
|
HasExtendedDebugLogger,
|
|
17
17
|
HasExtendedDebugLoggerMeta,
|
|
@@ -19,6 +19,7 @@ from faster_eth_utils import (
|
|
|
19
19
|
HasLoggerMeta,
|
|
20
20
|
Network,
|
|
21
21
|
ValidationError,
|
|
22
|
+
abi_to_signature,
|
|
22
23
|
add_0x_prefix,
|
|
23
24
|
apply_formatter_at_index,
|
|
24
25
|
apply_formatter_if as non_curried_apply_formatter_if,
|
|
@@ -30,6 +31,7 @@ from faster_eth_utils import (
|
|
|
30
31
|
apply_to_return_value,
|
|
31
32
|
big_endian_to_int,
|
|
32
33
|
clamp,
|
|
34
|
+
collapse_if_tuple,
|
|
33
35
|
combine_argument_formatters,
|
|
34
36
|
combomethod,
|
|
35
37
|
decode_hex,
|
|
@@ -37,15 +39,27 @@ from faster_eth_utils import (
|
|
|
37
39
|
encode_hex,
|
|
38
40
|
event_abi_to_log_topic,
|
|
39
41
|
event_signature_to_log_topic,
|
|
42
|
+
filter_abi_by_name,
|
|
43
|
+
filter_abi_by_type,
|
|
40
44
|
flatten_return,
|
|
41
45
|
from_wei,
|
|
46
|
+
from_wei_decimals,
|
|
42
47
|
function_abi_to_4byte_selector,
|
|
43
48
|
function_signature_to_4byte_selector,
|
|
49
|
+
get_abi_input_names,
|
|
50
|
+
get_abi_input_types,
|
|
51
|
+
get_abi_output_names,
|
|
52
|
+
get_abi_output_types,
|
|
53
|
+
get_aligned_abi_inputs,
|
|
54
|
+
get_all_event_abis,
|
|
55
|
+
get_all_function_abis,
|
|
44
56
|
get_extended_debug_logger,
|
|
45
57
|
get_logger,
|
|
58
|
+
get_normalized_abi_inputs,
|
|
46
59
|
hexstr_if_str as non_curried_hexstr_if_str,
|
|
47
60
|
humanize_bytes,
|
|
48
61
|
humanize_hash,
|
|
62
|
+
humanize_hexstr,
|
|
49
63
|
humanize_integer_sequence,
|
|
50
64
|
humanize_ipfs_uri,
|
|
51
65
|
humanize_seconds,
|
|
@@ -97,141 +111,143 @@ from faster_eth_utils import (
|
|
|
97
111
|
to_text,
|
|
98
112
|
to_tuple,
|
|
99
113
|
to_wei,
|
|
114
|
+
to_wei_decimals,
|
|
100
115
|
)
|
|
101
116
|
from faster_eth_utils.toolz import (
|
|
102
117
|
curry,
|
|
103
118
|
)
|
|
104
119
|
|
|
120
|
+
if TYPE_CHECKING:
|
|
121
|
+
from _typeshed import SupportsBool
|
|
122
|
+
# We have to sacrifice a little bit of specificity on dinosaur Python3.8
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
TArg = TypeVar("TArg")
|
|
126
|
+
TOther = TypeVar("TOther")
|
|
105
127
|
TReturn = TypeVar("TReturn")
|
|
106
128
|
TValue = TypeVar("TValue")
|
|
107
129
|
|
|
108
130
|
|
|
109
131
|
@overload
|
|
110
132
|
def apply_formatter_if(
|
|
111
|
-
condition: Callable[
|
|
112
|
-
) -> Callable[[Callable[
|
|
113
|
-
|
|
114
|
-
|
|
133
|
+
condition: Callable[[TArg], TypeGuard[TOther]],
|
|
134
|
+
) -> Callable[[Callable[[TOther], TReturn]], Callable[[TArg], TReturn | TArg]]:
|
|
135
|
+
...
|
|
115
136
|
|
|
116
137
|
@overload
|
|
117
138
|
def apply_formatter_if(
|
|
118
|
-
condition: Callable[
|
|
119
|
-
) -> Callable[[
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn]
|
|
140
|
+
) -> Callable[[TArg], TReturn | TArg]:
|
|
141
|
+
...
|
|
122
142
|
|
|
123
143
|
@overload
|
|
124
144
|
def apply_formatter_if(
|
|
125
|
-
condition: Callable[
|
|
126
|
-
) ->
|
|
127
|
-
|
|
145
|
+
condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn], value: TArg
|
|
146
|
+
) -> TReturn | TArg:
|
|
147
|
+
...
|
|
128
148
|
|
|
149
|
+
@overload
|
|
150
|
+
def apply_formatter_if(
|
|
151
|
+
condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg
|
|
152
|
+
) -> TReturn | TArg:
|
|
153
|
+
...
|
|
129
154
|
|
|
130
|
-
# This is just a stub to appease mypy, it gets overwritten later
|
|
131
155
|
def apply_formatter_if( # type: ignore
|
|
132
|
-
condition: Callable[
|
|
133
|
-
formatter:
|
|
134
|
-
value:
|
|
135
|
-
) ->
|
|
136
|
-
Callable[[Callable[
|
|
137
|
-
Callable[[
|
|
138
|
-
TReturn
|
|
139
|
-
|
|
140
|
-
|
|
156
|
+
condition: Callable[[TArg], TypeGuard[TOther]] | Callable[[TArg], bool],
|
|
157
|
+
formatter: Callable[[TOther], TReturn] | Callable[[TArg], TReturn] | None = None,
|
|
158
|
+
value: TArg | None = None,
|
|
159
|
+
) -> (
|
|
160
|
+
Callable[[Callable[[TOther], TReturn]], Callable[[TArg], TReturn | TArg]] |
|
|
161
|
+
Callable[[TArg], TReturn | TArg] |
|
|
162
|
+
TReturn |
|
|
163
|
+
TArg
|
|
164
|
+
):
|
|
141
165
|
pass
|
|
142
166
|
|
|
143
167
|
|
|
144
168
|
@overload
|
|
145
169
|
def apply_one_of_formatters(
|
|
146
170
|
formatter_condition_pairs: Sequence[
|
|
147
|
-
|
|
148
|
-
]
|
|
149
|
-
) -> Callable[[
|
|
150
|
-
...
|
|
171
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
172
|
+
],
|
|
173
|
+
) -> Callable[[TArg], TReturn]: ...
|
|
151
174
|
|
|
152
175
|
|
|
153
176
|
@overload
|
|
154
177
|
def apply_one_of_formatters(
|
|
155
178
|
formatter_condition_pairs: Sequence[
|
|
156
|
-
|
|
179
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
157
180
|
],
|
|
158
|
-
value:
|
|
159
|
-
) -> TReturn:
|
|
160
|
-
...
|
|
181
|
+
value: TArg,
|
|
182
|
+
) -> TReturn: ...
|
|
161
183
|
|
|
162
184
|
|
|
163
185
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
164
|
-
def apply_one_of_formatters( # type: ignore
|
|
186
|
+
def apply_one_of_formatters( # type: ignore[empty-body]
|
|
165
187
|
formatter_condition_pairs: Sequence[
|
|
166
|
-
|
|
188
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
167
189
|
],
|
|
168
|
-
value:
|
|
169
|
-
) -> TReturn:
|
|
170
|
-
...
|
|
190
|
+
value: TArg | None = None,
|
|
191
|
+
) -> Callable[[TArg], TReturn] | TReturn: ...
|
|
171
192
|
|
|
172
193
|
|
|
173
194
|
@overload
|
|
174
195
|
def hexstr_if_str(
|
|
175
|
-
to_type: Callable[..., TReturn]
|
|
176
|
-
) -> Callable[[
|
|
177
|
-
...
|
|
196
|
+
to_type: Callable[..., TReturn],
|
|
197
|
+
) -> Callable[[bytes | int | str], TReturn]: ...
|
|
178
198
|
|
|
179
199
|
|
|
180
200
|
@overload
|
|
181
201
|
def hexstr_if_str(
|
|
182
|
-
to_type: Callable[..., TReturn], to_format:
|
|
183
|
-
) -> TReturn:
|
|
184
|
-
...
|
|
202
|
+
to_type: Callable[..., TReturn], to_format: bytes | int | str
|
|
203
|
+
) -> TReturn: ...
|
|
185
204
|
|
|
186
205
|
|
|
187
206
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
188
207
|
def hexstr_if_str( # type: ignore
|
|
189
|
-
to_type: Callable[..., TReturn], to_format:
|
|
190
|
-
) -> TReturn:
|
|
191
|
-
...
|
|
208
|
+
to_type: Callable[..., TReturn], to_format: bytes | int | str | None = None
|
|
209
|
+
) -> TReturn: ...
|
|
192
210
|
|
|
193
211
|
|
|
194
212
|
@overload
|
|
195
213
|
def text_if_str(
|
|
196
|
-
to_type: Callable[..., TReturn]
|
|
197
|
-
) -> Callable[[
|
|
198
|
-
...
|
|
214
|
+
to_type: Callable[..., TReturn],
|
|
215
|
+
) -> Callable[[bytes | int | str], TReturn]: ...
|
|
199
216
|
|
|
200
217
|
|
|
201
218
|
@overload
|
|
202
219
|
def text_if_str(
|
|
203
|
-
to_type: Callable[..., TReturn], text_or_primitive:
|
|
204
|
-
) -> TReturn:
|
|
205
|
-
...
|
|
220
|
+
to_type: Callable[..., TReturn], text_or_primitive: bytes | int | str
|
|
221
|
+
) -> TReturn: ...
|
|
206
222
|
|
|
207
223
|
|
|
208
224
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
209
225
|
def text_if_str( # type: ignore
|
|
210
226
|
to_type: Callable[..., TReturn],
|
|
211
|
-
text_or_primitive:
|
|
212
|
-
) -> TReturn:
|
|
213
|
-
...
|
|
227
|
+
text_or_primitive: bytes | int | str | None = None,
|
|
228
|
+
) -> TReturn: ...
|
|
214
229
|
|
|
215
230
|
|
|
216
231
|
@overload
|
|
217
232
|
def apply_formatters_to_dict(
|
|
218
|
-
formatters:
|
|
219
|
-
) -> Callable[[
|
|
233
|
+
formatters: dict[Any, Any], unaliased: bool = False
|
|
234
|
+
) -> Callable[[dict[Any, Any] | CamelModel], dict[Any, Any]]:
|
|
220
235
|
...
|
|
221
236
|
|
|
222
237
|
|
|
223
238
|
@overload
|
|
224
239
|
def apply_formatters_to_dict(
|
|
225
|
-
formatters:
|
|
226
|
-
) ->
|
|
240
|
+
formatters: dict[Any, Any], value: dict[Any, Any] | CamelModel, unaliased: bool = False
|
|
241
|
+
) -> dict[Any, Any]:
|
|
227
242
|
...
|
|
228
243
|
|
|
229
244
|
|
|
230
245
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
231
|
-
def apply_formatters_to_dict(
|
|
232
|
-
formatters:
|
|
233
|
-
|
|
234
|
-
|
|
246
|
+
def apply_formatters_to_dict(
|
|
247
|
+
formatters: dict[Any, Any],
|
|
248
|
+
value: dict[Any, Any] | CamelModel | None = None,
|
|
249
|
+
unaliased: bool = False,
|
|
250
|
+
) -> dict[Any, Any]: ...
|
|
235
251
|
|
|
236
252
|
|
|
237
253
|
apply_formatter_at_index = curry(apply_formatter_at_index)
|
|
@@ -241,12 +257,21 @@ apply_formatters_to_dict = curry(non_curried_apply_formatters_to_dict) # noqa:
|
|
|
241
257
|
apply_formatters_to_sequence = curry(apply_formatters_to_sequence)
|
|
242
258
|
apply_key_map = curry(apply_key_map)
|
|
243
259
|
apply_one_of_formatters = curry(non_curried_apply_one_of_formatters) # noqa: F811
|
|
260
|
+
filter_abi_by_name = curry(filter_abi_by_name)
|
|
261
|
+
filter_abi_by_type = curry(filter_abi_by_type)
|
|
262
|
+
flatten_return = curry(flatten_return)
|
|
244
263
|
from_wei = curry(from_wei)
|
|
264
|
+
from_wei_decimals = curry(from_wei_decimals)
|
|
265
|
+
get_aligned_abi_inputs = curry(get_aligned_abi_inputs)
|
|
245
266
|
get_logger = curry(get_logger)
|
|
267
|
+
get_normalized_abi_inputs = curry(get_normalized_abi_inputs)
|
|
246
268
|
hexstr_if_str = curry(non_curried_hexstr_if_str) # noqa: F811
|
|
247
269
|
is_same_address = curry(is_same_address)
|
|
270
|
+
sort_return = curry(sort_return)
|
|
248
271
|
text_if_str = curry(non_curried_text_if_str) # noqa: F811
|
|
272
|
+
to_ordered_dict = curry(to_ordered_dict)
|
|
249
273
|
to_wei = curry(to_wei)
|
|
274
|
+
to_wei_decimals = curry(to_wei_decimals)
|
|
250
275
|
clamp = curry(clamp)
|
|
251
276
|
|
|
252
277
|
# Delete any methods and classes that are not intended to be importable from
|
|
@@ -255,13 +280,12 @@ clamp = curry(clamp)
|
|
|
255
280
|
# `from eth_utils.curried import *`
|
|
256
281
|
del Any
|
|
257
282
|
del Callable
|
|
258
|
-
del Dict
|
|
259
283
|
del Generator
|
|
260
284
|
del Optional
|
|
261
285
|
del Sequence
|
|
262
286
|
del TReturn
|
|
263
287
|
del TValue
|
|
264
|
-
del
|
|
288
|
+
del TypeGuard
|
|
265
289
|
del TypeVar
|
|
266
290
|
del Union
|
|
267
291
|
del curry
|
|
Binary file
|
|
Binary file
|
faster_eth_utils/decorators.py
CHANGED
|
@@ -1,69 +1,103 @@
|
|
|
1
1
|
import functools
|
|
2
|
-
import
|
|
3
|
-
import os
|
|
2
|
+
from collections.abc import Callable
|
|
4
3
|
from typing import (
|
|
5
4
|
Any,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Type,
|
|
5
|
+
Concatenate,
|
|
6
|
+
Final,
|
|
7
|
+
Generic,
|
|
10
8
|
TypeVar,
|
|
11
9
|
final,
|
|
12
10
|
)
|
|
13
11
|
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
)
|
|
12
|
+
from typing_extensions import ParamSpec
|
|
13
|
+
|
|
14
|
+
P = ParamSpec("P")
|
|
17
15
|
|
|
18
16
|
T = TypeVar("T")
|
|
19
17
|
|
|
18
|
+
TInstance = TypeVar("TInstance", bound=object)
|
|
19
|
+
"""A TypeVar representing an instance that a method can bind to."""
|
|
20
|
+
|
|
20
21
|
|
|
21
22
|
@final
|
|
22
|
-
class combomethod:
|
|
23
|
-
def __init__(
|
|
24
|
-
self
|
|
23
|
+
class combomethod(Generic[TInstance, P, T]):
|
|
24
|
+
def __init__(
|
|
25
|
+
self, method: Callable[Concatenate[TInstance | type[TInstance], P], T]
|
|
26
|
+
) -> None:
|
|
27
|
+
self.method: Final = method
|
|
28
|
+
|
|
29
|
+
def __repr__(self) -> str:
|
|
30
|
+
return f"combomethod({self.method})"
|
|
25
31
|
|
|
26
32
|
def __get__(
|
|
27
|
-
self,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
self,
|
|
34
|
+
obj: TInstance | None,
|
|
35
|
+
objtype: type[TInstance],
|
|
36
|
+
) -> Callable[P, T]:
|
|
37
|
+
|
|
38
|
+
method = self.method
|
|
39
|
+
bound_arg = objtype if obj is None else obj
|
|
40
|
+
|
|
41
|
+
@functools.wraps(method)
|
|
42
|
+
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
43
|
+
return method(bound_arg, *args, **kwargs)
|
|
35
44
|
|
|
36
45
|
return _wrapper
|
|
37
46
|
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
_return_arg_type_deco_cache: Final[
|
|
49
|
+
dict[int, Callable[[Callable[P, T]], Callable[P, Any]]]
|
|
50
|
+
] = {}
|
|
51
|
+
# No need to hold so many unique instances in memory
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def return_arg_type(at_position: int) -> Callable[[Callable[P, T]], Callable[P, Any]]:
|
|
40
55
|
"""
|
|
41
56
|
Wrap the return value with the result of `type(args[at_position])`.
|
|
42
57
|
"""
|
|
58
|
+
if deco := _return_arg_type_deco_cache.get(at_position):
|
|
59
|
+
return deco
|
|
43
60
|
|
|
44
|
-
def decorator(to_wrap: Callable[
|
|
61
|
+
def decorator(to_wrap: Callable[P, Any]) -> Callable[P, Any]:
|
|
45
62
|
@functools.wraps(to_wrap)
|
|
46
|
-
def wrapper(*args:
|
|
63
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
|
|
47
64
|
result = to_wrap(*args, **kwargs)
|
|
48
65
|
ReturnType = type(args[at_position])
|
|
49
|
-
return ReturnType(result) # type: ignore
|
|
66
|
+
return ReturnType(result) # type: ignore [call-arg]
|
|
50
67
|
|
|
51
68
|
return wrapper
|
|
52
69
|
|
|
70
|
+
_return_arg_type_deco_cache[at_position] = decorator
|
|
71
|
+
|
|
53
72
|
return decorator
|
|
54
73
|
|
|
55
74
|
|
|
75
|
+
ExcType = type[BaseException]
|
|
76
|
+
|
|
77
|
+
ReplaceExceptionsCache = dict[
|
|
78
|
+
tuple[tuple[ExcType, ExcType], ...],
|
|
79
|
+
Callable[[Callable[P, T]], Callable[P, T]],
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
_replace_exceptions_deco_cache: Final[ReplaceExceptionsCache[..., Any]] = {}
|
|
83
|
+
# No need to hold so many unique instances in memory
|
|
84
|
+
|
|
85
|
+
|
|
56
86
|
def replace_exceptions(
|
|
57
|
-
old_to_new_exceptions:
|
|
58
|
-
) -> Callable[[Callable[
|
|
87
|
+
old_to_new_exceptions: dict[ExcType, ExcType],
|
|
88
|
+
) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
59
89
|
"""
|
|
60
90
|
Replaces old exceptions with new exceptions to be raised in their place.
|
|
61
91
|
"""
|
|
62
|
-
|
|
92
|
+
cache_key = tuple(old_to_new_exceptions.items())
|
|
93
|
+
if deco := _replace_exceptions_deco_cache.get(cache_key):
|
|
94
|
+
return deco
|
|
95
|
+
|
|
96
|
+
old_exceptions = tuple(old_to_new_exceptions)
|
|
63
97
|
|
|
64
|
-
def decorator(to_wrap: Callable[
|
|
98
|
+
def decorator(to_wrap: Callable[P, T]) -> Callable[P, T]:
|
|
65
99
|
@functools.wraps(to_wrap)
|
|
66
|
-
def wrapped(*args:
|
|
100
|
+
def wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
67
101
|
try:
|
|
68
102
|
return to_wrap(*args, **kwargs)
|
|
69
103
|
except old_exceptions as err:
|
|
@@ -76,4 +110,6 @@ def replace_exceptions(
|
|
|
76
110
|
|
|
77
111
|
return wrapped
|
|
78
112
|
|
|
113
|
+
_replace_exceptions_deco_cache[cache_key] = decorator
|
|
114
|
+
|
|
79
115
|
return decorator
|
|
Binary file
|
faster_eth_utils/encoding.py
CHANGED
|
Binary file
|
faster_eth_utils/exceptions.py
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"""
|
|
2
|
+
faster-eth-utils exceptions always inherit from eth-utils exceptions, so porting to faster-eth-utils
|
|
3
|
+
does not require any change to your existing exception handlers. They will continue to work.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import eth_utils.exceptions
|
|
7
|
+
|
|
8
|
+
class ValidationError(eth_utils.exceptions.ValidationError): # type: ignore[misc]
|
|
2
9
|
"""
|
|
3
10
|
Raised when something does not pass a validation check.
|
|
4
11
|
"""
|
|
Binary file
|
faster_eth_utils/functional.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import collections
|
|
2
2
|
import functools
|
|
3
3
|
import itertools
|
|
4
|
+
from collections.abc import Callable, Iterable, Mapping
|
|
4
5
|
from typing import ( # noqa: F401
|
|
5
|
-
Callable,
|
|
6
6
|
Dict,
|
|
7
|
-
Iterable,
|
|
8
7
|
List,
|
|
9
|
-
Mapping,
|
|
10
8
|
Set,
|
|
11
9
|
Tuple,
|
|
12
10
|
TypeVar,
|
|
@@ -57,25 +55,25 @@ def apply_to_return_value(
|
|
|
57
55
|
TVal = TypeVar("TVal")
|
|
58
56
|
TKey = TypeVar("TKey")
|
|
59
57
|
|
|
60
|
-
def to_tuple(fn: Callable[P, Iterable[TVal]]) -> Callable[P,
|
|
61
|
-
def to_tuple_wrap(*args: P.args, **kwargs: P.kwargs) ->
|
|
58
|
+
def to_tuple(fn: Callable[P, Iterable[TVal]]) -> Callable[P, tuple[TVal, ...]]:
|
|
59
|
+
def to_tuple_wrap(*args: P.args, **kwargs: P.kwargs) -> tuple[TVal, ...]:
|
|
62
60
|
return tuple(fn(*args, **kwargs))
|
|
63
61
|
return to_tuple_wrap
|
|
64
62
|
|
|
65
|
-
def to_list(fn: Callable[P, Iterable[TVal]]) -> Callable[P,
|
|
66
|
-
def to_list_wrap(*args: P.args, **kwargs: P.kwargs) ->
|
|
63
|
+
def to_list(fn: Callable[P, Iterable[TVal]]) -> Callable[P, list[TVal]]:
|
|
64
|
+
def to_list_wrap(*args: P.args, **kwargs: P.kwargs) -> list[TVal]:
|
|
67
65
|
return list(fn(*args, **kwargs))
|
|
68
66
|
return to_list_wrap
|
|
69
67
|
|
|
70
|
-
def to_set(fn: Callable[P, Iterable[TVal]]) -> Callable[P,
|
|
71
|
-
def to_set_wrap(*args: P.args, **kwargs: P.kwargs) ->
|
|
68
|
+
def to_set(fn: Callable[P, Iterable[TVal]]) -> Callable[P, set[TVal]]:
|
|
69
|
+
def to_set_wrap(*args: P.args, **kwargs: P.kwargs) -> set[TVal]:
|
|
72
70
|
return set(fn(*args, **kwargs))
|
|
73
71
|
return to_set_wrap
|
|
74
72
|
|
|
75
73
|
def to_dict(
|
|
76
|
-
fn: Callable[P,
|
|
77
|
-
) -> Callable[P,
|
|
78
|
-
def to_dict_wrap(*args: P.args, **kwargs: P.kwargs) ->
|
|
74
|
+
fn: Callable[P, Mapping[TKey, TVal] | Iterable[tuple[TKey, TVal]]]
|
|
75
|
+
) -> Callable[P, dict[TKey, TVal]]:
|
|
76
|
+
def to_dict_wrap(*args: P.args, **kwargs: P.kwargs) -> dict[TKey, TVal]:
|
|
79
77
|
return dict(fn(*args, **kwargs))
|
|
80
78
|
return to_dict_wrap
|
|
81
79
|
|
|
Binary file
|
faster_eth_utils/hexadecimal.py
CHANGED
|
@@ -4,18 +4,19 @@ import binascii
|
|
|
4
4
|
import re
|
|
5
5
|
from typing import (
|
|
6
6
|
Any,
|
|
7
|
-
AnyStr,
|
|
8
7
|
Final,
|
|
8
|
+
TypeGuard,
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
from eth_typing import (
|
|
12
12
|
HexStr,
|
|
13
13
|
)
|
|
14
|
-
from typing_extensions import (
|
|
15
|
-
TypeGuard,
|
|
16
|
-
)
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
_HEX_REGEXP_MATCH: Final = re.compile("(0[xX])?[0-9a-fA-F]*").fullmatch
|
|
16
|
+
|
|
17
|
+
_hexlify: Final = binascii.hexlify
|
|
18
|
+
_unhexlify: Final = binascii.unhexlify
|
|
19
|
+
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
def decode_hex(value: str) -> bytes:
|
|
@@ -24,27 +25,29 @@ def decode_hex(value: str) -> bytes:
|
|
|
24
25
|
non_prefixed = remove_0x_prefix(HexStr(value))
|
|
25
26
|
# unhexlify will only accept bytes type someday
|
|
26
27
|
ascii_hex = non_prefixed.encode("ascii")
|
|
27
|
-
return
|
|
28
|
+
return _unhexlify(ascii_hex)
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
def encode_hex(value:
|
|
31
|
+
def encode_hex(value: str | bytes | bytearray) -> HexStr:
|
|
32
|
+
ascii_bytes: bytes | bytearray
|
|
31
33
|
if isinstance(value, (bytes, bytearray)):
|
|
32
34
|
ascii_bytes = value
|
|
33
35
|
elif isinstance(value, str):
|
|
34
|
-
ascii_bytes = value.encode("ascii")
|
|
36
|
+
ascii_bytes = value.encode("ascii")
|
|
35
37
|
else:
|
|
36
38
|
raise TypeError("Value must be an instance of str or unicode")
|
|
37
39
|
|
|
38
|
-
binary_hex =
|
|
40
|
+
binary_hex = _hexlify(ascii_bytes)
|
|
39
41
|
return add_0x_prefix(HexStr(binary_hex.decode("ascii")))
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
def is_0x_prefixed(value: str) -> bool:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
# this check is not needed in the compiled version
|
|
46
|
+
# if not isinstance(value, str):
|
|
47
|
+
# raise TypeError(
|
|
48
|
+
# f"is_0x_prefixed requires text typed arguments. Got: {repr(value)}"
|
|
49
|
+
# )
|
|
50
|
+
return value.startswith("0x") or value.startswith("0X")
|
|
48
51
|
|
|
49
52
|
|
|
50
53
|
def remove_0x_prefix(value: HexStr) -> HexStr:
|
|
@@ -62,7 +65,7 @@ def add_0x_prefix(value: HexStr) -> HexStr:
|
|
|
62
65
|
def is_hexstr(value: Any) -> TypeGuard[HexStr]:
|
|
63
66
|
if not isinstance(value, str) or not value:
|
|
64
67
|
return False
|
|
65
|
-
return
|
|
68
|
+
return _HEX_REGEXP_MATCH(value) is not None
|
|
66
69
|
|
|
67
70
|
|
|
68
71
|
def is_hex(value: Any) -> TypeGuard[HexStr]:
|
|
@@ -70,4 +73,4 @@ def is_hex(value: Any) -> TypeGuard[HexStr]:
|
|
|
70
73
|
raise TypeError(f"is_hex requires text typed arguments. Got: {repr(value)}")
|
|
71
74
|
if not value:
|
|
72
75
|
return False
|
|
73
|
-
return
|
|
76
|
+
return _HEX_REGEXP_MATCH(value) is not None
|
|
Binary file
|