faster-hexbytes 1.3.2__cp310-cp310-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.
Binary file
@@ -0,0 +1,11 @@
1
+ from importlib.metadata import (
2
+ version as __version,
3
+ )
4
+
5
+ from faster_hexbytes.main import (
6
+ HexBytes,
7
+ )
8
+
9
+ __all__ = ["HexBytes"]
10
+
11
+ __version__ = __version("hexbytes")
Binary file
@@ -0,0 +1,58 @@
1
+ import binascii
2
+ from typing import (
3
+ Final,
4
+ Union,
5
+ )
6
+
7
+
8
+ unhexlify: Final = binascii.unhexlify
9
+
10
+
11
+ def to_bytes(val: Union[bytes, str, bytearray, bool, int, memoryview]) -> bytes:
12
+ """
13
+ Equivalent to: `faster_eth_utils.hexstr_if_str(faster_eth_utils.to_bytes, val)` .
14
+
15
+ Convert a hex string, integer, or bool, to a bytes representation.
16
+ Alternatively, pass through bytes or bytearray as a bytes value.
17
+ """
18
+ if isinstance(val, bytes):
19
+ return val
20
+ elif isinstance(val, str):
21
+ return hexstr_to_bytes(val)
22
+ elif isinstance(val, bytearray):
23
+ return bytes(val)
24
+ elif isinstance(val, bool):
25
+ return b"\x01" if val else b"\x00"
26
+ elif isinstance(val, int):
27
+ # Note that this int check must come after the bool check, because
28
+ # isinstance(True, int) is True
29
+ if val < 0:
30
+ raise ValueError(f"Cannot convert negative integer {val} to bytes")
31
+ else:
32
+ return to_bytes(hex(val))
33
+ elif isinstance(val, memoryview):
34
+ return bytes(val)
35
+ else:
36
+ raise TypeError(f"Cannot convert {val!r} of type {type(val)} to bytes")
37
+
38
+
39
+ def hexstr_to_bytes(hexstr: str) -> bytes:
40
+ if hexstr.startswith(("0x", "0X")):
41
+ non_prefixed_hex = hexstr[2:]
42
+ else:
43
+ non_prefixed_hex = hexstr
44
+
45
+ # if the hex string is odd-length, then left-pad it to an even length
46
+ if len(hexstr) % 2:
47
+ padded_hex = "0" + non_prefixed_hex
48
+ else:
49
+ padded_hex = non_prefixed_hex
50
+
51
+ try:
52
+ ascii_hex = padded_hex.encode("ascii")
53
+ except UnicodeDecodeError:
54
+ raise ValueError(
55
+ f"hex string {padded_hex} may only contain [0-9a-fA-F] characters"
56
+ )
57
+ else:
58
+ return unhexlify(ascii_hex)
Binary file
@@ -0,0 +1,101 @@
1
+ from typing import (
2
+ TYPE_CHECKING,
3
+ Callable,
4
+ Final,
5
+ Tuple,
6
+ Type,
7
+ Union,
8
+ overload,
9
+ )
10
+
11
+ # accessing hexbytes.HexBytes after `import hexbytes`
12
+ # fails because mypyc tries to lookup HexBytes from
13
+ # CPyModule_hexbytes___main which was never imported
14
+ import hexbytes.main as hexbytes
15
+ from mypy_extensions import (
16
+ mypyc_attr,
17
+ )
18
+ from typing_extensions import (
19
+ Self,
20
+ )
21
+
22
+ from faster_hexbytes._utils import (
23
+ to_bytes,
24
+ )
25
+
26
+ if TYPE_CHECKING:
27
+ from typing import (
28
+ SupportsIndex,
29
+ )
30
+
31
+
32
+ BytesLike = Union[bytes, str, bool, bytearray, int, memoryview]
33
+
34
+ _bytes_new: Final = bytes.__new__
35
+
36
+
37
+ @mypyc_attr(native_class=False, allow_interpreted_subclasses=True)
38
+ class HexBytes(hexbytes.HexBytes):
39
+ """
40
+ Thin wrapper around the python built-in :class:`bytes` class.
41
+
42
+ It has these changes:
43
+ 1. Accepts more initializing values: bool, bytearray, bytes, (non-negative) int,
44
+ str, and memoryview
45
+ 2. The representation at console (__repr__) is 0x-prefixed
46
+ 3. ``to_0x_hex`` returns a 0x-prefixed hex string
47
+ """
48
+
49
+ def __new__(cls, val: BytesLike) -> Self:
50
+ bytesval = to_bytes(val)
51
+ return _bytes_new(cls, bytesval)
52
+
53
+ @overload
54
+ def __getitem__(self, key: "SupportsIndex") -> int: # noqa: F811
55
+ ...
56
+
57
+ @overload # noqa: F811
58
+ def __getitem__(self, key: slice) -> Self: # noqa: F811
59
+ ...
60
+
61
+ def __getitem__( # noqa: F811
62
+ self, key: Union["SupportsIndex", slice]
63
+ ) -> Union[int, Self]:
64
+ result = bytes.__getitem__(self, key)
65
+ if isinstance(result, int):
66
+ return result
67
+ cls = type(self)
68
+ if cls is HexBytes:
69
+ # fast-path case with faster C code for non-subclass
70
+ return HexBytes(result) # type: ignore [return-value]
71
+ return cls(result)
72
+
73
+ def __repr__(self) -> str:
74
+ return f"HexBytes('0x{self.hex()}')"
75
+
76
+ def to_0x_hex(self) -> str:
77
+ """
78
+ Convert the bytes to a 0x-prefixed hex string
79
+ """
80
+ return f"0x{self.hex()}"
81
+
82
+ def __reduce__(
83
+ self,
84
+ ) -> Tuple[Callable[..., bytes], Tuple[Type["HexBytes"], bytes]]:
85
+ """
86
+ An optimized ``__reduce__`` that bypasses the input validation in
87
+ ``HexBytes.__new__`` since an existing HexBytes instance has already been
88
+ validated when created.
89
+ """
90
+ return _bytes_new, (type(self), bytes(self))
91
+
92
+
93
+ # these 3 helpers serve as a workaround for a mypyc bug until
94
+ # https://github.com/python/mypy/pull/19957 is merged and released
95
+
96
+ @mypyc_attr(native_class=False)
97
+ class _HexBytesSubclass1(HexBytes): ...
98
+ @mypyc_attr(native_class=False)
99
+ class _HexBytesSubclass2(HexBytes): ...
100
+ @mypyc_attr(native_class=False)
101
+ class _HexBytesSubclass3(HexBytes): ...
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: faster_hexbytes
3
+ Version: 1.3.2
4
+ Summary: A faster fork of hexbytes: Python `bytes` subclass that decodes hex, with a readable console output. Implemented in C.
5
+ Home-page: https://github.com/ethereum/hexbytes
6
+ Author: The Ethereum Foundation
7
+ Author-email: snakecharmers@ethereum.org
8
+ License: MIT
9
+ Keywords: ethereum
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Requires-Python: >=3.9, <4
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: hexbytes==1.3.1
26
+ Requires-Dist: mypy_extensions
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=0.9.0; extra == "dev"
29
+ Requires-Dist: bump_my_version>=0.19.0; extra == "dev"
30
+ Requires-Dist: ipython; extra == "dev"
31
+ Requires-Dist: mypy==1.10.0; extra == "dev"
32
+ Requires-Dist: pre-commit>=3.4.0; extra == "dev"
33
+ Requires-Dist: tox>=4.0.0; extra == "dev"
34
+ Requires-Dist: twine; extra == "dev"
35
+ Requires-Dist: wheel; extra == "dev"
36
+ Requires-Dist: sphinx>=6.0.0; extra == "dev"
37
+ Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "dev"
38
+ Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "dev"
39
+ Requires-Dist: towncrier<25,>=24; extra == "dev"
40
+ Requires-Dist: eth_utils>=2.0.0; extra == "dev"
41
+ Requires-Dist: hypothesis>=3.44.24; extra == "dev"
42
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
43
+ Requires-Dist: pytest-xdist>=2.4.0; extra == "dev"
44
+ Provides-Extra: docs
45
+ Requires-Dist: sphinx>=6.0.0; extra == "docs"
46
+ Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "docs"
47
+ Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "docs"
48
+ Requires-Dist: towncrier<25,>=24; extra == "docs"
49
+ Provides-Extra: test
50
+ Requires-Dist: eth_utils>=2.0.0; extra == "test"
51
+ Requires-Dist: hypothesis>=3.44.24; extra == "test"
52
+ Requires-Dist: pytest>=7.0.0; extra == "test"
53
+ Requires-Dist: pytest-xdist>=2.4.0; extra == "test"
54
+ Dynamic: author
55
+ Dynamic: author-email
56
+ Dynamic: classifier
57
+ Dynamic: description
58
+ Dynamic: description-content-type
59
+ Dynamic: home-page
60
+ Dynamic: keywords
61
+ Dynamic: license
62
+ Dynamic: license-file
63
+ Dynamic: provides-extra
64
+ Dynamic: requires-dist
65
+ Dynamic: requires-python
66
+ Dynamic: summary
67
+
68
+ # HexBytes
69
+
70
+ [![Join the conversation on Discord](https://img.shields.io/discord/809793915578089484?color=blue&label=chat&logo=discord&logoColor=white)](https://discord.gg/GHryRvPB84)
71
+ [![Build Status](https://circleci.com/gh/ethereum/hexbytes.svg?style=shield)](https://circleci.com/gh/ethereum/hexbytes)
72
+ [![PyPI version](https://badge.fury.io/py/hexbytes.svg)](https://badge.fury.io/py/hexbytes)
73
+ [![Python versions](https://img.shields.io/pypi/pyversions/hexbytes.svg)](https://pypi.python.org/pypi/hexbytes)
74
+ [![Docs build](https://readthedocs.org/projects/hexbytes/badge/?version=latest)](https://hexbytes.readthedocs.io/en/latest/?badge=latest)
75
+
76
+ Python `bytes` subclass that decodes hex, with a readable console output
77
+
78
+ Read the [documentation](https://hexbytes.readthedocs.io/).
79
+
80
+ View the [change log](https://hexbytes.readthedocs.io/en/latest/release_notes.html).
81
+
82
+ ## Installation
83
+
84
+ ```sh
85
+ python -m pip install hexbytes
86
+ ```
@@ -0,0 +1,13 @@
1
+ 6a32f4913d613d6a7ddf__mypyc.cp310-win32.pyd,sha256=IQdiV3G25t7B9_xx0hU__KU1l06eNvWR2G3eetPY4ow,46592
2
+ faster_hexbytes/__init__.cp310-win32.pyd,sha256=8QpthQnrHVxd4wjS1DnvYPZRVelWdcSMx7j1580SSls,9216
3
+ faster_hexbytes/__init__.py,sha256=ydnGcx4ny2H1UjCnkxW0qn0u0G0Yo8pERQuZOKxbfP0,185
4
+ faster_hexbytes/_utils.cp310-win32.pyd,sha256=DPXvVylNJnOTfe9ZEn7jzBMCLS9p9R98ToV4IolUewo,9216
5
+ faster_hexbytes/_utils.py,sha256=3Zp_hNNM_uyVVwJGfKs3dzeKryGEs_pjjOWi6KzqrcM,1801
6
+ faster_hexbytes/main.cp310-win32.pyd,sha256=JhO3AIzBFFihps5GCfs1xS1RW-pXfU32MVIPqDZ03a8,9216
7
+ faster_hexbytes/main.py,sha256=kxGxXjm8gDpX3F3xs_F-qixqhkxdo3TENGHoYfALHTw,2876
8
+ faster_hexbytes/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
9
+ faster_hexbytes-1.3.2.dist-info/licenses/LICENSE,sha256=0yDgluyUXL4Wtez0QidbRbAJ8gPmBCH_PVss1vyL_Q4,1116
10
+ faster_hexbytes-1.3.2.dist-info/METADATA,sha256=7JImJ0mkenTtVVLlYXZz8qTBV-rqdlyXbgOcE3jaSJ8,3600
11
+ faster_hexbytes-1.3.2.dist-info/WHEEL,sha256=GWZF0cboiU4MhsG0baPl8rrtCaXFSLW25384gp3vddM,97
12
+ faster_hexbytes-1.3.2.dist-info/top_level.txt,sha256=xJbUGq2PZqSSdlvVDwPydJ9IkMtDVoLg-DVy83iOh58,44
13
+ faster_hexbytes-1.3.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-win32
5
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-2025 The Ethereum Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ 6a32f4913d613d6a7ddf__mypyc
2
+ faster_hexbytes