cchecksum 0.0.11__tar.gz → 0.0.13__tar.gz

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 cchecksum might be problematic. Click here for more details.

Files changed (44) hide show
  1. {cchecksum-0.0.11 → cchecksum-0.0.13}/.github/workflows/pytest.yaml +1 -1
  2. {cchecksum-0.0.11 → cchecksum-0.0.13}/PKG-INFO +2 -2
  3. cchecksum-0.0.13/README.md +9 -0
  4. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/_checksum.c +8 -8
  5. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/_checksum.pyx +3 -4
  6. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/checksum.py +21 -20
  7. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum.egg-info/PKG-INFO +2 -2
  8. {cchecksum-0.0.11 → cchecksum-0.0.13}/setup.py +1 -1
  9. cchecksum-0.0.11/README.md +0 -7
  10. {cchecksum-0.0.11 → cchecksum-0.0.13}/.github/workflows/black.yaml +0 -0
  11. {cchecksum-0.0.11 → cchecksum-0.0.13}/.github/workflows/deploy-docs.yaml +0 -0
  12. {cchecksum-0.0.11 → cchecksum-0.0.13}/.github/workflows/release.yaml +0 -0
  13. {cchecksum-0.0.11 → cchecksum-0.0.13}/.gitignore +0 -0
  14. {cchecksum-0.0.11 → cchecksum-0.0.13}/LICENSE +0 -0
  15. {cchecksum-0.0.11 → cchecksum-0.0.13}/Makefile +0 -0
  16. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/__init__.py +0 -0
  17. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/_checksum.pyi +0 -0
  18. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/checksum.pyi +0 -0
  19. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum/py.typed +0 -0
  20. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum.egg-info/SOURCES.txt +0 -0
  21. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum.egg-info/dependency_links.txt +0 -0
  22. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum.egg-info/not-zip-safe +0 -0
  23. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum.egg-info/requires.txt +0 -0
  24. {cchecksum-0.0.11 → cchecksum-0.0.13}/cchecksum.egg-info/top_level.txt +0 -0
  25. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/Makefile +0 -0
  26. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/alabaster.css +0 -0
  27. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/basic.css +0 -0
  28. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/custom.css +0 -0
  29. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/doctools.js +0 -0
  30. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/documentation_options.js +0 -0
  31. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/file.png +0 -0
  32. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/language_data.js +0 -0
  33. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/minus.png +0 -0
  34. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/plus.png +0 -0
  35. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/pygments.css +0 -0
  36. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/searchtools.js +0 -0
  37. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/_build/html/_static/sphinx_highlight.js +0 -0
  38. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/conf.py +0 -0
  39. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/index.rst +0 -0
  40. {cchecksum-0.0.11 → cchecksum-0.0.13}/docs/make.bat +0 -0
  41. {cchecksum-0.0.11 → cchecksum-0.0.13}/pyproject.toml +0 -0
  42. {cchecksum-0.0.11 → cchecksum-0.0.13}/requirements.txt +0 -0
  43. {cchecksum-0.0.11 → cchecksum-0.0.13}/setup.cfg +0 -0
  44. {cchecksum-0.0.11 → cchecksum-0.0.13}/test_checksum.py +0 -0
@@ -48,4 +48,4 @@ jobs:
48
48
  pip install -e .
49
49
 
50
50
  - name: Run test suite
51
- run: pytest
51
+ run: pytest -s -v
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cchecksum
3
- Version: 0.0.11
4
- Summary: A ~2x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
3
+ Version: 0.0.13
4
+ Summary: A ~4.5x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
5
5
  Home-page: https://github.com/BobTheBuidler/cchecksum
6
6
  Author: BobTheBuidler
7
7
  Author-email: bobthebuidlerdefi@gmail.com
@@ -0,0 +1,9 @@
1
+ ## CChecksum
2
+
3
+ CChecksum is a ~4.5x faster drop-in replacement for eth_utils.to_checksum_address, with the most cpu-intensive part implemented in c.
4
+
5
+ It keeps the exact same API as the existing implementation, exceptions and all.
6
+
7
+ Just `pip install cchecksum`, drop it in, and run your script with a substantial speed improvement.
8
+
9
+ ![image](https://github.com/user-attachments/assets/f2732c1f-f36e-486c-9258-cdeb09bb5eb5)
@@ -3148,7 +3148,7 @@ static const char __pyx_k_Step_may_not_be_zero_axis_d[] = "Step may not be zero
3148
3148
  static const char __pyx_k_itemsize_0_for_cython_array[] = "itemsize <= 0 for cython.array";
3149
3149
  static const char __pyx_k_unable_to_allocate_array_data[] = "unable to allocate array data.";
3150
3150
  static const char __pyx_k_strided_and_direct_or_indirect[] = "<strided and direct or indirect>";
3151
- static const char __pyx_k_Computes_the_checksummed_versio[] = "\n Computes the checksummed version of an Ethereum address.\n\n This function takes a normalized Ethereum address (without the '0x' prefix) and its corresponding\n hash (also without the '0x' prefix) and returns the checksummed address as per the Ethereum\n Improvement Proposal 55 (EIP-55).\n\n Args:\n norm_address_no_0x (str): The normalized Ethereum address without the '0x' prefix.\n address_hash_hex_no_0x (bytes): The hash of the address, also without the '0x' prefix.\n\n Returns:\n The checksummed Ethereum address with the '0x' prefix.\n\n Examples:\n >>> cchecksum(\"b47e3cd837ddf8e4c57f05d70ab865de6e193bbb\", \"abcdef1234567890abcdef1234567890abcdef12\")\n '0xB47E3Cd837DdF8E4C57F05D70Ab865De6E193BbB'\n\n >>> cchecksum(\"0000000000000000000000000000000000000000\", \"1234567890abcdef1234567890abcdef12345678\")\n '0x0000000000000000000000000000000000000000'\n\n See Also:\n - :func:`eth_utils.to_checksum_address`: A utility function for converting addresses to their checksummed form.\n ";
3151
+ static const char __pyx_k_Computes_the_checksummed_versio[] = "\n Computes the checksummed version of an Ethereum address.\n\n This function takes a normalized Ethereum address (without the '0x' prefix) and its corresponding\n hash (also without the '0x' prefix) and returns the checksummed address as per the Ethereum\n Improvement Proposal 55 (EIP-55).\n\n Args:\n norm_address_no_0x: The normalized Ethereum address without the '0x' prefix.\n address_hash_hex_no_0x: The hash of the address, also without the '0x' prefix.\n\n Returns:\n The checksummed Ethereum address with the '0x' prefix.\n\n Examples:\n >>> cchecksum(\"b47e3cd837ddf8e4c57f05d70ab865de6e193bbb\", \"abcdef1234567890abcdef1234567890abcdef12\")\n '0xB47E3Cd837DdF8E4C57F05D70Ab865De6E193BbB'\n\n >>> cchecksum(\"0000000000000000000000000000000000000000\", \"1234567890abcdef1234567890abcdef12345678\")\n '0x0000000000000000000000000000000000000000'\n\n See Also:\n - :func:`eth_utils.to_checksum_address`: A utility function for converting addresses to their checksummed form.\n ";
3152
3152
  static const char __pyx_k_All_dimensions_preceding_dimensi[] = "All dimensions preceding dimension %d must be indexed and not sliced";
3153
3153
  static const char __pyx_k_Buffer_view_does_not_expose_stri[] = "Buffer view does not expose strides";
3154
3154
  static const char __pyx_k_Can_only_create_a_buffer_that_is[] = "Can only create a buffer that is contiguous in memory.";
@@ -17995,7 +17995,7 @@ PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
17995
17995
  PyObject *__pyx_args, PyObject *__pyx_kwds
17996
17996
  #endif
17997
17997
  ); /*proto*/
17998
- PyDoc_STRVAR(__pyx_doc_9cchecksum_9_checksum_cchecksum, "cchecksum(unicode norm_address_no_0x, const unsigned char[::1] address_hash_hex_no_0x) -> str\n\n Computes the checksummed version of an Ethereum address.\n\n This function takes a normalized Ethereum address (without the '0x' prefix) and its corresponding\n hash (also without the '0x' prefix) and returns the checksummed address as per the Ethereum\n Improvement Proposal 55 (EIP-55).\n\n Args:\n norm_address_no_0x (str): The normalized Ethereum address without the '0x' prefix.\n address_hash_hex_no_0x (bytes): The hash of the address, also without the '0x' prefix.\n\n Returns:\n The checksummed Ethereum address with the '0x' prefix.\n\n Examples:\n >>> cchecksum(\"b47e3cd837ddf8e4c57f05d70ab865de6e193bbb\", \"abcdef1234567890abcdef1234567890abcdef12\")\n '0xB47E3Cd837DdF8E4C57F05D70Ab865De6E193BbB'\n\n >>> cchecksum(\"0000000000000000000000000000000000000000\", \"1234567890abcdef1234567890abcdef12345678\")\n '0x0000000000000000000000000000000000000000'\n\n See Also:\n - :func:`eth_utils.to_checksum_address`: A utility function for converting addresses to their checksummed form.\n ");
17998
+ PyDoc_STRVAR(__pyx_doc_9cchecksum_9_checksum_cchecksum, "cchecksum(unicode norm_address_no_0x, const unsigned char[::1] address_hash_hex_no_0x) -> str\n\n Computes the checksummed version of an Ethereum address.\n\n This function takes a normalized Ethereum address (without the '0x' prefix) and its corresponding\n hash (also without the '0x' prefix) and returns the checksummed address as per the Ethereum\n Improvement Proposal 55 (EIP-55).\n\n Args:\n norm_address_no_0x: The normalized Ethereum address without the '0x' prefix.\n address_hash_hex_no_0x: The hash of the address, also without the '0x' prefix.\n\n Returns:\n The checksummed Ethereum address with the '0x' prefix.\n\n Examples:\n >>> cchecksum(\"b47e3cd837ddf8e4c57f05d70ab865de6e193bbb\", \"abcdef1234567890abcdef1234567890abcdef12\")\n '0xB47E3Cd837DdF8E4C57F05D70Ab865De6E193BbB'\n\n >>> cchecksum(\"0000000000000000000000000000000000000000\", \"1234567890abcdef1234567890abcdef12345678\")\n '0x0000000000000000000000000000000000000000'\n\n See Also:\n - :func:`eth_utils.to_checksum_address`: A utility function for converting addresses to their checksummed form.\n ");
17999
17999
  static PyMethodDef __pyx_mdef_9cchecksum_9_checksum_1cchecksum = {"cchecksum", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_9cchecksum_9_checksum_1cchecksum, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_9cchecksum_9_checksum_cchecksum};
18000
18000
  static PyObject *__pyx_pw_9cchecksum_9_checksum_1cchecksum(PyObject *__pyx_self,
18001
18001
  #if CYTHON_METH_FASTCALL
@@ -18227,7 +18227,7 @@ static PyObject *__pyx_pf_9cchecksum_9_checksum_cchecksum(CYTHON_UNUSED PyObject
18227
18227
  * # the character is capitalized.
18228
18228
  * buffer[i + 2] = address_char - 32 if 97 <= address_char <= 102 else address_char # <<<<<<<<<<<<<<
18229
18229
  *
18230
- * # NOTE: For some reason on some systems the buffer length is longer than 42 here, even though that should not be possible.
18230
+ * # It is faster to decode a buffer with a known size ie buffer[:42]
18231
18231
  */
18232
18232
  __Pyx_TraceLine(52,0,__PYX_ERR(0, 52, __pyx_L1_error))
18233
18233
  __pyx_t_7 = (97 <= __pyx_v_address_char);
@@ -18244,14 +18244,14 @@ static PyObject *__pyx_pf_9cchecksum_9_checksum_cchecksum(CYTHON_UNUSED PyObject
18244
18244
  __pyx_L5:;
18245
18245
  }
18246
18246
 
18247
- /* "cchecksum/_checksum.pyx":56
18248
- * # NOTE: For some reason on some systems the buffer length is longer than 42 here, even though that should not be possible.
18249
- * # Lucky for us, the first 42 characters are always correct. One day maybe I'll debug this.
18247
+ /* "cchecksum/_checksum.pyx":55
18248
+ *
18249
+ * # It is faster to decode a buffer with a known size ie buffer[:42]
18250
18250
  * return buffer[:42].decode('ascii') # <<<<<<<<<<<<<<
18251
18251
  */
18252
- __Pyx_TraceLine(56,0,__PYX_ERR(0, 56, __pyx_L1_error))
18252
+ __Pyx_TraceLine(55,0,__PYX_ERR(0, 55, __pyx_L1_error))
18253
18253
  __Pyx_XDECREF(__pyx_r);
18254
- __pyx_t_3 = __Pyx_decode_c_string(((char const *)__pyx_v_buffer), 0, 42, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 56, __pyx_L1_error)
18254
+ __pyx_t_3 = __Pyx_decode_c_string(((char const *)__pyx_v_buffer), 0, 42, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error)
18255
18255
  __Pyx_GOTREF(__pyx_t_3);
18256
18256
  __pyx_r = ((PyObject*)__pyx_t_3);
18257
18257
  __pyx_t_3 = 0;
@@ -10,8 +10,8 @@ def cchecksum(str norm_address_no_0x, const unsigned char[::1] address_hash_hex_
10
10
  Improvement Proposal 55 (EIP-55).
11
11
 
12
12
  Args:
13
- norm_address_no_0x (str): The normalized Ethereum address without the '0x' prefix.
14
- address_hash_hex_no_0x (bytes): The hash of the address, also without the '0x' prefix.
13
+ norm_address_no_0x: The normalized Ethereum address without the '0x' prefix.
14
+ address_hash_hex_no_0x: The hash of the address, also without the '0x' prefix.
15
15
 
16
16
  Returns:
17
17
  The checksummed Ethereum address with the '0x' prefix.
@@ -51,6 +51,5 @@ def cchecksum(str norm_address_no_0x, const unsigned char[::1] address_hash_hex_
51
51
  # the character is capitalized.
52
52
  buffer[i + 2] = address_char - 32 if 97 <= address_char <= 102 else address_char
53
53
 
54
- # NOTE: For some reason on some systems the buffer length is longer than 42 here, even though that should not be possible.
55
- # Lucky for us, the first 42 characters are always correct. One day maybe I'll debug this.
54
+ # It is faster to decode a buffer with a known size ie buffer[:42]
56
55
  return buffer[:42].decode('ascii')
@@ -2,17 +2,14 @@ from binascii import hexlify
2
2
  from typing import Optional, Union
3
3
 
4
4
  from eth_hash.auto import keccak
5
- from eth_typing import AnyAddress, ChecksumAddress, HexAddress, HexStr, Primitives
6
- from eth_utils import encode_hex, hexstr_if_str
5
+ from eth_typing import AnyAddress, ChecksumAddress, HexAddress, HexStr
6
+ from eth_utils import encode_hex, is_hexstr, remove_0x_prefix
7
7
  from eth_utils.address import _HEX_ADDRESS_REGEXP
8
8
  from eth_utils.toolz import compose
9
9
 
10
10
  from cchecksum._checksum import cchecksum
11
11
 
12
12
 
13
- BytesLike = Union[Primitives, bytearray, memoryview]
14
-
15
-
16
13
  # force _hasher_first_run and _preimage_first_run to execute so we can cache the new hasher
17
14
  keccak(b"")
18
15
 
@@ -84,7 +81,7 @@ def to_normalized_address(value: Union[AnyAddress, str, bytes]) -> HexAddress:
84
81
  - :func:`is_address` for checking if a string is a valid address.
85
82
  """
86
83
  try:
87
- hex_address = hexstr_if_str(to_hex, value).lower()
84
+ hex_address = hexstr_if_str(value).lower()
88
85
  except AttributeError as e:
89
86
  raise TypeError(
90
87
  f"Value must be any string, instead got type {type(value)}"
@@ -102,23 +99,28 @@ def to_normalized_address(value: Union[AnyAddress, str, bytes]) -> HexAddress:
102
99
  encode_memoryview = compose(encode_hex, bytes)
103
100
 
104
101
 
105
- def to_hex(
106
- address_bytes: Optional[BytesLike] = None,
107
- *,
108
- hexstr: Optional[HexStr] = None,
109
- ) -> HexStr:
102
+ def hexstr_if_str(hexstr_or_primitive: Union[bytes, int, str]) -> HexStr:
110
103
  """
111
- Auto converts any supported value into its hex representation.
112
- Trims leading zeros, as defined in:
113
- https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding
104
+ Convert to a type, assuming that strings can be only hexstr (not unicode text).
105
+
106
+ :param hexstr_or_primitive bytes, str, int: value to convert
114
107
  """
115
- if hexstr is not None:
116
- return hexstr if hexstr.startswith(("0x", "0X")) else f"0x{hexstr}"
108
+ if isinstance(hexstr_or_primitive, str):
109
+ if remove_0x_prefix(hexstr_or_primitive) and not is_hexstr(hexstr_or_primitive):
110
+ raise ValueError(
111
+ "when sending a str, it must be a hex string. " f"Got: {repr(hexstr_or_primitive)}"
112
+ )
113
+
114
+ return (
115
+ hexstr_or_primitive
116
+ if hexstr_or_primitive.startswith(("0x", "0X"))
117
+ else f"0x{hexstr_or_primitive}"
118
+ )
117
119
 
118
- if isinstance(address_bytes, (bytes, bytearray)):
120
+ elif isinstance(address_bytes, (bytes, bytearray)):
119
121
  return encode_hex(address_bytes)
120
122
 
121
- if isinstance(address_bytes, memoryview):
123
+ elif isinstance(address_bytes, memoryview):
122
124
  return encode_memoryview(address_bytes)
123
125
 
124
126
  raise TypeError(
@@ -128,6 +130,5 @@ def to_hex(
128
130
 
129
131
  del hexlify
130
132
  del Optional, Union
131
- del AnyAddress, ChecksumAddress, HexAddress, HexStr, Primitives
133
+ del AnyAddress, ChecksumAddress, HexAddress, HexStr
132
134
  del _HEX_ADDRESS_REGEXP, compose, keccak
133
- del BytesLike
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cchecksum
3
- Version: 0.0.11
4
- Summary: A ~2x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
3
+ Version: 0.0.13
4
+ Summary: A ~4.5x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
5
5
  Home-page: https://github.com/BobTheBuidler/cchecksum
6
6
  Author: BobTheBuidler
7
7
  Author-email: bobthebuidlerdefi@gmail.com
@@ -13,7 +13,7 @@ setup(
13
13
  "local_scheme": "no-local-version",
14
14
  "version_scheme": "python-simplified-semver",
15
15
  },
16
- description="A ~2x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.",
16
+ description="A ~4.5x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.",
17
17
  author="BobTheBuidler",
18
18
  author_email="bobthebuidlerdefi@gmail.com",
19
19
  url="https://github.com/BobTheBuidler/cchecksum",
@@ -1,7 +0,0 @@
1
- ## CChecksum
2
-
3
- CChecksum is a ~2x faster drop-in replacement for eth_utils.to_checksum_address, with the most cpu-intensive part implemented in c.
4
-
5
- Just `pip install cchecksum`, drop it in, and run your script with a substantial speed improvement.
6
-
7
- ![image](https://github.com/user-attachments/assets/a2da6950-2759-42fa-8a56-7d7e095cd2ce)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes