1+ import random
12import timeit
2- from _typeshed import Incomplete
3- from collections .abc import Generator
3+ from _typeshed import ReadableBuffer
4+ from collections .abc import Iterable
45from hmac import compare_digest
5- from typing import Any
6+ from typing import Final , Literal , SupportsBytes , SupportsIndex , overload
67
78from passlib .utils .compat import JYTHON as JYTHON
89
@@ -34,9 +35,9 @@ __all__ = [
3435 "has_salt_info" ,
3536]
3637
37- sys_bits : Any
38+ sys_bits : Final [ int ]
3839unix_crypt_schemes : list [str ]
39- rounds_cost_values : Any
40+ rounds_cost_values : Final [ list [ str ]]
4041
4142class SequenceMixin :
4243 def __getitem__ (self , idx ): ...
@@ -47,29 +48,40 @@ class SequenceMixin:
4748
4849consteq = compare_digest
4950
50- def str_consteq (left , right ): ...
51- def saslprep (source , param : str = "value" ): ...
52- def render_bytes (source , * args ): ...
53- def xor_bytes (left , right ): ...
54- def is_same_codec (left , right ): ...
55- def is_ascii_safe (source ): ...
56- def to_bytes (source , encoding : str = "utf-8" , param : str = "value" , source_encoding : Incomplete | None = None ): ...
57- def to_unicode (source , encoding : str = "utf-8" , param : str = "value" ): ...
58- def to_native_str (source , encoding : str = "utf-8" , param : str = "value" ): ...
51+ def str_consteq (left : str | bytes , right : str | bytes ) -> bool : ...
52+ def splitcomma (source : str , sep : str = "," ) -> list [str ]: ...
53+ def saslprep (source : str , param : str = "value" ) -> str : ...
54+ def render_bytes (source : str | bytes , * args : str | bytes ) -> bytes : ...
55+ def bytes_to_int (value : Iterable [SupportsIndex ] | SupportsBytes | ReadableBuffer ) -> int : ...
56+ def int_to_bytes (value : int , count : SupportsIndex ) -> bytes : ...
57+ def xor_bytes (
58+ left : Iterable [SupportsIndex ] | SupportsBytes | ReadableBuffer ,
59+ right : Iterable [SupportsIndex ] | SupportsBytes | ReadableBuffer ,
60+ ) -> bytes : ...
61+ def repeat_string (source : str | bytes , size : int ) -> str | bytes : ...
62+ def is_ascii_codec (codec : str ) -> bool : ...
63+ def is_same_codec (left : str , right : str ) -> bool : ...
64+ def is_ascii_safe (source : str | bytes ) -> bool : ...
65+ def to_bytes (source : str | bytes , encoding : str = "utf-8" , param : str = "value" , source_encoding : str | None = None ) -> bytes : ...
66+ def to_unicode (source : str | bytes , encoding : str = "utf-8" , param : str = "value" ) -> str : ...
67+ def to_native_str (source : str | bytes , encoding : str = "utf-8" , param : str = "value" ) -> str : ...
5968
6069has_crypt : bool
6170
62- def safe_crypt (secret , hash ) -> None : ...
63- def test_crypt (secret , hash ) : ...
71+ def safe_crypt (secret : str | bytes , hash : str | bytes ) -> str | None : ...
72+ def test_crypt (secret : str | bytes , hash : str ) -> bool : ...
6473
6574timer = timeit .default_timer
6675tick = timer
67- rng : Any
76+ rng : random . Random
6877
69- def getrandbytes (rng , count ) -> Generator [None , None , Any ]: ...
70- def getrandstr (rng , charset , count ) -> Generator [None , None , Any ]: ...
71- def generate_password (size : int = 10 , charset = ...): ...
72- def is_crypt_handler (obj ): ...
73- def is_crypt_context (obj ): ...
74- def has_rounds_info (handler ): ...
75- def has_salt_info (handler ): ...
78+ @overload
79+ def getrandbytes (rng : random .Random , count : None ) -> Literal [b"" ]: ...
80+ @overload
81+ def getrandbytes (rng : random .Random , count ) -> bytes : ...
82+ def getrandstr (rng : random .Random , charset : str , count : int ) -> str : ...
83+ def generate_password (size : int = 10 , charset : str = ...) -> str : ...
84+ def is_crypt_handler (obj ) -> bool : ...
85+ def is_crypt_context (obj ) -> bool : ...
86+ def has_rounds_info (handler ) -> bool : ...
87+ def has_salt_info (handler ) -> bool : ...
0 commit comments