Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/python/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyc

ó
[³XMc@s¯dZddlZddlZddlZeeddƒZdefd„ƒYZdefd„ƒYZ	de
fd	„ƒYZeƒZej
Z
ejZ[d
ddgZdS(sQ
Cryptographically secure random implementation, with fallback on normal random.
iÿÿÿÿNtgetrandbitstSecureRandomNotAvailablecBseZdZRS(sD
    Exception raised when no secure random algorithm is found.
    (t__name__t
__module__t__doc__(((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyRstSourceNotAvailablecBseZdZRS(sQ
    Internal exception used when a specific random source is not available.
    (RRR(((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyRst
RandomFactorycBsSeZdZdZeZd„Zd„Zed„Zd„Z	d„Z
d„ZRS(	sy
    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.

    @cvar randomSources: list of file sources used when os.urandom is not
        available.
    @type randomSources: C{tuple}
    s/dev/urandomcCs=ytj|ƒSWn%ttfk
r8}t|ƒ‚nXdS(sO
        Wrapper around C{os.urandom} that cleanly manage its absence.
        N(tosturandomtAttributeErrortNotImplementedErrorR(tselftnbyteste((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyt
_osUrandom-scCsxx[|jD]P}yt|dƒ}Wnttfk
r<q
X|j|ƒ}|jƒ|Sq
Wtd|jfƒ‚dS(sœ
        Wrapper around random file sources.

        This method isn't meant to be call out of the class and could be
        removed arbitrarily.
        trbsFile sources not available: %sN(t
randomSourcestfiletIOErrortOSErrortreadtcloseR(RRtsrctftbytes((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyt_fileUrandom7s
cCsxx9d	D]1}yt||ƒ|ƒSWqtk
r7qXqW|rhtjddtddƒ|j|ƒStdƒ‚dS(
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}
        RRsPurandom unavailable - proceeding with non-cryptographically secure random sourcetcategoryt
stacklevelis!No secure random source availableN(s
_osUrandoms_fileUrandom(tgetattrRtwarningstwarntRuntimeWarningtinsecureRandomR(RRtfallbackR((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pytsecureRandomKs



cCsQ|jdk	rA|j|dƒ}d|d|}|jdƒStdƒ‚dS(s3
        Wrapper around C{os.getrandbits}.
        is%%0%dxithexs#random.getrandbits is not availableN(RtNonetdecodeR(RRtnthexBytes((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyt	_randBitshs

cCs=d}x0t|ƒD]"}|ttjddƒƒ7}qW|S(s5
        Wrapper around C{random.randrange}.
        tiiÿ(txrangetchrtrandomt	randrange(RRRti((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyt
_randRangess cCs@x9dD]1}yt||ƒ|ƒSWqtk
r7qXqWdS(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
_randRange(RR(RRR((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyR }s



(s/dev/urandom(RRRRRRRtFalseR"R(R/R (((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyRs	
			
R"R (RRRR,RR$RtRuntimeErrorRRtobjectRtfactoryR"R t__all__(((s</usr/lib/python2.7/dist-packages/twisted/python/randbytes.pyt<module>s$r