
    h                         S r SSKrSSKrSSKr\" \SS5      r\R                  r " S S\	5      r
 " S S\	5      r " S S	5      r\" 5       r\R                  r\R                  rC/ S
Qrg)zQ
Cryptographically secure random implementation, with fallback on normal random.
    Ngetrandbitsc                       \ rS rSrSrSrg)SecureRandomNotAvailable   z<
Exception raised when no secure random algorithm is found.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       _/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/python/randbytes.pyr   r          r   r   c                       \ rS rSrSrSrg)SourceNotAvailable   zI
Internal exception used when a specific random source is not available.
r   Nr   r   r   r   r   r      r   r   r   c                       \ rS rSrSrSr\rS\S\4S jr	SS\S\
S\4S jjrS\S\4S	 jr\R                  r\" S
S
5      rS\S\4S jrS\S\4S jrSrg)RandomFactory   z
Factory providing L{secureRandom} and L{insecureRandom} methods.

You shouldn't have to instantiate this class, use the module level
functions instead: it is an implementation detail and could be removed or
changed arbitrarily.
r   nbytesreturnc                 v     [         R                  " U5      $ ! [        [        4 a  n[	        U5      eSnAff = f)z?
Wrapper around C{os.urandom} that cleanly manage its absence.
N)osurandomAttributeErrorNotImplementedErrorr   )selfr   es      r   
_osUrandomRandomFactory._osUrandom-   s7    	(::f%% 34 	($Q''	(s    838fallbackc                      U R                  U5      $ ! [         a     Of = fU(       a+  [        R                  " S[        SS9  U R                  U5      $ [        S5      e)a#  
Return a number of secure random bytes.

@param nbytes: number of bytes to generate.
@type nbytes: C{int}
@param fallback: Whether the function should fallback on non-secure
    random or not.  Default to C{False}.
@type fallback: C{bool}

@return: a string of random bytes.
@rtype: C{str}
zPurandom unavailable - proceeding with non-cryptographically secure random source   )category
stacklevelz!No secure random source available)r!   r   warningswarnRuntimeWarninginsecureRandomr   )r   r   r#   s      r   secureRandomRandomFactory.secureRandom6   sd    	??6**! 		 MMM'	 &&v..*+NOO    
  c                     U R                   b*  U R                  US-  5      nSUS-  -  U-  n[        U5      $ [        S5      e)z#
Wrapper around C{os.getrandbits}.
   z%%0%dxr%   z#random.getrandbits is not available)r   _fromhexr   )r   r   nhexBytess       r   	_randBitsRandomFactory._randBitsS   sN     '  !,A FQJ/14HH%% !FGGr   r   c           
          SR                  [        U5       Vs/ s H-  n[        [        R                  " U R
                  5      /5      PM/     sn5      $ s  snf )z&
Wrapper around the C{random} module.
r   )joinrangebytesrandomchoice_BYTES)r   r   is      r   _randModuleRandomFactory._randModule`   s>     xxeFmTmdkk :;<mTUUTs   4Ac                 h     U R                  U5      $ ! [         a     Of = fU R                  U5      $ )z
Return a number of non secure random bytes.

@param nbytes: number of bytes to generate.
@type nbytes: C{int}

@return: a string of random bytes.
@rtype: C{str}
)r4   r   r>   )r   r   s     r   r+   RandomFactory.insecureRandomf   s9    	>>&))! 		''r.   N)F)r	   r
   r   r   r   randomSourcesr   intr9   r!   boolr,   r4   	maketrans
_maketransr<   r>   r+   r   r   r   r   r   r      s     MK( ( (P3 P$ P5 P:H H H JS!FV# V% V(S (U (r   r   )r,   r+   r   )r   r   r:   r(   getattrr   r9   fromhexr1   RuntimeErrorr   r   r   factoryr,   r+   __all__r   r   r   <module>rL      s{   

 
  fmT2==|  U( U(p /##'' Ir   