Your IP : 172.28.240.42


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

ó
ê=Nc@s dZddlZddlmZddlmZdefd„ƒYZdeejfd„ƒYZ	d	eejfd
„ƒYZ
deejfd„ƒYZdS(
s-
Test cases for L{twisted.python.randbytes}.
iÿÿÿÿN(tunittest(t	randbytestSecureRandomTestCaseBasecBseZdZd„ZRS(s1
    Base class for secureRandom test cases.
    cCsrxktddƒD]Z}||ƒ}|jt|ƒ|ƒ||ƒ}|jt|ƒ|ƒ|j||ƒqWdS(s|
        The given random bytes source should return the number of bytes
        requested each time it is called and should probably not return the
        same bytes on two consecutive calls (although this is a perfectly
        legitimate occurrence and rejecting it may generate a spurious failure
        -- maybe we'll get lucky and the heat death with come first).
        iiN(trangetassertEqualtlentassertNotEquals(tselftsourcetnbyteststs2((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyt_checks(t__name__t
__module__t__doc__R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyRstSecureRandomTestCasecBseZdZd„ZRS(s4
    Test secureRandom under normal conditions.
    cCs|jtjƒdS(s£
        L{randbytes.secureRandom} should return a string of the requested
        length and make some effort to make its result otherwise unpredictable.
        N(RRtsecureRandom(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_normal+s(R
RRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyR&stConditionalSecureRandomTestCasecBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s<
    Test random sources one by one, then remove it to.
    cCstjƒ|_dS(sJ
        Create a L{randbytes.RandomFactory} to use in the tests.
        N(Rt
RandomFactorytfactory(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pytsetUp:scCstjƒ‚dS(sL
        A factory raising an error when a source is not available.
        N(RtSourceNotAvailable(RR	((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyterrorFactoryAscCs|j|jjƒdS(sy
        L{RandomFactory._osUrandom} should work as a random source whenever
        L{os.urandom} is available.
        N(RRt
_osUrandom(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_osUrandomHscCsKy|j|jjƒWn-tjk
rF|jtjjdƒƒnXdS(s}
        L{RandomFactory._fileUrandom} should work as a random source whenever
        C{/dev/urandom} is available.
        s/dev/urandomN(	RRt_fileUrandomRRtassertFalsetostpathtexists(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_fileUrandomPscs{ˆjˆj_ˆjˆj_ˆjtjˆjjdƒ‡fd†}ˆjt	dt
|ƒ}ˆjt|ƒdƒdS(st
        Remove all secure sources and assert it raises a failure. Then try the
        fallback parameter.
        icsˆjjddtƒS(Nitfallback(RRtTrue((R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pytwrapperessPurandom unavailable - proceeding with non-cryptographically secure random sourceN(
RRRRtassertRaisesRtSecureRandomNotAvailableRtassertWarnstRuntimeWarningt__file__RR(RR#R
((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_withoutAnything\s	(R
RRRRRR R)(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyR4s				tRandomTestCaseBasecBs eZdZd„Zd„ZRS(s%
    'Normal' random test cases.
    cCs|jtjƒdS(s"
        Test basic case.
        N(RRtinsecureRandom(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyRvscCs)tjƒ}d|_|j|jƒdS(sG
        Test C{insecureRandom} without C{random.getrandbits}.
        N(RRtNonetgetrandbitsRR+(RR((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_withoutGetrandbits}s	(R
RRRR.(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyR*qs	(RRt
twisted.trialRttwisted.pythonRtobjectRtTestCaseRRR*(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyt<module>s<