ó
*oPc           @`  sü   d  Z  d d l m Z m Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 e
 e d d  Z e	 r e j Z n	 d   Z d e f d     YZ d	 e f d
     YZ d e f d     YZ e   Z e j Z e j Z [ d d d g Z d S(   sQ   
Cryptographically secure random implementation, with fallback on normal random.
i    (   t   divisiont   absolute_importN(   t   _PY3t   getrandbitsc         C`  s   |  j  d  S(   Nt   hex(   t   decode(   t   hexBytes(    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyt   _fromhex   s    t   SecureRandomNotAvailablec           B`  s   e  Z d  Z RS(   sD   
    Exception raised when no secure random algorithm is found.
    (   t   __name__t
   __module__t   __doc__(    (    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyR      s   t   SourceNotAvailablec           B`  s   e  Z d  Z RS(   sQ   
    Internal exception used when a specific random source is not available.
    (   R	   R
   R   (    (    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyR      s   t   RandomFactoryc           B`  s}   e  Z d  Z d Z e Z d   Z e d  Z d   Z e	 rQ e
 j Z d   Z n e j Z d   Z e d d  Z d   Z RS(	   sů   
    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.
    c         C`  s=   y t  j |  SWn% t t f k
 r8 } t |   n Xd S(   sO   
        Wrapper around C{os.urandom} that cleanly manage its absence.
        N(   t   ost   urandomt   AttributeErrort   NotImplementedErrorR   (   t   selft   nbytest   e(    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyt
   _osUrandom5   s    c         C`  sa   y |  j  |  SWn t k
 r$ n X| rQ t j d d t d d |  j |  St d   d S(   sk  
        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}
        sP   urandom unavailable - proceeding with non-cryptographically secure random sourcet   categoryt
   stackleveli   s!   No secure random source availableN(   R   R   t   warningst   warnt   RuntimeWarningt   insecureRandomR   (   R   R   t   fallback(    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyt   secureRandom?   s    c         C`  sN   |  j  d k	 r> |  j  | d  } d | d | } t |  St d   d S(   s3   
        Wrapper around C{os.getrandbits}.
        i   s   %%0%dxi   s#   random.getrandbits is not availableN(   R   t   NoneR   R   (   R   R   t   nR   (    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyt	   _randBits\   s
    
c         C`  s;   d j  g  t |  D]! } t t j |  j  g  ^ q  S(   s>   
            Wrapper around the C{random} module.
            t    (   t   joint   ranget   bytest   randomt   choicet   _BYTES(   R   R   t   i(    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyt   _randModulei   s    c         C`  s2   d j  g  t |  D] } t j |  j  ^ q  S(   s>   
            Wrapper around the C{random} module.
            R!   (   R"   R#   R%   R&   R'   (   R   R   R(   (    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyR)   q   s    R!   c         C`  s@   x9 d D]1 } y t  |  |  |  SWq t k
 r7 q Xq Wd S(   sŇ   
        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}
        R    R)   N(   s	   _randBitss   _randModule(   t   getattrR   (   R   R   t   src(    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyR   {   s
    
(    (   R	   R
   R   t   randomSourcesR   R   t   FalseR   R    R   R$   t	   maketranst
   _maketransR)   t   stringR'   R   (    (    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyR   &   s   	
				R   R   (   R   t
   __future__R    R   R   R   R%   R0   t   twisted.python.compatR   R*   R   R   R$   t   fromhexR   t   RuntimeErrorR   R   t   objectR   t   factoryR   R   t   __all__(    (    (    sJ   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/randbytes.pyt   <module>   s   0	g			