faster-eth-utils 5.3.19__cp311-cp311-win32.whl → 5.3.23__cp311-cp311-win32.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/abi.cp311-win32.pyd +0 -0
- faster_eth_utils/abi.py +76 -55
- faster_eth_utils/address.cp311-win32.pyd +0 -0
- faster_eth_utils/address.py +7 -14
- faster_eth_utils/applicators.cp311-win32.pyd +0 -0
- faster_eth_utils/applicators.py +20 -33
- faster_eth_utils/conversions.cp311-win32.pyd +0 -0
- faster_eth_utils/conversions.py +18 -20
- faster_eth_utils/crypto.cp311-win32.pyd +0 -0
- faster_eth_utils/crypto.py +3 -8
- faster_eth_utils/currency.cp311-win32.pyd +0 -0
- faster_eth_utils/currency.py +11 -8
- faster_eth_utils/curried/__init__.py +35 -44
- faster_eth_utils/debug.cp311-win32.pyd +0 -0
- faster_eth_utils/decorators.cp311-win32.pyd +0 -0
- faster_eth_utils/decorators.py +16 -20
- faster_eth_utils/encoding.cp311-win32.pyd +0 -0
- faster_eth_utils/encoding.py +1 -1
- faster_eth_utils/exceptions.cp311-win32.pyd +0 -0
- faster_eth_utils/exceptions.py +1 -1
- faster_eth_utils/functional.cp311-win32.pyd +0 -0
- faster_eth_utils/functional.py +10 -12
- faster_eth_utils/hexadecimal.cp311-win32.pyd +0 -0
- faster_eth_utils/hexadecimal.py +8 -12
- faster_eth_utils/humanize.cp311-win32.pyd +0 -0
- faster_eth_utils/humanize.py +16 -16
- faster_eth_utils/logging.py +33 -27
- faster_eth_utils/module_loading.cp311-win32.pyd +0 -0
- faster_eth_utils/network.cp311-win32.pyd +0 -0
- faster_eth_utils/network.py +2 -3
- faster_eth_utils/numeric.cp311-win32.pyd +0 -0
- faster_eth_utils/pydantic.py +4 -6
- faster_eth_utils/toolz.cp311-win32.pyd +0 -0
- faster_eth_utils/types.cp311-win32.pyd +0 -0
- faster_eth_utils/types.py +5 -8
- faster_eth_utils/units.cp311-win32.pyd +0 -0
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/METADATA +8 -9
- faster_eth_utils-5.3.23.dist-info/RECORD +53 -0
- faster_eth_utils__mypyc.cp311-win32.pyd +0 -0
- faster_eth_utils-5.3.19.dist-info/RECORD +0 -53
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/WHEEL +0 -0
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/licenses/LICENSE +0 -0
- {faster_eth_utils-5.3.19.dist-info → faster_eth_utils-5.3.23.dist-info}/top_level.txt +0 -0
faster_eth_utils/currency.py
CHANGED
|
@@ -46,11 +46,12 @@ class denoms:
|
|
|
46
46
|
|
|
47
47
|
MIN_WEI: Final = 0
|
|
48
48
|
MAX_WEI: Final = 2**256 - 1
|
|
49
|
+
DECIMAL_ZERO: Final = decimal.Decimal(0)
|
|
49
50
|
|
|
50
51
|
_NumberType = Union[int, float, str, decimal.Decimal]
|
|
51
52
|
|
|
52
53
|
|
|
53
|
-
def _from_wei(number: int, unit_value: decimal.Decimal) ->
|
|
54
|
+
def _from_wei(number: int, unit_value: decimal.Decimal) -> int | decimal.Decimal:
|
|
54
55
|
if number == 0:
|
|
55
56
|
return 0
|
|
56
57
|
|
|
@@ -75,7 +76,7 @@ def _to_wei(number: _NumberType, unit_value: decimal.Decimal) -> int:
|
|
|
75
76
|
else:
|
|
76
77
|
raise TypeError("Unsupported type. Must be one of integer, float, or string")
|
|
77
78
|
|
|
78
|
-
if d_number ==
|
|
79
|
+
if d_number == DECIMAL_ZERO:
|
|
79
80
|
return 0
|
|
80
81
|
|
|
81
82
|
s_number = str(number)
|
|
@@ -97,14 +98,15 @@ def _to_wei(number: _NumberType, unit_value: decimal.Decimal) -> int:
|
|
|
97
98
|
return int(result_value)
|
|
98
99
|
|
|
99
100
|
|
|
100
|
-
def from_wei(number: int, unit: str) ->
|
|
101
|
+
def from_wei(number: int, unit: str) -> int | decimal.Decimal:
|
|
101
102
|
"""
|
|
102
103
|
Takes a number of wei and converts it to any other ether unit.
|
|
103
104
|
"""
|
|
104
|
-
|
|
105
|
+
unit_key = unit.lower()
|
|
106
|
+
if unit_key not in units:
|
|
105
107
|
raise ValueError(f"Unknown unit. Must be one of {'/'.join(units.keys())}")
|
|
106
108
|
|
|
107
|
-
unit_value = units[
|
|
109
|
+
unit_value = units[unit_key]
|
|
108
110
|
|
|
109
111
|
return _from_wei(number, unit_value)
|
|
110
112
|
|
|
@@ -113,15 +115,16 @@ def to_wei(number: _NumberType, unit: str) -> int:
|
|
|
113
115
|
"""
|
|
114
116
|
Takes a number of a unit and converts it to wei.
|
|
115
117
|
"""
|
|
116
|
-
|
|
118
|
+
unit_key = unit.lower()
|
|
119
|
+
if unit_key not in units:
|
|
117
120
|
raise ValueError(f"Unknown unit. Must be one of {'/'.join(units.keys())}")
|
|
118
121
|
|
|
119
|
-
unit_value = units[
|
|
122
|
+
unit_value = units[unit_key]
|
|
120
123
|
|
|
121
124
|
return _to_wei(number, unit_value)
|
|
122
125
|
|
|
123
126
|
|
|
124
|
-
def from_wei_decimals(number: int, decimals: int) ->
|
|
127
|
+
def from_wei_decimals(number: int, decimals: int) -> int | decimal.Decimal:
|
|
125
128
|
"""
|
|
126
129
|
Takes a number of wei and converts it to a decimal with the specified
|
|
127
130
|
number of decimals.
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import sys
|
|
2
|
+
from collections.abc import Callable, Generator, Sequence
|
|
2
3
|
from typing import (
|
|
3
4
|
TYPE_CHECKING,
|
|
4
5
|
Any,
|
|
5
|
-
Callable,
|
|
6
|
-
Dict,
|
|
7
|
-
Generator,
|
|
8
6
|
Optional,
|
|
9
|
-
|
|
10
|
-
Tuple,
|
|
7
|
+
TypeGuard,
|
|
11
8
|
TypeVar,
|
|
12
9
|
Union,
|
|
13
10
|
overload,
|
|
14
11
|
)
|
|
15
|
-
from typing_extensions import TypeGuard
|
|
16
12
|
|
|
17
13
|
from faster_eth_utils import (
|
|
18
14
|
CamelModel,
|
|
@@ -122,11 +118,8 @@ from faster_eth_utils.toolz import (
|
|
|
122
118
|
)
|
|
123
119
|
|
|
124
120
|
if TYPE_CHECKING:
|
|
125
|
-
|
|
126
|
-
from _typeshed import SupportsBool
|
|
121
|
+
from _typeshed import SupportsBool
|
|
127
122
|
# We have to sacrifice a little bit of specificity on dinosaur Python3.8
|
|
128
|
-
else:
|
|
129
|
-
SupportsBool = Any
|
|
130
123
|
|
|
131
124
|
|
|
132
125
|
TArg = TypeVar("TArg")
|
|
@@ -138,44 +131,44 @@ TValue = TypeVar("TValue")
|
|
|
138
131
|
@overload
|
|
139
132
|
def apply_formatter_if(
|
|
140
133
|
condition: Callable[[TArg], TypeGuard[TOther]],
|
|
141
|
-
) -> Callable[[Callable[[TOther], TReturn]], Callable[[TArg],
|
|
134
|
+
) -> Callable[[Callable[[TOther], TReturn]], Callable[[TArg], TReturn | TArg]]:
|
|
142
135
|
...
|
|
143
136
|
|
|
144
137
|
@overload
|
|
145
138
|
def apply_formatter_if(
|
|
146
139
|
condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn]
|
|
147
|
-
) -> Callable[[TArg],
|
|
140
|
+
) -> Callable[[TArg], TReturn | TArg]:
|
|
148
141
|
...
|
|
149
142
|
|
|
150
143
|
@overload
|
|
151
144
|
def apply_formatter_if(
|
|
152
145
|
condition: Callable[[TArg], TypeGuard[TOther]], formatter: Callable[[TOther], TReturn], value: TArg
|
|
153
|
-
) ->
|
|
146
|
+
) -> TReturn | TArg:
|
|
154
147
|
...
|
|
155
148
|
|
|
156
149
|
@overload
|
|
157
150
|
def apply_formatter_if(
|
|
158
151
|
condition: Callable[[TArg], bool], formatter: Callable[[TArg], TReturn], value: TArg
|
|
159
|
-
) ->
|
|
152
|
+
) -> TReturn | TArg:
|
|
160
153
|
...
|
|
161
154
|
|
|
162
155
|
def apply_formatter_if( # type: ignore
|
|
163
|
-
condition:
|
|
164
|
-
formatter:
|
|
165
|
-
value:
|
|
166
|
-
) ->
|
|
167
|
-
Callable[[Callable[[TOther], TReturn]], Callable[[TArg],
|
|
168
|
-
Callable[[TArg],
|
|
169
|
-
TReturn
|
|
170
|
-
TArg
|
|
171
|
-
|
|
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
|
+
):
|
|
172
165
|
pass
|
|
173
166
|
|
|
174
167
|
|
|
175
168
|
@overload
|
|
176
169
|
def apply_one_of_formatters(
|
|
177
170
|
formatter_condition_pairs: Sequence[
|
|
178
|
-
|
|
171
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
179
172
|
],
|
|
180
173
|
) -> Callable[[TArg], TReturn]: ...
|
|
181
174
|
|
|
@@ -183,78 +176,78 @@ def apply_one_of_formatters(
|
|
|
183
176
|
@overload
|
|
184
177
|
def apply_one_of_formatters(
|
|
185
178
|
formatter_condition_pairs: Sequence[
|
|
186
|
-
|
|
179
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
187
180
|
],
|
|
188
181
|
value: TArg,
|
|
189
182
|
) -> TReturn: ...
|
|
190
183
|
|
|
191
184
|
|
|
192
185
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
193
|
-
def apply_one_of_formatters(
|
|
186
|
+
def apply_one_of_formatters( # type: ignore[empty-body]
|
|
194
187
|
formatter_condition_pairs: Sequence[
|
|
195
|
-
|
|
188
|
+
tuple[Callable[[TArg], "SupportsBool"], Callable[[TArg], TReturn]]
|
|
196
189
|
],
|
|
197
|
-
value:
|
|
198
|
-
) -> TReturn: ...
|
|
190
|
+
value: TArg | None = None,
|
|
191
|
+
) -> Callable[[TArg], TReturn] | TReturn: ...
|
|
199
192
|
|
|
200
193
|
|
|
201
194
|
@overload
|
|
202
195
|
def hexstr_if_str(
|
|
203
196
|
to_type: Callable[..., TReturn],
|
|
204
|
-
) -> Callable[[
|
|
197
|
+
) -> Callable[[bytes | int | str], TReturn]: ...
|
|
205
198
|
|
|
206
199
|
|
|
207
200
|
@overload
|
|
208
201
|
def hexstr_if_str(
|
|
209
|
-
to_type: Callable[..., TReturn], to_format:
|
|
202
|
+
to_type: Callable[..., TReturn], to_format: bytes | int | str
|
|
210
203
|
) -> TReturn: ...
|
|
211
204
|
|
|
212
205
|
|
|
213
206
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
214
207
|
def hexstr_if_str( # type: ignore
|
|
215
|
-
to_type: Callable[..., TReturn], to_format:
|
|
208
|
+
to_type: Callable[..., TReturn], to_format: bytes | int | str | None = None
|
|
216
209
|
) -> TReturn: ...
|
|
217
210
|
|
|
218
211
|
|
|
219
212
|
@overload
|
|
220
213
|
def text_if_str(
|
|
221
214
|
to_type: Callable[..., TReturn],
|
|
222
|
-
) -> Callable[[
|
|
215
|
+
) -> Callable[[bytes | int | str], TReturn]: ...
|
|
223
216
|
|
|
224
217
|
|
|
225
218
|
@overload
|
|
226
219
|
def text_if_str(
|
|
227
|
-
to_type: Callable[..., TReturn], text_or_primitive:
|
|
220
|
+
to_type: Callable[..., TReturn], text_or_primitive: bytes | int | str
|
|
228
221
|
) -> TReturn: ...
|
|
229
222
|
|
|
230
223
|
|
|
231
224
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
232
225
|
def text_if_str( # type: ignore
|
|
233
226
|
to_type: Callable[..., TReturn],
|
|
234
|
-
text_or_primitive:
|
|
227
|
+
text_or_primitive: bytes | int | str | None = None,
|
|
235
228
|
) -> TReturn: ...
|
|
236
229
|
|
|
237
230
|
|
|
238
231
|
@overload
|
|
239
232
|
def apply_formatters_to_dict(
|
|
240
|
-
formatters:
|
|
241
|
-
) -> Callable[[
|
|
233
|
+
formatters: dict[Any, Any], unaliased: bool = False
|
|
234
|
+
) -> Callable[[dict[Any, Any] | CamelModel], dict[Any, Any]]:
|
|
242
235
|
...
|
|
243
236
|
|
|
244
237
|
|
|
245
238
|
@overload
|
|
246
239
|
def apply_formatters_to_dict(
|
|
247
|
-
formatters:
|
|
248
|
-
) ->
|
|
240
|
+
formatters: dict[Any, Any], value: dict[Any, Any] | CamelModel, unaliased: bool = False
|
|
241
|
+
) -> dict[Any, Any]:
|
|
249
242
|
...
|
|
250
243
|
|
|
251
244
|
|
|
252
245
|
# This is just a stub to appease mypy, it gets overwritten later
|
|
253
246
|
def apply_formatters_to_dict(
|
|
254
|
-
formatters:
|
|
255
|
-
value:
|
|
247
|
+
formatters: dict[Any, Any],
|
|
248
|
+
value: dict[Any, Any] | CamelModel | None = None,
|
|
256
249
|
unaliased: bool = False,
|
|
257
|
-
) ->
|
|
250
|
+
) -> dict[Any, Any]: ...
|
|
258
251
|
|
|
259
252
|
|
|
260
253
|
apply_formatter_at_index = curry(apply_formatter_at_index)
|
|
@@ -287,13 +280,11 @@ clamp = curry(clamp)
|
|
|
287
280
|
# `from eth_utils.curried import *`
|
|
288
281
|
del Any
|
|
289
282
|
del Callable
|
|
290
|
-
del Dict
|
|
291
283
|
del Generator
|
|
292
284
|
del Optional
|
|
293
285
|
del Sequence
|
|
294
286
|
del TReturn
|
|
295
287
|
del TValue
|
|
296
|
-
del Tuple
|
|
297
288
|
del TypeGuard
|
|
298
289
|
del TypeVar
|
|
299
290
|
del Union
|
|
Binary file
|
|
Binary file
|
faster_eth_utils/decorators.py
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import functools
|
|
2
|
+
from collections.abc import Callable
|
|
2
3
|
from typing import (
|
|
3
4
|
Any,
|
|
4
|
-
|
|
5
|
-
Dict,
|
|
5
|
+
Concatenate,
|
|
6
6
|
Final,
|
|
7
7
|
Generic,
|
|
8
|
-
Optional,
|
|
9
|
-
Tuple,
|
|
10
|
-
Type,
|
|
11
8
|
TypeVar,
|
|
12
|
-
Union,
|
|
13
9
|
final,
|
|
14
10
|
)
|
|
15
11
|
|
|
16
|
-
from typing_extensions import
|
|
12
|
+
from typing_extensions import ParamSpec
|
|
17
13
|
|
|
18
14
|
P = ParamSpec("P")
|
|
19
15
|
|
|
@@ -26,7 +22,7 @@ TInstance = TypeVar("TInstance", bound=object)
|
|
|
26
22
|
@final
|
|
27
23
|
class combomethod(Generic[TInstance, P, T]):
|
|
28
24
|
def __init__(
|
|
29
|
-
self, method: Callable[Concatenate[
|
|
25
|
+
self, method: Callable[Concatenate[TInstance | type[TInstance], P], T]
|
|
30
26
|
) -> None:
|
|
31
27
|
self.method: Final = method
|
|
32
28
|
|
|
@@ -35,22 +31,22 @@ class combomethod(Generic[TInstance, P, T]):
|
|
|
35
31
|
|
|
36
32
|
def __get__(
|
|
37
33
|
self,
|
|
38
|
-
obj:
|
|
39
|
-
objtype:
|
|
34
|
+
obj: TInstance | None,
|
|
35
|
+
objtype: type[TInstance],
|
|
40
36
|
) -> Callable[P, T]:
|
|
41
37
|
|
|
42
|
-
|
|
38
|
+
method = self.method
|
|
39
|
+
bound_arg = objtype if obj is None else obj
|
|
40
|
+
|
|
41
|
+
@functools.wraps(method)
|
|
43
42
|
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
44
|
-
|
|
45
|
-
return self.method(obj, *args, **kwargs)
|
|
46
|
-
else:
|
|
47
|
-
return self.method(objtype, *args, **kwargs) # type: ignore [arg-type]
|
|
43
|
+
return method(bound_arg, *args, **kwargs)
|
|
48
44
|
|
|
49
45
|
return _wrapper
|
|
50
46
|
|
|
51
47
|
|
|
52
48
|
_return_arg_type_deco_cache: Final[
|
|
53
|
-
|
|
49
|
+
dict[int, Callable[[Callable[P, T]], Callable[P, Any]]]
|
|
54
50
|
] = {}
|
|
55
51
|
# No need to hold so many unique instances in memory
|
|
56
52
|
|
|
@@ -76,10 +72,10 @@ def return_arg_type(at_position: int) -> Callable[[Callable[P, T]], Callable[P,
|
|
|
76
72
|
return decorator
|
|
77
73
|
|
|
78
74
|
|
|
79
|
-
ExcType =
|
|
75
|
+
ExcType = type[BaseException]
|
|
80
76
|
|
|
81
|
-
ReplaceExceptionsCache =
|
|
82
|
-
|
|
77
|
+
ReplaceExceptionsCache = dict[
|
|
78
|
+
tuple[tuple[ExcType, ExcType], ...],
|
|
83
79
|
Callable[[Callable[P, T]], Callable[P, T]],
|
|
84
80
|
]
|
|
85
81
|
|
|
@@ -88,7 +84,7 @@ _replace_exceptions_deco_cache: Final[ReplaceExceptionsCache[..., Any]] = {}
|
|
|
88
84
|
|
|
89
85
|
|
|
90
86
|
def replace_exceptions(
|
|
91
|
-
old_to_new_exceptions:
|
|
87
|
+
old_to_new_exceptions: dict[ExcType, ExcType],
|
|
92
88
|
) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
93
89
|
"""
|
|
94
90
|
Replaces old exceptions with new exceptions to be raised in their place.
|
|
Binary file
|
faster_eth_utils/encoding.py
CHANGED
|
Binary file
|
faster_eth_utils/exceptions.py
CHANGED
|
@@ -5,7 +5,7 @@ does not require any change to your existing exception handlers. They will conti
|
|
|
5
5
|
|
|
6
6
|
import eth_utils.exceptions
|
|
7
7
|
|
|
8
|
-
class ValidationError(eth_utils.exceptions.ValidationError):
|
|
8
|
+
class ValidationError(eth_utils.exceptions.ValidationError): # type: ignore[misc]
|
|
9
9
|
"""
|
|
10
10
|
Raised when something does not pass a validation check.
|
|
11
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,22 +4,18 @@ import binascii
|
|
|
4
4
|
import re
|
|
5
5
|
from typing import (
|
|
6
6
|
Any,
|
|
7
|
-
AnyStr,
|
|
8
7
|
Final,
|
|
9
|
-
|
|
8
|
+
TypeGuard,
|
|
10
9
|
)
|
|
11
10
|
|
|
12
11
|
from eth_typing import (
|
|
13
12
|
HexStr,
|
|
14
13
|
)
|
|
15
|
-
from typing_extensions import (
|
|
16
|
-
TypeGuard,
|
|
17
|
-
)
|
|
18
14
|
|
|
19
15
|
_HEX_REGEXP_MATCH: Final = re.compile("(0[xX])?[0-9a-fA-F]*").fullmatch
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
_hexlify: Final = binascii.hexlify
|
|
18
|
+
_unhexlify: Final = binascii.unhexlify
|
|
23
19
|
|
|
24
20
|
|
|
25
21
|
|
|
@@ -29,11 +25,11 @@ def decode_hex(value: str) -> bytes:
|
|
|
29
25
|
non_prefixed = remove_0x_prefix(HexStr(value))
|
|
30
26
|
# unhexlify will only accept bytes type someday
|
|
31
27
|
ascii_hex = non_prefixed.encode("ascii")
|
|
32
|
-
return
|
|
28
|
+
return _unhexlify(ascii_hex)
|
|
33
29
|
|
|
34
30
|
|
|
35
|
-
def encode_hex(value:
|
|
36
|
-
ascii_bytes:
|
|
31
|
+
def encode_hex(value: str | bytes | bytearray) -> HexStr:
|
|
32
|
+
ascii_bytes: bytes | bytearray
|
|
37
33
|
if isinstance(value, (bytes, bytearray)):
|
|
38
34
|
ascii_bytes = value
|
|
39
35
|
elif isinstance(value, str):
|
|
@@ -41,7 +37,7 @@ def encode_hex(value: AnyStr) -> HexStr:
|
|
|
41
37
|
else:
|
|
42
38
|
raise TypeError("Value must be an instance of str or unicode")
|
|
43
39
|
|
|
44
|
-
binary_hex =
|
|
40
|
+
binary_hex = _hexlify(ascii_bytes)
|
|
45
41
|
return add_0x_prefix(HexStr(binary_hex.decode("ascii")))
|
|
46
42
|
|
|
47
43
|
|
|
@@ -51,7 +47,7 @@ def is_0x_prefixed(value: str) -> bool:
|
|
|
51
47
|
# raise TypeError(
|
|
52
48
|
# f"is_0x_prefixed requires text typed arguments. Got: {repr(value)}"
|
|
53
49
|
# )
|
|
54
|
-
return value.startswith(
|
|
50
|
+
return value.startswith("0x") or value.startswith("0X")
|
|
55
51
|
|
|
56
52
|
|
|
57
53
|
def remove_0x_prefix(value: HexStr) -> HexStr:
|
|
Binary file
|
faster_eth_utils/humanize.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
from collections.abc import (
|
|
2
|
+
Iterable,
|
|
3
|
+
Iterator,
|
|
4
|
+
)
|
|
1
5
|
from typing import (
|
|
2
6
|
Any,
|
|
3
7
|
Final,
|
|
4
|
-
Iterable,
|
|
5
|
-
Iterator,
|
|
6
|
-
Tuple,
|
|
7
|
-
Union,
|
|
8
8
|
)
|
|
9
9
|
from urllib import (
|
|
10
10
|
parse,
|
|
@@ -23,13 +23,14 @@ from faster_eth_utils.currency import (
|
|
|
23
23
|
from . import toolz
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
def humanize_seconds(seconds:
|
|
27
|
-
|
|
26
|
+
def humanize_seconds(seconds: float | int) -> str:
|
|
27
|
+
seconds_int = int(seconds)
|
|
28
|
+
if seconds_int == 0:
|
|
28
29
|
return "0s"
|
|
29
30
|
|
|
30
|
-
unit_values = _consume_leading_zero_units(_humanize_seconds(
|
|
31
|
+
unit_values = _consume_leading_zero_units(_humanize_seconds(seconds_int))
|
|
31
32
|
|
|
32
|
-
return "".join(
|
|
33
|
+
return "".join(f"{amount}{unit}" for amount, unit in toolz.take(3, unit_values))
|
|
33
34
|
|
|
34
35
|
|
|
35
36
|
SECOND: Final = 1
|
|
@@ -53,8 +54,8 @@ UNITS: Final = (
|
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
def _consume_leading_zero_units(
|
|
56
|
-
units_iter: Iterator[
|
|
57
|
-
) -> Iterator[
|
|
57
|
+
units_iter: Iterator[tuple[int, str]]
|
|
58
|
+
) -> Iterator[tuple[int, str]]:
|
|
58
59
|
for amount, unit in units_iter:
|
|
59
60
|
if amount == 0:
|
|
60
61
|
continue
|
|
@@ -65,7 +66,7 @@ def _consume_leading_zero_units(
|
|
|
65
66
|
yield from units_iter
|
|
66
67
|
|
|
67
68
|
|
|
68
|
-
def _humanize_seconds(seconds: int) -> Iterator[
|
|
69
|
+
def _humanize_seconds(seconds: int) -> Iterator[tuple[int, str]]:
|
|
69
70
|
remainder = seconds
|
|
70
71
|
|
|
71
72
|
for duration, unit in UNITS:
|
|
@@ -140,7 +141,7 @@ def _is_CIDv0_ipfs_hash(ipfs_hash: str) -> bool:
|
|
|
140
141
|
return False
|
|
141
142
|
|
|
142
143
|
|
|
143
|
-
def _find_breakpoints(values:
|
|
144
|
+
def _find_breakpoints(values: tuple[int, ...]) -> Iterator[int]:
|
|
144
145
|
yield 0
|
|
145
146
|
for index, (left, right) in enumerate(toolz.sliding_window(2, values), 1):
|
|
146
147
|
if left + 1 == right:
|
|
@@ -150,7 +151,7 @@ def _find_breakpoints(values: Tuple[int, ...]) -> Iterator[int]:
|
|
|
150
151
|
yield len(values)
|
|
151
152
|
|
|
152
153
|
|
|
153
|
-
def _extract_integer_ranges(values:
|
|
154
|
+
def _extract_integer_ranges(values: tuple[int, ...]) -> Iterator[tuple[int, int]]:
|
|
154
155
|
"""
|
|
155
156
|
Return a tuple of consecutive ranges of integers.
|
|
156
157
|
|
|
@@ -165,7 +166,7 @@ def _extract_integer_ranges(values: Tuple[int, ...]) -> Iterator[Tuple[int, int]
|
|
|
165
166
|
yield chunk[0], chunk[-1]
|
|
166
167
|
|
|
167
168
|
|
|
168
|
-
def _humanize_range(bounds:
|
|
169
|
+
def _humanize_range(bounds: tuple[int, int]) -> str:
|
|
169
170
|
left, right = bounds
|
|
170
171
|
if left == right:
|
|
171
172
|
return str(left)
|
|
@@ -197,5 +198,4 @@ def humanize_wei(number: int) -> str:
|
|
|
197
198
|
else:
|
|
198
199
|
unit = "wei"
|
|
199
200
|
amount = from_wei(number, unit)
|
|
200
|
-
|
|
201
|
-
return x
|
|
201
|
+
return f"{str(amount)} {unit}"
|