
    h8                     H    d Z ddlZddlZg dZdZd Zd Zd Zd Z	d	 Z
d
 Zy)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                    t         sd}n4t        |       rt        d      }nt        t        t	        |                   }t        | t        t        f      r| D ]  }|dz  t        |      z   } |S t        | t              rCt        | j                               D ]%  }|dz  t        |      dz  z   t        | |         z   }' |S |t        |       z  }|S )Nr   str   i   )
HASH_TYPES_is_strhashr   type
isinstancetuplelistdictsortedkeys)valmy_hashvks       \/var/www/betterdocs.net/sherlock_api/venv/lib/python3.12/site-packages/stem/util/__init__.py_hash_valuer"   0   s    	G s|Ug Sc^$geT]# +447*g+ 
. #tCHHJ C4DGdN3d3q6lBgC
 
. tCyG	.    c                     t         j                  j                         rt        | t        t
        f      S t        | t        t        f      S )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   s7     
[[cE3<((cE7+,,r#   c                     t         j                  j                         rt        | t              S t        | t        t
        f      S )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.   _   s2     
[[c3cC;''r#   c                     t         j                  j                         r6| t        j                  ddd      z
  }|j                  dz  |j
                  z   S | t        j                  ddd      z
  j                         S )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   sh     
[[ **4A66E::--))$155DDFFr#   c                 r   t        |       r| S t        j                  j                         st	        d      t        j                  j                  d      st	        d      ddlm} ddlm}m	} ddl
m}m} t        | ||f      rI| j                         j                  |j                   j"                  |j$                  j"                  	      S t        | ||f      r;| j                  |j                   j"                  |j$                  j"                  	      S t'        d
t)        |       j*                  z        )zE
  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                 J   |j                  dd      }|j                  dd      }t        | dd      }|r||S |r|j                  |       nd}|dz  t        t	        t        |                   z   }|D ]  }t        | |      }|dz  t        |      z   }! |rt        | d|       |S )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' 0d
#t
Cn{3//G0 C)	.r#   )__doc__r2   stem.prereqr%   __all__r   r"   r   r.   r   rN   r^    r#   r!   <module>rc      sA     B 
<-"("G$o>r#   