fix 3.11 python
This commit is contained in:
parent
df488e667b
commit
bca224601a
1 changed files with 4 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
from hashlib import sha256
|
||||
from sys import set_int_max_str_digits, version_info
|
||||
|
||||
BYTEORDER = "big"
|
||||
|
||||
|
@ -16,10 +17,12 @@ def exist(path: str) -> bool:
|
|||
|
||||
|
||||
def int_to_bytes(data: int) -> bytes:
|
||||
"""Transforme un int en bytes"""
|
||||
"""Convert int to bytes"""
|
||||
return data.to_bytes((data.bit_length() + 7) // 8, BYTEORDER)
|
||||
|
||||
|
||||
def h(data: str) -> str:
|
||||
"""Hash un texte"""
|
||||
if version_info[1] >= 11: # https://docs.python.org/3/library/sys.html#sys.set_int_max_str_digits
|
||||
set_int_max_str_digits(len(data))
|
||||
return str(int.from_bytes(sha256(int_to_bytes(int(data))).digest(), BYTEORDER))
|
||||
|
|
Reference in a new issue