
    <i8                     H    S r SSKrSSKr/ SQrSrS rS rS rS r	S	 r
S
 rg)z-
Utility functions used by the stem library.
    N)conf
connectionenumlog	lru_cacheordereddictproc	str_toolssystemterm
test_tools	tor_toolsdatetime_to_unixTc                    [         (       d  SnO9[        U 5      (       a  [        S5      nO[        [        [	        U 5      5      5      n[        U [        [        45      (       a  U  H  nUS-  [        U5      -   nM     U$ [        U [        5      (       aD  [        U R                  5       5       H%  nUS-  [        U5      S-  -   [        X   5      -   nM'     U$ U[        U 5      -  nU$ )Nr   str   i   )
HASH_TYPES_is_strhashr   type
isinstancetuplelistdictsortedkeys)valmy_hashvks       L/home/james-whalen/.local/lib/python3.13/site-packages/stem/util/__init__.py_hash_valuer"   0   s    	G s||Ug Sc^$geT]##447*g  
. #tCHHJ4DGdN3d36lBg  
 
. tCyG	.    c                     [         R                  R                  5       (       a  [        U [        [
        45      $ [        U [        [        45      $ )a  
Check if a value is a string. This will be removed when we no longer provide
backward compatibility for the Python 2.x series.

:param object val: value to be checked

:returns: **True** if the value is some form of string (unicode or bytes),
  and **False** otherwise
)stemprereqis_python_3r   bytesr   unicoder   s    r!   r   r   N   s:     
[[cE3<((cE7+,,r#   c                     [         R                  R                  5       (       a  [        U [        5      $ [        U [        [
        45      $ )a  
Check if a value is an integer. This will be removed when we no longer
provide backward compatibility for the Python 2.x series.

:param object val: value to be checked

:returns: **True** if the value is some form of integer (int or long),
  and **False** otherwise
)r%   r&   r'   r   intlongr*   s    r!   _is_intr.   _   s5     
[[c3cC;''r#   c                    [         R                  R                  5       (       a7  U [        R                  " SSS5      -
  nUR                  S-  UR
                  -   $ U [        R                  " SSS5      -
  R                  5       $ )z
Converts a utc datetime object to a unix timestamp.

.. versionadded:: 1.5.0

:param datetime timestamp: timestamp to be converted

:returns: **float** for the unix timestamp of the given datetime object
i     iQ )r%   r&   _is_python_26datetimedayssecondstotal_seconds)	timestampdeltas     r!   r   r   p   sk     
[[  **4A66E::--))$155DDFFr#   c                    [        U 5      (       a  U $ [        R                  R                  5       (       d  [	        S5      e[        R                  R                  SS9(       d  [	        S5      eSSKJn  SSKJnJ	n  SSK
JnJn  [        XU45      (       aF  U R                  5       R                  UR                   R"                  UR$                  R"                  S	9$ [        XU45      (       a8  U R                  UR                   R"                  UR$                  R"                  S	9$ ['        S
[)        U 5      R*                  -  5      e)zA
Normalizes X25509 and ED25519 keys into their public key bytes.
z2Key normalization requires the cryptography moduleT)ed25519z;Key normalization requires the cryptography ed25519 supportr   )serialization)Ed25519PrivateKeyEd25519PublicKey)X25519PrivateKeyX25519PublicKey)encodingformatzAKey must be a string or cryptographic public/private key (was %s))r   r%   r&   is_crypto_availableImportErrorcryptography.hazmat.primitivesr:   1cryptography.hazmat.primitives.asymmetric.ed25519r;   r<   0cryptography.hazmat.primitives.asymmetric.x25519r=   r>   r   
public_keypublic_bytesEncodingRawPublicFormat
ValueErrorr   __name__)keyr:   r;   r<   r=   r>   s         r!   _pubkey_bytesrN      s   
 S\\J		(	(	*	*
J
KK;;**T*:
S
TT:c`(9:;;>>((''++))-- )   #)9:;;''++))--   
 X[_`c[d[m[mm
nnr#   c                 l   UR                  SS5      nUR                  SS5      n[        U SS5      nU(       a  Ub  U$ U(       a  UR                  U 5      OSnUS-  [        [	        [        U 5      5      5      -   nU H  n[        X5      nUS-  [        U5      -   nM!     U(       a  [        U SU5        U$ )a  
Provide a hash value for the given set of attributes.

:param Object obj: object to be hashed
:param list attributes: attribute names to take into account
:param bool cache: persists hash in a '_cached_hash' object attribute
:param class parent: include parent's hash value
cacheFparentN_cached_hashr   r   )getgetattr__hash__r   r   r   r"   setattr)	obj
attributeskwargs	is_cachedparent_classcached_hashr   attrr   s	            r!   
_hash_attrr^      s     jj%()Hd+,^T2+;**6L!!#&A'dNT#d3i.11'd
#
Cn{3//G  C)	.r#   )__doc__r2   stem.prereqr%   __all__r   r"   r   r.   r   rN   r^    r#   r!   <module>rc      sA     B 
<-"("G$o>r#   