faster-hexbytes 1.3.9__cp315-cp315t-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.
@@ -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,61 @@
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 val.to_bytes(max(1, (val.bit_length() + 7) // 8), "big")
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") or hexstr.startswith("0X"):
41
+ non_prefixed_hex = hexstr[2:]
42
+ else:
43
+ non_prefixed_hex = hexstr
44
+
45
+ if not non_prefixed_hex:
46
+ return b""
47
+
48
+ # if the hex string is odd-length, then left-pad it to an even length
49
+ if len(non_prefixed_hex) & 1:
50
+ padded_hex = "0" + non_prefixed_hex
51
+ else:
52
+ padded_hex = non_prefixed_hex
53
+
54
+ try:
55
+ ascii_hex = padded_hex.encode("ascii")
56
+ except UnicodeDecodeError:
57
+ raise ValueError(
58
+ f"hex string {padded_hex} may only contain [0-9a-fA-F] characters"
59
+ )
60
+ else:
61
+ return unhexlify(ascii_hex)
Binary file
@@ -0,0 +1,110 @@
1
+ from typing import (
2
+ TYPE_CHECKING,
3
+ Callable,
4
+ Final,
5
+ Union,
6
+ cast,
7
+ overload,
8
+ )
9
+
10
+ # accessing hexbytes.HexBytes after `import hexbytes`
11
+ # fails because mypyc tries to lookup HexBytes from
12
+ # CPyModule_hexbytes___main which was never imported
13
+ import hexbytes.main as hexbytes
14
+ from mypy_extensions import (
15
+ mypyc_attr,
16
+ )
17
+ from typing_extensions import (
18
+ Self,
19
+ )
20
+
21
+ from faster_hexbytes._utils import (
22
+ to_bytes,
23
+ )
24
+
25
+ if TYPE_CHECKING:
26
+ from typing import (
27
+ SupportsIndex,
28
+ )
29
+
30
+
31
+ BytesLike = Union[bytes, str, bool, bytearray, int, memoryview]
32
+
33
+ _bytes_new: Final = bytes.__new__
34
+
35
+
36
+ @mypyc_attr(native_class=False, acyclic=True, allow_interpreted_subclasses=True)
37
+ class HexBytes(hexbytes.HexBytes):
38
+ """
39
+ Thin wrapper around the python built-in :class:`bytes` class.
40
+
41
+ It has these changes:
42
+ 1. Accepts more initializing values: bool, bytearray, bytes, (non-negative) int,
43
+ str, and memoryview
44
+ 2. The representation at console (__repr__) is 0x-prefixed
45
+ 3. ``to_0x_hex`` returns a 0x-prefixed hex string
46
+ """
47
+
48
+ def __new__(cls, val: BytesLike) -> Self:
49
+ if type(val) is cls:
50
+ # These are immutable, just return it
51
+ return val
52
+ elif isinstance(val, bytes):
53
+ # These don't require `to_bytes`
54
+ return _bytes_new(cls, val)
55
+ bytesval = to_bytes(val)
56
+ return _bytes_new(cls, bytesval)
57
+
58
+ @overload
59
+ def __getitem__(self, key: "SupportsIndex") -> int: # noqa: F811
60
+ ...
61
+
62
+ @overload # noqa: F811
63
+ def __getitem__(self, key: slice) -> Self: # noqa: F811
64
+ ...
65
+
66
+ def __getitem__( # noqa: F811
67
+ self, key: Union["SupportsIndex", slice]
68
+ ) -> Union[int, Self]:
69
+ result = bytes.__getitem__(self, key)
70
+ if isinstance(result, int):
71
+ return result
72
+ cls = type(self)
73
+ if cls is HexBytes:
74
+ # fast-path case with faster C code for non-subclass
75
+ if isinstance(key, slice):
76
+ # fast-path case to skip __init__
77
+ return cast(Self, _bytes_new(HexBytes, result))
78
+ else:
79
+ return cast(Self, HexBytes(result))
80
+ return cls(result)
81
+
82
+ def __repr__(self) -> str:
83
+ return f"HexBytes('0x{self.hex()}')"
84
+
85
+ def to_0x_hex(self) -> str:
86
+ """
87
+ Convert the bytes to a 0x-prefixed hex string
88
+ """
89
+ return f"0x{self.hex()}"
90
+
91
+ def __reduce__(
92
+ self,
93
+ ) -> tuple[Callable[..., bytes], tuple[type["HexBytes"], bytes]]:
94
+ """
95
+ An optimized ``__reduce__`` that bypasses the input validation in
96
+ ``HexBytes.__new__`` since an existing HexBytes instance has already been
97
+ validated when created.
98
+ """
99
+ return _bytes_new, (type(self), bytes(self))
100
+
101
+
102
+ # these 3 helpers serve as a workaround for a mypyc bug until
103
+ # https://github.com/python/mypy/pull/19957 is merged and released
104
+
105
+ @mypyc_attr(native_class=False)
106
+ class _HexBytesSubclass1(HexBytes): ...
107
+ @mypyc_attr(native_class=False)
108
+ class _HexBytesSubclass2(HexBytes): ...
109
+ @mypyc_attr(native_class=False)
110
+ class _HexBytesSubclass3(HexBytes): ...
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: faster_hexbytes
3
+ Version: 1.3.9
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/BobTheBuidler/faster-hexbytes
6
+ Author: The Ethereum Foundation
7
+ Author-email: snakecharmers@ethereum.org
8
+ License: MIT
9
+ Project-URL: Documentation, https://hexbytes.readthedocs.io/en/stable/
10
+ Project-URL: Release Notes, https://github.com/BobTheBuidler/faster-hexbytes/releases
11
+ Project-URL: Issues, https://github.com/BobTheBuidler/faster-hexbytes/issues
12
+ Project-URL: Source - Precompiled (.py), https://github.com/BobTheBuidler/faster-hexbytes/tree/master/faster_eth_utils
13
+ Project-URL: Source - Compiled (.c), https://github.com/BobTheBuidler/faster-hexbytes/tree/master/build
14
+ Project-URL: Benchmarks, https://github.com/BobTheBuidler/faster-hexbytes/tree/master/benchmarks
15
+ Project-URL: Benchmarks - Results, https://github.com/BobTheBuidler/faster-hexbytes/tree/master/benchmarks/results
16
+ Project-URL: Original, https://github.com/ethereum/hexbytes
17
+ Keywords: ethereum
18
+ Classifier: Development Status :: 5 - Production/Stable
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: License :: OSI Approved :: MIT License
21
+ Classifier: Natural Language :: English
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Python :: 3.14
28
+ Classifier: Programming Language :: Python :: 3.15
29
+ Requires-Python: >=3.10, <4
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: hexbytes==1.3.1
33
+ Requires-Dist: mypy_extensions<2,>=0.4.2
34
+ Requires-Dist: typing-extensions<5,>=4.0.0
35
+ Provides-Extra: dev
36
+ Requires-Dist: build>=0.9.0; extra == "dev"
37
+ Requires-Dist: bump_my_version>=0.19.0; extra == "dev"
38
+ Requires-Dist: ipython; extra == "dev"
39
+ Requires-Dist: mypy==2.4.0; extra == "dev"
40
+ Requires-Dist: pre-commit>=3.4.0; extra == "dev"
41
+ Requires-Dist: tox>=4.0.0; extra == "dev"
42
+ Requires-Dist: twine; extra == "dev"
43
+ Requires-Dist: wheel; extra == "dev"
44
+ Requires-Dist: sphinx>=6.0.0; extra == "dev"
45
+ Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "dev"
46
+ Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "dev"
47
+ Requires-Dist: towncrier<26,>=25; extra == "dev"
48
+ Requires-Dist: eth_utils>=2.0.0; extra == "dev"
49
+ Requires-Dist: hypothesis>=3.44.24; extra == "dev"
50
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
51
+ Requires-Dist: pytest-xdist>=2.4.0; extra == "dev"
52
+ Provides-Extra: docs
53
+ Requires-Dist: sphinx>=6.0.0; extra == "docs"
54
+ Requires-Dist: sphinx-autobuild>=2021.3.14; extra == "docs"
55
+ Requires-Dist: sphinx_rtd_theme>=1.0.0; extra == "docs"
56
+ Requires-Dist: towncrier<26,>=25; extra == "docs"
57
+ Provides-Extra: test
58
+ Requires-Dist: eth_utils>=2.0.0; extra == "test"
59
+ Requires-Dist: hypothesis>=3.44.24; extra == "test"
60
+ Requires-Dist: pytest>=7.0.0; extra == "test"
61
+ Requires-Dist: pytest-xdist>=2.4.0; extra == "test"
62
+ Provides-Extra: benchmark
63
+ Requires-Dist: pytest-benchmark; extra == "benchmark"
64
+ Requires-Dist: pytest-codspeed<5.1,>=5; extra == "benchmark"
65
+ Requires-Dist: eth-typing; extra == "benchmark"
66
+ Provides-Extra: codspeed
67
+ Requires-Dist: pytest-codspeed<5.1,>=5; extra == "codspeed"
68
+ Requires-Dist: eth-typing; extra == "codspeed"
69
+ Dynamic: author
70
+ Dynamic: author-email
71
+ Dynamic: classifier
72
+ Dynamic: description
73
+ Dynamic: description-content-type
74
+ Dynamic: home-page
75
+ Dynamic: keywords
76
+ Dynamic: license
77
+ Dynamic: license-file
78
+ Dynamic: project-url
79
+ Dynamic: provides-extra
80
+ Dynamic: requires-dist
81
+ Dynamic: requires-python
82
+ Dynamic: summary
83
+
84
+ ### I forked hexbytes and compiled it to C. It does the same stuff, now faster
85
+
86
+ [![PyPI](https://img.shields.io/pypi/v/faster-hexbytes.svg?logo=Python&logoColor=white)](https://pypi.org/project/faster-hexbytes/)
87
+ [![Monthly Downloads](https://img.shields.io/pypi/dm/faster-hexbytes)](https://pypistats.org/packages/faster-hexbytes)
88
+ [![Codspeed.io Status](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/BobTheBuidler/faster-hexbytes)
89
+
90
+ ##### This fork will be kept up-to-date with [hexbytes](https://github.com/ethereum/hexbytes). I will pull updates as they are released and push new [faster-hexbytes](https://github.com/BobTheBuidler/faster-hexbytes) releases to [PyPI](https://pypi.org/project/faster-hexbytes/).
91
+
92
+ ##### `faster_hexbytes.HexBytes` inherits from `hexbytes.HexBytes`, so porting to `faster-hexbytes` does not require you to update any `isinstance` or `issubclass` checks. All such checks in your codebase, and in any dependencies, will continue to work as they did when originaly implemented.
93
+
94
+ ##### We benchmark `faster-hexbytes` against the original `hexbytes` for your convenience. [See results](https://github.com/BobTheBuidler/faster-hexbytes/tree/master/benchmarks/results).
95
+
96
+ ##### You can find the compiled C code and header files in the [build](https://github.com/BobTheBuidler/hexbytes/tree/master/build) directory.
97
+
98
+ ###### You may also be interested in: [faster-web3.py](https://github.com/BobTheBuidler/faster-hexbytes/), [faster-eth-abi](https://github.com/BobTheBuidler/faster-eth-abi/), and [faster-eth-utils](https://github.com/BobTheBuidler/faster-eth-utils/)
99
+
100
+ ##### The original hexbytes readme is below:
101
+
102
+ # HexBytes
103
+
104
+ [![Join the conversation on Discord](https://img.shields.io/discord/809793915578089484?color=blue&label=chat&logo=discord&logoColor=white)](https://discord.gg/GHryRvPB84)
105
+ [![Build Status](https://circleci.com/gh/ethereum/hexbytes.svg?style=shield)](https://circleci.com/gh/ethereum/hexbytes)
106
+ [![PyPI version](https://badge.fury.io/py/hexbytes.svg)](https://badge.fury.io/py/hexbytes)
107
+ [![Python versions](https://img.shields.io/pypi/pyversions/hexbytes.svg)](https://pypi.python.org/pypi/hexbytes)
108
+ [![Docs build](https://readthedocs.org/projects/hexbytes/badge/?version=latest)](https://hexbytes.readthedocs.io/en/latest/?badge=latest)
109
+
110
+ Python `bytes` subclass that decodes hex, with a readable console output
111
+
112
+ Read the [documentation](https://hexbytes.readthedocs.io/).
113
+
114
+ View the [change log](https://hexbytes.readthedocs.io/en/latest/release_notes.html).
115
+
116
+ ## Installation
117
+
118
+ ```sh
119
+ python -m pip install hexbytes
120
+ ```
@@ -0,0 +1,13 @@
1
+ faster_hexbytes__mypyc.cp315t-win32.pyd,sha256=ZZYdm91EYprikSCSNGpcsDDNf2Xp744gg2OHbTewYIw,65536
2
+ faster_hexbytes/__init__.cp315t-win32.pyd,sha256=WBA7_6XxQ1lWYv262T4pifisL4rg3gkekvjykbEkhIw,9216
3
+ faster_hexbytes/__init__.py,sha256=ydnGcx4ny2H1UjCnkxW0qn0u0G0Yo8pERQuZOKxbfP0,185
4
+ faster_hexbytes/_utils.cp315t-win32.pyd,sha256=oLSu4lOYiBwbd5nmvQD18xh5sot9Hd4U2BB2vlVq16A,9216
5
+ faster_hexbytes/_utils.py,sha256=oA4KjZm3tuQFLJa77bHxgeC4kBOmCxBAXoWEL-Iy_Xk,1920
6
+ faster_hexbytes/main.cp315t-win32.pyd,sha256=SCJHc_y_QNqXyE4k_aLNOYjWgT9RdFtqC9aMlKPKmSM,9216
7
+ faster_hexbytes/main.py,sha256=AIxRjEktbwuTBTW095kG8wedLpuEMCbeQhqsZ4i8JIM,3268
8
+ faster_hexbytes/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
9
+ faster_hexbytes-1.3.9.dist-info/licenses/LICENSE,sha256=0yDgluyUXL4Wtez0QidbRbAJ8gPmBCH_PVss1vyL_Q4,1116
10
+ faster_hexbytes-1.3.9.dist-info/METADATA,sha256=6hnVgAj8f8uXytS4kwhAPNJS57j_7sLzZ3pWhQzKCb8,6400
11
+ faster_hexbytes-1.3.9.dist-info/WHEEL,sha256=HqmQhCfAfmCuuvIb9V-PliyMZZwXDVLHiA5aIbnMmQM,98
12
+ faster_hexbytes-1.3.9.dist-info/top_level.txt,sha256=JLqPzpL8j6tDI0rkOzaXmast5SdH4RkTfvLXdTHaZCs,39
13
+ faster_hexbytes-1.3.9.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp315-cp315t-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
+ faster_hexbytes
2
+ faster_hexbytes__mypyc
Binary file