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_amp.pyc


{|Nc@sH	dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZmZmZmZmZdd
lmZddlmZeZyddlmZWnek
rnXeoejr
eZneekr"d
ZneZdejfdYZdej fdYZ!de"fdYZ#de"fdYZ$de"fdYZ%dej&fdYZ'dej(fdYZ)de)fdYZ*dej(fdYZ+d ej(fd!YZ,d"ej(fd#YZ-d$ej(fd%YZ.d&ej(fd'YZ/d(ej(fd)YZ0d*ej(fd+YZ1d,ej(fd-YZ2d.ej(fd/YZ3d0ej4fd1YZ5d2ej6fd3YZ7d4Z8d5e"fd6YZ9d7ej fd8YZ:d9e:fd:YZ;d;e;fd<YZ<d=e;fd>YZ=d?e;fd@YZ>e!e!dAZ?dBejfdCYZ@dDej fdEYZAdFejBfdGYZCdHejBfdIYZDdJeEfdKYZFdLfdMYZGdNejBfdOYZHdPej(fdQYZIdRejJfdSYZKdTeKfdUYZLdVeLfdWYZMdXej fdYYZNdZejBfd[YZOd\ZPd]ZQd^ejBfd_YZRd`ejBfdaYZSdbfdcYZTddfdeYZUdfeUfdgYZVdheUfdiYZWdjeUfdkYZXdle:fdmYZYdnejBfdoYZZdpejBfdqYZ[dre"fdsYZ\dte"fduYZ]dvej(fdwYZ^dxe^fdyYZ_dze^fd{YZ`d|ej fd}YZad~ej fdYZbdej fdYZcdejBfdYZddZedfdYZfdZgdZheek	rehZindefejBfdYZjde;fdYZkdefejBfdYZldefejBfdYZmdej&fdYZndej(fdYZodej(fdYZpdej fdYZqderfdYZsdeofdYZtdejBfdYZudfdYZvdejBevfdYZwdejBevfdYZxdejBevfdYZydejBevfdYZzdejBevfdYZ{dejBfdYZ|dejBevfdYZ}dejBfdYZ~dejBfdYZdejBfdYZejjerD	dZeeZ_eej_eel_eem_ndS(s%
Tests for L{twisted.protocols.amp}.
iN(tverifyObject(t
setIDFunction(tfilepath(tFailure(tamp(tunittest(tprotocoltdeferterrortreactort
interfaces(tiosim(tStringTransport(tsslsSSL not availablet	TestProtocBsAeZdZdZdZdZdZdZdZRS(s
    A trivial protocol for use in testing where a L{Protocol} is expected.

    @ivar instanceId: the id of this instance
    @ivar onConnLost: deferred that will fired when the connection is lost
    @ivar dataToSend: data to send on the protocol
    icCs2||_||_tj|_tjdt_dS(Ni(t
onConnLostt
dataToSendRt
instanceCountt
instanceId(tselfRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt__init__1s		cCs g|_|jj|jdS(N(tdatat	transporttwriteR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytconnectionMade8s	cCs|jj|dS(N(Rtappend(Rtbytes((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytdataReceived=scCs|jj|jdS(N(RtcallbackR(Rtreason((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytconnectionLostAscCsd|jfS(s
        Custom repr for testing to avoid coupling amp tests with repr from
        L{Protocol}

        Returns a string which contains a unique identifier that can be looked
        up using the instanceId property::

            <TestProto #3>
        s<TestProto #%d>(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt__repr__Es
(	t__name__t
__module__t__doc__RRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR&s				tSimpleSymmetricProtocolcBs#eZdZdZdZRS(cCs|jdd|S(Nthello(tcallRemoteString(Rttext((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	sendHelloUscCstjd|dS(NR$(RtBox(Rtbox((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	amp_HELLOZscCstjddS(Nt
howdoyoudotworld(RtQuitBox(RR)((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytamp_HOWDOYOUDO]s(R R!R'R*R.(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR#Ss		tUnfriendlyGreetingcBseZdZRS(s&Greeting was insufficiently kind.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR/bstDeathThreatcBseZdZRS(s&Greeting was insufficiently kind.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR0fstUnknownProtocolcBseZdZRS(s+Asked to switch to the wrong protocol.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR1jst
TransportPeercBs#eZdZdZdZRS(cCsdS(Nt((Rtdtnametproto((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytretrieverscCs
|jjS(N(RtgetPeer(Rt
notAStringR6((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytfromStringProtouscCsdS(N((RR5tstringstobjectsR6((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttoBoxxs(R R!R7R:R=(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR2os		tHelloc
BseZdZdejfdejdefdejdefdedefdejdefdejdefdejdefgZ	dejfdejdefgZ
ide6Zide
6ZRS(	R$toptionaltprinttfromt	mixedCasesdash-argtunderscore_argt
UNFRIENDLYtDEAD(R R!tcommandNameRtStringtBooleantTruetUnicodeR2t	argumentstresponseR/terrorsR0tfatalErrors(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR>}s
t
NoAnswerHellocBseZejZeZRS((R R!R>RFtFalsetrequiresAnswer(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyROs	tFutureHellocBseZdZdejfdejdefdejdefdedefdejdefgZ	dejfdejdefgZ
ide6ZRS(R$R?R@RAtbonusRD(
R R!RFRRGRHRIRJR2RKRLR/RM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRRstWTFcBseZdZRS(s+
    An example of an invalid command.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRTstBrokenReturncBseZdZdZRS(s\ An example of a perfectly good command, but the handler is going to return
    None...
    t
broken_return(R R!R"RF(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRUstGoodbyecBs&eZdejfgZejZRS(tgoodbye(R R!RRGRLR-tresponseType(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRWst
HowdoyoudocBseZdZRS(R+(R R!RF(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRZstWaitForevercBseZdZRS(twait_forever(R R!RF(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR[stGetListcBsJeZdZdejfgZdejdejfgfgZRS(tgetlisttlengthtbodytx(R R!RFRtIntegerRKtAmpListRL(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR]stDontRejectMecBs_eZdZdejfdejdejfgdefgZdejfgZRS(tdontrejectmet	magicWordtlistR5R?RL(	R R!RFRRJRcRIRKRL(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRds-tSecuredPingcBseZdejfgZRS(tpinged(R R!RRHRL(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRhstTestSwitchProtocBs0eZdZdejfgZide6ZRS(sSwitch-ProtoR5tUNKNOWN(R R!RFRRGRKR1RM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRjstSingleUseFactorycBs)eZdZdZdZdZRS(cCs||_||j_dS(N(R6tfactory(RR6((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs	cCs|jd}|_|S(N(R6tNone(Rtaddrtp((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
buildProtocolscCs
||_dS(N(treasonFailed(Rt	connectorR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytclientConnectionFaileds	N(R R!RRqRnRrRt(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRls		sgwebol nargotThingIDontUnderstandErrorcBseZRS((R R!(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRustFactoryNotifiercBs-eZdZdZdZejeRS(cCsJ|jdk	rF||j_t|jdrF|jjjdqFndS(NtonMade(RmRnttheProtothasattrRwR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs<ddlm}|j|js1tdnitd6S(Ni(t
ISSLTransports+only send secure pings over secure channelsRi(ttwisted.internet.interfacesRzt
providedByRR0RI(RRz((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytemitpongsN(R R!RnRmRR}Rht	responder(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRvs		tSimpleSymmetricCommandProtocolcBseZdZddZdZdZeZddddddZ	e
je	dZe
jeddZejedZejedZejedZejeed	Zd
ZejedZejeRS(
cCstjj|||_dS(N(RtAMPRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs|jtd|S(NR$(t
callRemoteR>(RR&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR'scCs|jtd|d|S(NR$tPrint(RR>(RR&ttranslation((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytsendUnicodeHellosc	Cs||jjkst|tkr3tn|jdrQtdn|dkrltdntd|}|dk	r|j
td|nt|_|S(NtfucksDon't be a dick.tdietaieeeeeeeeeR$R(
RR8tAssertionErrortTHING_I_DONT_UNDERSTANDRut
startswithR/R0tdictRntupdateRItgreeted(	RR$tFromR?RRBtdash_argRCtresult((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytcmdHello	s	cCsitddg|d6S(NRaiR`(R(RR_((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
cmdGetlistscCs4|dkrd}nd|dd}td|S(Nulist omittedu%s acceptediR5RL(RnR(RRfRgRL((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytokiwonts	cCstj|_|jS(N(RtDeferredtwaiting(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	waitforit%scCs
tddS(NR+R,(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pythowdo*scCs
tddS(NRXteveryone(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytsaybye.scsU|rd}nd}t|jt|jttd|jfdS(Nsno-protos
test-protoR5csS(N((tign(Rp(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt<lambda>:s(RRtSWITCH_CLIENT_DATARRjRltaddCallback(RtfailR5((Rps9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytswitchToTestProtocol2s	cCs,|dkrt|jtSt|dS(Ns
test-proto(RRtSWITCH_SERVER_DATAR1(RR5((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytswitchit<scCsdS(N(Rn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	donothingBsN(R R!Rnt
maybeLaterRR'RRPRRR>R~RR]RRdRR[RRZRRWRRRjRRU(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs.		

	

	
	
	

	
	t DeferredSymmetricCommandProtocolcBseZdZejeRS(cCsG|dkr7t|jt|_tj|_|jSt|dS(Ns
test-proto(RRRtmaybeLaterProtoRRRR1(RR5((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRHs
(R R!RRjR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRGs	tBadNoAnswerCommandProtocolcBs-eZddddddZejeRS(cCsdS(sQ
        This responder does nothing and forgets to return a dictionary.
        N((RR$RR?RRBRRC((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytbadResponderQsN(R R!RnRROR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRPstNoAnswerCommandProtocolcBs-eZddddddZejeRS(cCstd|dS(NR$s	-noanswer(R(RR$RR?RRBRRC((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytgoodNoAnswerResponderYsN(R R!RnRROR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRXscOstj||||S(s.Returns a 3-tuple: (client, server, pump)
    (RtconnectedServerAndClient(tServerClasstClientClasstatkw((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR^stTotallyDumbProtocolcBseZdZdZRS(R3cCs|j|7_dS(N(tbuf(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRis(R R!RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRgst
LiteralAmpcBseZdZdZRS(cCs
g|_dS(N(tboxes(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRmscCs|jj|dS(N(RR(RR)((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytampBoxReceivedps(R R!RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRls	tAmpBoxTestscBs)eZdZdZdZdZRS(sm
    Test a few essential properties of AMP boxes, mostly with respect to
    serialization correctness.
    cCs2tjdd}|jt|jtdS(s8
        Make sure that strs serialize to strs.
        tkeytvalueN(RtAmpBoxtassertEqualttypet	serializetstr(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_serializeStr|scCs-tjidd6}|jt|jdS(sX
        Verify that TypeError is raised when trying to serialize Unicode keys.
        RukeyN(RRtassertRaisest	TypeErrorR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_serializeUnicodeKeyRaisesscCs)tjdd}|jt|jdS(sb
        Verify that TypeError is raised when trying to serialize Unicode
        values.
        RuvalueN(RRRRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt test_serializeUnicodeValueRaisess(R R!R"RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRvs		tParsingTestcBs,eZdZdZdZdZRS(cCstj}|j|jdt|j|jdt|jt|jd|jt|jd|jt|jd|j|jtd|j|jtddS(se
        Verify that the Boolean parser parses 'True' and 'False', but nothing
        else.
        RIRPtninjattruetTRUEN(	RRHRt
fromStringRIRPRRttoString(Rtb((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_booleanValuesscCsctj|j}tj}|j|}|j|}|j|||j||dS(sL
        Verify the 'Path' argument can parse and emit a file path.
        N(	RtFilePathtmktempRtPathRRtassertNotIdenticalR(RtfpRptstv((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_pathValueRoundTripscCs+tj}|jtj|jtjS(sk
        Test that empty boxes raise an error; they aren't supposed to be sent
        on purpose.
        (RRRtNoEmptyBoxesRR((RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_sillyEmptyThingsc
Cstdtdt\}}}d}d}d}d}d}d}	d}
|g||
g||g||g||||g|||g||||	g|
||gg}x[|D]S}tj}
|
jt||
j||j|j|j	d|
qWdS(sq
        Verify that various kinds of data make it through the encode/parse
        round-trip unharmed.
        RRtsimplettesttceqs: tcrteststest
tlftestshello
tnewlinestest
one
twotnewline2stest
one
 twoR`sblah

testtestiN(Rstest(Rs: (Rstest
(Rshello
(Rstest
one
two(Rstest
one
 two(sbodysblah

testtest(
RRRR(RRt_sendTotflushRR(RtcRRptSIMPLEtCEtCRtLFtNEWLINEtNEWLINE2tBODYTESTttestDataRtjb((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_ParsingRoundTrips.			


(R R!RRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs				tFakeLocatorcBs eZdZdZdZRS(sZ
    This is a fake implementation of the interface implied by
    L{CommandLocator}.
    cCs
i|_dS(sN
        Remember the given keyword arguments as a set of responders.
        N(tcommands(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs|j|S(sz
        Look up and return a function passed as a keyword argument of the given
        name to the constructor.
        (R(RRF((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytlocateResponders(R R!R"RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs	t
FakeSendercBs2eZdZdZdZdZdZRS(s\
    This is a fake implementation of the 'box sender' interface implied by
    L{AMP}.
    cCsg|_g|_d|_dS(sn
        Create a fake sender and initialize the list of received boxes and
        unhandled errors.
        iN(t	sentBoxestunhandledErrorstexpectedErrors(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs		cCs|jd7_dS(sB
        Expect one error, so that the test doesn't fail.
        iN(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytexpectErrorscCs|jj|dS(s6
        Accept a box, but don't do anything.
        N(RR(RR)((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytsendBoxscCs?|jd8_|jdkr+|jn|jj|dS(sW
        Deal with failures by instantly re-raising them for easier debugging.
        iiN(RtraiseExceptionRR(Rtfailure((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytunhandledErrors
(R R!R"RRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
	
		tCommandDispatchTestscBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s
    The AMP CommandDispatcher class dispatches converts AMP boxes into commands
    and responses using Command.responder decorator.

    Note: Originally, AMP's factoring was such that many tests for this
    functionality are now implemented as full round-trip tests in L{AMPTest}.
    Future tests should be written at this level instead, to ensure API
    compatibility and to provide more granular, readable units of test
    coverage.
    cCsDt|_t|_tj|j|_|jj|jdS(s-
        Create a dispatcher to use.
        N(RtlocatorRtsenderRt
BoxDispatchert
dispatchertstartReceivingBoxes(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytsetUp&scsjgfd}tjdddddd}||jjd<|jj||j|gdS(s
        L{CommandDispatcher.ampBoxReceived} should locate the appropriate
        command in its responder lookup, based on the '_ask' key.
        cs!j|tjidd6S(NRXR$(RRR((R)(treceived(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytthunk6s
t_commandR$t_askstest-command-idR,N(RR(RRRRR(RRtinput((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_receivedAsk0s	cCsltd}|jj|jjt||jt|jjd|j|jjdj	|dS(sy
        L{CommandDispatcher} should relay its unhandled errors in responding to
        boxes to its boxSender.
        ssomething went wrong, oh noiiN(
tRuntimeErrorRRRRRRtlenRR(Rterr((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_sendUnhandledErrorAs

cstdfd}||jjd<tjdddddd}|jj|jj||j	t
|jjd|j	|jjd	jd
S(sp
        Errors during serialization ought to be relayed to the sender's
        unhandledError method.
        ssomething undefined went wrongcs&dtjffdY}|S(Nt	BrokenBoxcseZfdZRS(cs
dS(N((RR6(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRUs(R R!R((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRTs(RR((RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRSsR$RRstest-command-idR,iiN(
RRRRR(RRRRRRRR(RRR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt test_unhandledSerializationErrorMs	
c	Cs|jjtdd}|j|jjtjddddddgg}|j|j	|j|g|jj
tjidd6dd6dd	6|j|tddd
dgdS(
s[
        L{CommandDispatcher.callRemote} should emit a properly formatted '_ask'
        box to its boxSender and record an outstanding L{Deferred}.  When a
        corresponding '_answer' packet is received, the L{Deferred} should be
        fired, and the results translated via the given L{Command}'s response
        de-serialization.
        R$R,RRt1tyaytignoredR@t_answerRuignoredN(RRR>RRRRRRRRR(RtDtanswers((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_callRemotebs
cCsfg}|j|j|jdt|jj|j|jjdjt|jdg|dS(s
        Verify that C{callResult} completes with a C{None} result and that an
        unhandled error has been logged.
        iiN(
taddBothRRRRRtassertIsInstanceRtZeroDivisionErrorRn(Rt
callResulttfinalResult((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt_localCallbackErrorLoggingTestyscCst|jj|jjtdd}|jd|jjtjidd6dd6dd6|j	|d	S(
s
        If the last callback on the L{Deferred} returned by C{callRemote} (added
        by application code calling C{callRemote}) fails, the failure is passed
        to the sender's C{unhandledError} method.
        R$R,cSsddS(Nii((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRRR@RR	N(
RRRRR>RRRRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt/test_callRemoteSuccessLocalCallbackErrorLoggings
cCst|jj|jjtdd}|jd|jjtjidd6dd6dd	6|j	|d
S(s
        Like L{test_callRemoteSuccessLocalCallbackErrorLogging}, but for the
        case where the L{Deferred} returned by C{callRemote} fails.
        R$R,cSsddS(Nii((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRt_errortbugst_error_codetstufft_error_descriptionN(
RRRRR>t
addErrbackRRRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt-test_callRemoteErrorLocalCallbackErrorLoggings
(R R!R"RRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
	
						tSimpleGreetingcBsMeZdZdZdejfdejfgZdejfgZRS(sN
    A very simple greeting command that uses a few basic argument types.
    Rtgreetingtcookiet
cookieplus(	R R!R"RFRRJRbRKRL(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
tTestLocatorcBs/eZdZdZdZejeZRS(sI
    A locator which implements a responder to the 'simple' command.
    cCs
g|_dS(N(t	greetings(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs'|jj||ftd|dS(NRi(R RR(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytgreetingResponders(R R!R"RR!RR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs		tOverridingLocatorcBs&eZdZdZejeZRS(sJ
    A locator which overrides the responder to the 'simple' command.
    cCs'|jj||ftd|dS(sV
        Return a different cookieplus than L{TestLocator.greetingResponder}.
        Ri(R RR(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR!s(R R!R"R!RR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR"s	tInheritingLocatorcBseZdZRS(sN
    This locator should inherit the responder from L{OverridingLocator}.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR#stOverrideLocatorAMPcBs2eZdZdZdZejeZRS(cCs<tjj|t|_i|jd6|_g|_dS(Ntcustom(RRRtobjecttcustomRespondertexpectationsR (R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs:||jkr |j|}|Stt|j|SdS(sB
        Override the deprecated lookupFunction function.
        N(R(tsuperR$tlookupFunction(RR5R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR*s
cCs'|jj||ftd|dS(NRi(R RR(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR!s(R R!RR*R!RR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR$s			tCommandLocatorTestscBsDeZdZdZdZdZdZdZdZRS(s
    The CommandLocator should enable users to specify responders to commands as
    functions that take structured objects, annotated with metadata.
    csU|}|jd}|tjdddd}fd}|j|S(s
        Check that a locator of type C{locatorClass} finds a responder
        for command named I{simple} and that the found responder answers
        with the C{expected} result to a C{SimpleGreeting<"ni hao", 5>}
        command.
        RRsni haoRt5cs&j|tjdtdS(NR(RRRR(tvalues(texpectedR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytdones(RRR(R(RtlocatorClassR.RtresponderCallableRR/((RR.s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt_checkSimpleGreetings
	cCs|jtdS(s
        A method on a L{CommandLocator} subclass decorated with a L{Command}
        subclass's L{responder} decorator should be returned from
        locateResponder, wrapped in logic to serialize and deserialize its
        arguments.
        i(R2R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_responderDecoratorscCs|jtdS(s
        L{CommandLocator} subclasses can override a responder inherited from
        a base class by using the L{Command.responder} decorator to register
        a new responder method.
        i	(R2R"(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_responderOverridingscCs|jtdS(s
        Responder lookup follows the same rules as normal method lookup
        rules, particularly with respect to inheritance.
        i	(R2R#(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_responderInheritancescstjtdtfd}jj|jtdtfd}|tjdddd}fd}|j|S(	s0
        Subclasses which override locateResponder under its old name,
        lookupFunction, should have the override invoked instead.  (This tests
        an AMP subclass, because in the version of the code that could invoke
        this deprecated code path, there was no L{CommandLocator}.)
        s-Override locateResponder, not lookupFunction.cs
jdS(NR%(R((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR1scs
jdS(NR(R((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR7sRsni haoRR,cs j|tjdddS(NRt8(RRR(R-(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR/9s(	R$tassertWarnstPendingDeprecationWarningt__file__RR'RR(R(RtcustomResponderObjecttnormalResponderObjectRR/((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt%test_lookupFunctionDeprecatedOverride&s	csdtjtdtfd}|tjdddd}fd}|j|S(s
        Invoking locateResponder under its old name, lookupFunction, should
        emit a deprecation warning, but do the same thing.
        s)Call locateResponder, not lookupFunction.cs
jdS(NR(R*((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRGsRsni haoRR,cs j|tjdddS(NRR6(RRR(R-(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR/Is(RR7R8R9RR(R(RR1RR/((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt#test_lookupFunctionDeprecatedInvoke>s	(	R R!R"R2R3R4R5R<R=(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR+s		
				sSuccess!sNo, really.  Success.tBinaryProtocolTestscBseZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZRS(s
    Tests for L{amp.BinaryBoxProtocol}.

    @ivar _boxSender: After C{startReceivingBoxes} is called, the L{IBoxSender}
        which was passed to it.
    cCsg|_g|_dS(sz
        Keep track of all boxes received by this test in its capacity as an
        L{IBoxReceiver} implementor.
        N(RR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR[s	cCs
||_dS(sm
        Implement L{IBoxReceiver.startReceivingBoxes} to just remember the
        value passed in.
        N(t
_boxSender(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRdscCs|jj|dS(s5
        A box was received by the protocol.
        N(RR(RR)((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRlscCs
||_dS(sD
        Record the reason that we stopped receiving boxes.
        N(t
stopReason(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytstopReceivingBoxessscCsdS(Nsno peer((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR8{scCsdS(Nsno host((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytgetHostscCs|jj|dS(N(RR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs3tj|}|jd|j|j|dS(s
        When L{amp.BinaryBoxProtocol} is connected to a transport, it calls
        C{startReceivingBoxes} on its L{IBoxReceiver} with itself as the
        L{IBoxSender} parameter.
        N(RtBinaryBoxProtocoltmakeConnectionRntassertIdenticalR?(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_startReceivingBoxess
cCsUdddY}t}tj|}|j||j|jddS(s
        The L{IBoxReceiver} which is started when L{amp.BinaryBoxProtocol} is
        connected to a transport can call C{sendBox} on the L{IBoxSender}
        passed to it before C{startReceivingBoxes} returns and have that box
        sent.
        tSynchronouslySendingReceivercBseZdZRS(cSs!|jtjidd6dS(Ntbartfoo(RRR((RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs(R R!R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRGstfoobarN((RRRCRDRR(RRGRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!test_sendBoxInStartReceivingBoxess	
	cCs\tj|}|jd|jd|jd|j|jtjddgdS(s
        When a binary box protocol receives:
            * a key
            * a value
            * an empty string
        it should emit a box and send it to its boxReceiver.
        R$R,R3N(RRCtstringReceivedRRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_receiveBoxStateMachines



cCsFt}tj|}|j||jd|j|jdS(s
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        the first a key it receives is larger than 255.
        sN(RRRCRDRt
assertTruet
disconnecting(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt$test_firstBoxFirstKeyExcessiveLengths
	

cCsct}tj|}|j||jd|j|j|jd|j|jdS(s
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        a subsequent key in the first box it receives is larger than 255.
        tkvsN(RRRCRDRtassertFalseRORN(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt)test_firstBoxSubsequentKeyExcessiveLengths	


cCsct}tj|}|j||jd|j|j|jd|j|jdS(s
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        the first key in a subsequent box it receives is larger than 255.
        tkvsN(RRRCRDRRRRORN(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt)test_subsequentBoxFirstKeyExcessiveLengths	


cCstj|}|jt|jd|jttjd|j	j
tj|j|j	j
j|j|j	j
j|j|j	j
j
d|j|j	j
jddS(s
        If L{amp.BinaryBoxProtocol} disconnects because it received a key
        length prefix which was too large, the L{IBoxReceiver}'s
        C{stopReceivingBoxes} method is called with a L{TooLong} failure.
        sssimulated connection doneN(RRCRDRRRRRtConnectionDoneR@ttraptTooLongRNRtisKeyRRtisLocalRERntkeyName(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_excessiveKeyFailures
cCsqt}tj|}|j||jttd|jdt|j	t|j
|jdS(s~
        L{amp.BinaryBoxProtocol.unhandledError} logs the failure passed to it
        and disconnects its transport.
        s
Fake erroriN(RRRCRDRRRRRtflushLoggedErrorsRNRO(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt test_unhandledErrorWithTransports	
cCsttj|}|jt|jttd|jttd|j	dt
|jtdS(s
        L{amp.BinaryBoxProtocol.unhandledError} completes without error when
        there is no associated transport.
        t	Simulateds
Fake erroriN(RRCRDRRRt	ExceptionRRRRR](RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt#test_unhandledErrorWithoutTransports
cCsjtj|}|jtjidd6dd6j|j|jtjidd6dd6gdS(s
        When a binary box protocol receives the serialized form of an AMP box,
        it should emit a similar box to its boxReceiver.
        t	valueTestttestKeytanotherValuet
anotherKeyN(RRCRR(RRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_receiveBoxDatascCsd}d|}t}tj|}|j||jtji|d6j|j|jtji|d6g|j	|j
dS(	s
        An L{amp.BinaryBoxProtocol} can receive serialized AMP boxes with
        values of up to (2 ** 16 - 1) bytes.
        iiiRatkNii(RRRCRDRR(RRRRRRO(RR_RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_receiveLongerBoxDatas
	
#&cCsytj|}|j|tjidd6dd6}|j||j||jdj|j|jdS(s
        When a binary box protocol sends a box, it should emit the serialized
        bytes of that box to its transport.
        RbRcR$tsomeDataR3N(	RRCRDR(RRtjoinRR(RRtaBox((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_sendBox#s



cCsOtj|}|j|tt}|j||j|j|dS(s
        When a binary box protocol loses its connection, it should notify its
        box receiver that it has stopped receiving boxes.
        N(RRCRDRRRRER@(RRtconnectionFailure((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt#test_connectionLostStopSendingBoxes1s


cstdd|dd
fdY}tj|tjidd6dd6}j||jd}j||jj	||j
d	jjd|j
|jdgjd
|j
d	jjd|j
tjj|dS(s
        L{BinaryBoxProtocol} has the capacity to switch to a different protocol
        on a box boundary.  When a protocol is in the process of switching, it
        cannot receive traffic.
        s
outgoing datatSwitchyReceivercs,eZeZdZfdZRS(cSsdS(N((RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRGscs7j|jdt|_jjdS(NsShould only receive one box!(RRtswitchedRIt_lockForSwitcht	_switchTo(RR)(Rt
otherProtoR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRIs
	
(R R!RPRpRR((RRsR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRoEs	tlotstincludeRtoftHello, world!R3s	more datatHello, world!more dataN((RRnRRCR(RDRRRERRRjRRtProtocolSwitchedR(RRot	anyOldBoxtmoreThanOneBox((RRsRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_protocolSwitch=s 




cCsOtj|}|j|tdd}|j||j|jgdS(s
        After switching to a different protocol, if no extra bytes beyond
        the switch box were delivered, an empty string is not passed to the
        switched protocol's C{dataReceived} method.
        R3N(RRCRDRRnRrRR(RRRs((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_protocolSwitchEmptyBufferas


cCstj|}|j|tjidd6}|j|jtj|j||j|j||j	dj
|j|j|jt
dd}|j||jtj|jdS(s8
        In order to make sure the protocol never gets any invalid data sent
        into the middle of a box, it must be locked for switching before it is
        switched.  It can only be unlocked if the switch failed, and attempting
        to send a box while it is locked should raise an exception.
        RtsomeR3s
outgoing dataN(RRCRDR(RqRRyRt_unlockFromSwitchRRjRRRRnRr(RRt	sampleBoxRs((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt test_protocolSwitchInvalidStatesns



"

cCsdtjfdY}|}tj|}|j||j|j|tt}|j	||j
|j|dS(so
        When the protocol is switched, it should notify its nested protocol of
        disconnection.
        tLosercBseZdZdZRS(cSs
||_dS(N(R(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsN(R R!RnRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsN(RtProtocolRRCRDRqRrRRRRR(RRtconnectionLoserRRm((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!test_protocolSwitchLoseConnections	



cCsdddY}tj|}tj}|}|j||j|j||tt}|j	||j
|j|dS(s~
        When the protocol is switched, it should notify its nested client
        protocol factory of disconnection.
        tClientLosercBseZdZdZRS(cSs
||_dS(N(R(RRsR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytclientConnectionLostsN(R R!RnRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsN((RRCRRRDRqRrRRRRR(RRRRtclientLoserRm((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt'test_protocolSwitchLoseClientConnections	


N(R R!R"RRRRnR@RAR8RBRRFRKRMRPRSRUR\R^RaRfRhRlRnR|R}RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR>Ss6																
		
				$	
		tAMPTestcBsjeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZee_d
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ e!e"e"dZ#dZ$e!dZ%d Z&d!Z'd"Z(d#Z)d$Z*RS(%cCsxtjtjftjtjftjtjftjtjftjtjftjtjftjtjfgD]/\}}|j	|j
|d||fqpWdS(s~
        The classes in the amp module ought to implement the interfaces that
        are declared for their benefit.
        s%s does not implements(%s)N(Rt
IBoxSenderRCtIBoxReceiverRtIResponderLocatortCommandLocatortSimpleStringLocatorRt
failUnlesst
implementedBy(Rt	interfacetimplementation((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_interfaceDeclarationsscCs]t\}}}g}d}|j|j|j|j|j|dd|dS(s
        Verify that a simple command can be sent and its response received with
        the simple low-level string-based API.
        R,iR$N(RR'RRRR(RRRRptLtHELLO((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_helloWorlds
cCs]t\}}}g}d}|j|j|j|j|j|dd|dS(s}
        Verify that mixed-case, underscored and dashed arguments are mapped to
        their python names properly.
        R,iR$N(RR'RRRR(RRRRpRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_wireFormatRoundTrips
cCstdtdt\}}}g}d}d}|j||j|j|j|j|dd||j|dd|dS(	sK
        Verify that unicode arguments can be encoded and decoded.
        RRR,swor\u1234ldiR$RN(RRRRRRR(RRRRpRRt
HELLO_UNICODE((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_helloWorldUnicodes
cCs;t\}}}|jddt}|j|ddS(sm
        L{BoxDispatcher.callRemoteString} returns C{None} if C{requiresAnswer}
        is C{False}.
        RTRQN(RR%RPRERn(RRRRptret((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt(test_callRemoteStringRequiresAnswerFalsescCst\}}}g}d}|jdj|j|j|j|j|jdd}|j|j|j|j|j|dd|dS(s
        Verify that unknown commands using low-level APIs will be rejected with an
        error, but will NOT terminate the connection.
        cSs|jtjdS(s:
            You can't propagate the error...
            tOK(RWRtUnhandledCommand(te((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytclearAndAddsRTRR,iR$N(	RR%RRRRRtpopR'(RRRRpRRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_unknownCommandLows	"

cCst\}}}g}d}|jtj|j|j|j|j|jdd}|j	|j|j|j|j|dd|dS(s
        Verify that unknown commands using high-level APIs will be rejected with an
        error, but will NOT terminate the connection.
        cSs|jtjdS(s:
            You can't propagate the error...
            R(RWRR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRR,iR$N(
RRRTRRRRRRR'(RRRRpRRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_unknownCommandHighs	"

cCsfg}tjtjdtjj|j|djtj	|j
dt|djdS(s
        It can be very confusing if you write some code which responds to a
        command, but gets the return value wrong.  Most commonly you end up
        returning None instead of a dictionary.

        Verify that if that happens, the framework logs a useful error.
        RiRnN(
RtdispatchCommandRRRURFRRRWtBadLocalReturntfailUnlessIntreprR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_brokenReturnValues
	"cCsutdtdt\}}}g}d}|jtd|ddj|j|j|j|dd|dS(	s
        Verify that unknown arguments are ignored, and not passed to a Python
        function which can't accept them.
        RRR,R$RSsI'm not in the book!iN(RRRRRRRRR(RRRRpRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_unknownArgument,s	

cCs|jtttjdt|jtttjt|jtttjt|jdttjkdS(sS
        Verify that the various Box objects repr properly, for debugging.
        RRN(	RRRRt
_SwitchBoxRR-RR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_simpleReprs?s%""csmtdd}tj|_fd}|jtt||jtd|j	fdS(sQ
        Verify that L{AMP} objects output their innerProtocol when set.
        s
outgoing datacsid6j|t|S(Ni4(tgettid(tobj(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytfakeIDPss%<AMP inner <TestProto #%d> at 0x1234>N(
RRnRRt
innerProtocolt
addCleanupRRRR(RRsR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_innerProtocolInReprIs	csKtjfd}|jtt||jtddS(sh
        Verify that L{AMP} objects do not output 'inner' when no innerProtocol
        is set.
        csid6j|t|S(Ni!C(RR(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR_ss<AMP at 0x4321>N(RRRRRR(RR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_innerProtocolNotInReprYscCs&|jtttjtdS(s;
        L{amp._TLSBox.__repr__} returns a string.
        N(RRRRt_TLSBoxR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_simpleSSLReprescCst\}}}dd}|jtj|jdid|6}|j|j|j|j|j|j	d|j|j||j
tt|t||j
dt|dS(	sl
        Verify that a key that is too long will immediately raise a synchronous
        exception.
        tHiiR>thiRNi(RRRRXR%RNRYRZRER[RnRRtassertInRRR(RRRRpRattl((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_keyTooLongns
	"cCst\}}}dd}|jtj|j|}|j|j|j|j|j	|j
|jd|j|j
||jtt|t|k|jdt|k|jdt|kdS(ss
        Verify that attempting to send value longer than 64k will immediately
        raise an exception.
        RiiR$RNi(RRRRXR'RtfailIfRYRRZRR[tfailUnlessIdenticalRRRR(RRRRpRaR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_valueTooLongs

%cCsitdtdt\}}}g}d}|j|j|j|j|j|dd|dS(s
        Verify that a simple command can be sent and its response received with
        the high-level value parsing API.
        RRR,iR$N(RRR'RRRR(RRRRpRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_helloWorldCommands
cCsg}tdtdt\}}}d}|j|j|j|j|djt|jt	|dj
ddS(s
        Verify that if a known error type is raised and handled, it will be
        properly relayed to the other end of the connection and translated into
        an exception, and no error will be logged.
        RRsfuck youisDon't be a dick.N(RRR'RRRRWR/RRR(RRRRRpR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_helloErrorHandlings
cCsg}tdtdt\}}}d}|j|j|j|j|jjt|j|j|j|j|jjt	j
dS(s

        Verify that if a known, fatal error type is raised and handled, it will
        be properly relayed to the other end of the connection and translated
        into an exception, no error will be logged, and the connection will be
        terminated.
        RRRN(RRR'RRRRRWR0RRV(RRRRRpR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_helloFatalErrorHandlings

cCsg}tdtdt\}}}t}|j|j|j|j|j}|jt	j
|j|j|j|j}|jtj|j
|jtdS(s
        Verify that if an unknown error type is raised, it will be relayed to
        the other end of the connection and translated into an exception, it
        will be logged, and then the connection will be dropped.
        RRN(RRRR'RRRRRWRtUnknownRemoteErrorRRVRR]Ru(RRRRRpRturetcl((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_helloNoErrorHandlings
cCstdtdt\}}}g}|jtj|j|j|j|g|jj	|j|j
jtj
|jji|jS(s
        Verify that a command that does not get answered until after the
        connection terminates will not cause any errors.
        RR(RRRR[RRRRRtloseConnectionRRWRRVRR(RRRRpR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_lateAnswers


cCsUtdtdt\}}}d}|jtd||j|j|jdS(sG
        Verify that a command that requires no answer is run.
        RRR,R$N(RRRRORRR(RRRRpR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_requiresNoAnswers
cCsg}tdtdt\}}}d}|jtd||j|j|jtjd}|jt	d|j
|j|j|jj
tj|j|jdS(s]
        Verify that commands sent after a failed no-answer request do not complete.
        RRsfuck youR$R,N(RRRRORRR]RtRemoteAmpErrorR>RRRRWRRVRR(RRRRRpR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_requiresNoAnswerFails

cCsgtdtdt\}}}|jtdd|j|jtj}|j	t
|ddS(s+
        Verify that responders of requiresAnswer=False commands have to return
        a dictionary anyway.

        (requiresAnswer is a hint from the _client_ - the server may be called
        upon to answer commands in any case, if the client wants to know when
        they complete.)
        RRR$iN(RRRRRORR]RRRR(RRRRptle((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_noAnswerResponderBadAnswers	
cCstdtdt\}}}g}|jtddj|j|j|jt	|d|j|t
ddddgdS(	s
        Verify that responders with requiresAnswer=False will actually respond
        if the client sets requiresAnswer=True.  In other words, verify that
        requiresAnswer is a hint honored only by the client.
        RRR$sHello!isHello!-noanswerRN(RRRRR>RRRRRRRn(RRRRpR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt$test_noAnswerResponderAskedForAnswer%s
cCstdtdt\}}}g}|jtddj|j|j|jjd}|j	|idd6gddS(	sN
        Test encoding of an argument that uses the AmpList encoding.
        RRR_i
R`iRaN(
RRRR]RRRRRR(RRRRpRR-((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_ampListCommand6s
cCsvtdtdt\}}}g}|jtddj|j|j|jjd}|j	|ddS(s
        Sending a command with an omitted AmpList argument that is
        designated as optional does not raise an InvalidSignature error.
        RRRfupleaseRLslist omittedN(
RRRRdRRRRRR(RRRRpRRL((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_optionalAmpListOmittedDs
cCstdtdt\}}}g}|jtdddidd6gj|j|j|jjd}|j	|d	d
S(sV
        Sanity check that optional AmpList arguments are processed normally.
        RRRfupleaseRgRIR5RLsfoo acceptedN(
RRRRdRRRRRR(RRRRpRRL((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_optionalAmpListPresentSs
cCs|jtjtdS(s~
        Verify that if we pass an invalid argument list (omitting an argument),
        an exception will be raised.
        N(RRtInvalidSignatureR>(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_failEarlyOnArgSendingbscstj}t|tj}t|tdfddfd\}}fd}jj||jjjdS(s
        As a debugging aid, a protocol system should raise a
        L{ProtocolSwitched} exception when asked to switch a protocol that is
        already switched.
        RcsS(N(((tserverProto(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRtsRcsS(N(((tclientProto(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRuscs#jtjjt_dS(N(RRRyRRIt
testSucceeded(R(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRpvsN(	RRRRRRRRR(RtserverDeferredtclientDeferredRRpRp((RRRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_doubleProtocolSwitchjs
c
st_tj|tj|tdfddfd\}}}|rg}|jtj|jn|j	}|rj
tj|j
dnfdfd}	|j|	|jjd
k	r)jjj|jn|rq|rT|jjtjdd	n|jji|jn|jj|jjjd
S(s
        Verify that it is possible to switch to another protocol mid-connection and
        send data to it successfully.
        RcsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRcsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsR,csq|\\}}\}}j|j|jdj|tjdj|tt_dS(NR3(RRRjRRRIR(t.0t
serverSuccesst
serverDatat
clientSuccesst
clientData(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytcbConnsLosts	

cstjgjS(N(RtDeferredListR(R6(RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytcbSwitchstSPURIOUSs,Here's some traffic in the form of an error.N(RPRRRRRR[RRRRRRyR'RRRRnRRRterrbackRRRR(
RtswitchertspuriousTraffict
spuriousErrorRRRptwfdrtswitchDeferredR((RRRRRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR|~s<	






cCs|jdtS(s
        Verify that protocol-switching even works if the value returned from
        the command that does the switch is deferred.
        R(R|R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_protocolSwitchDeferredscst|_tj}||tj}||tdfddfd\}}}g}|jdtj|j|j	|j
jt|j
|j|jdj|j|j	|j|j
dddS(	s
        Verify that if we try to switch protocols and it fails, the connection
        stays up and we can go back to speaking AMP.
        RcsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRcsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRR,R$N(RPRRRRRRIRRRRRWR1RR'RR(RRRRRRRpR((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_protocolSwitchFails	

cCs|jdtS(ss
        Verify that attempts to send traffic after a switch will not corrupt
        the nested protocol.
        R(R|RI(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_trafficAfterSwitchscCs|jdtdtS(sh
        Returning an error after a protocol switch should record the underlying
        error.
        RR(R|RI(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_errorAfterSwitchscCstdtdt\}}}g}d}d}|j|j|j|j|j|jd||jt	j|j|j|j|jd||j|j
|j|jjtj
dS(st
        Verify that commands with a responseType of QuitBox will in fact
        terminate the connection.
        RRR,RR$RXN(RRR'RRRRRRRWRRWRRV(RRRRpRRtGOODBYE((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_quitBoxQuitss

c
Cst\}}}g}|j|_|jtdddddddd|j|jt|d	xId
tjfddddgD])\}}|j|dj	||qW|dj	d
|j|didS(s
        Verify that the command dictionaries for a callRemoteN look correct
        after being serialized and parsed.
        R$s
hello testRBsmixed case arg testRRaRCtyiRsdash-argiRN(R$s
hello test(RBsmixed case arg test(sdash-argRa(RCR(
RRRRR>RRRRFR(RRRRpRRgR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_basicLiteralEmits

!csgdtjffdY}td|\}}}|jtdddddd	d
djj|j|jt	d|jd
dt
dddddd	d
dddddddf|jdt
dddddS(s
        Verify that a call similar to basicLiteralEmit's is handled properly with
        high-level quoting and passing to Python methods, and that argument
        names are correctly handled.
        tStructuredHellocs$eZfdZejeRS(cs j||ftddS(NR$taaa(RR(RRRg(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyths(R R!RR>R~((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRR$s
hello testRBsmixed case arg testRRaRCRiiRtfileRR?iRN((sfilesfile(RRRRR>RRRRRRRn(RRRRRp((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_basicStructuredEmits"

	
(+R R!RRRRRRRRRRRRRtskipSSLtskipRRRRRRRRRRRRRRRRRRPR|RRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsP		
	
		
					
												
								5						t!PretendRemoteCertificateAuthoritycBseZdZRS(cCstS(N(RI(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytcheckIsPretendRemote5s(R R!R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR4st	IOSimCertcBs eZdZdZdZRS(icGs|S(N((RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytoptions;scCs%||kst|jd7_tS(s
        This isn't a real certificate, and wouldn't work on a real socket, but
        iosim specifies a different API so that we don't have to do any crypto
        math to demonstrate that the right functions get called in the right
        places.
        i(RtverifyCountRI(Rt	otherCert((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytiosimVerify>s(R R!RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR8s	tOKCertcBseZdZRS(cCs|jst|S(N(RR(RRa((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRJs(R R!R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRIst
GrumpyCertcBseZdZRS(cCs|jd7_tS(Ni(RRP(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyROs(R R!R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRNst
DroppyCertcBseZdZdZRS(cCs
||_dS(N(ttoDrop(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRTscCs |jd7_|jjtS(Ni(RRRRI(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRWs
(R R!RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRSs	tSecurableProtocBs0eZdZdZdZejjeRS(cCs
tgS(N(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
verifyFactory`scCs+|j}|j}td|d|S(Nttls_localCertificatettls_verifyAuthorities(tcertFactoryRR(Rtcerttverify((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
getTLSVarscs
N(	R R!RnRmRRRtStartTLSR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR\s		tTLSTestcBs2eZdZdZdZdZeZRS(cstdtdt\}}}tfd|_|jtjddtgg}|jtj	|j
|j|jj
dg}|jtj	|j
|j|j|ditd6d	S(
s
        Verify that starting TLS and succeeding at handshaking sends all the
        notifications to all the right places.
        RRcsS(N(((tokc(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRxsRRiiRiN(RRRRRRR	RRhRRRRRRI(RtclitsvrRpR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_startingTLSns 	


cstdtdt\}}}tfd|_|jtjddtg|jt	|_
|jtj|jtjddtgdS(sz
        Verify that the protocol will complain if we attempt to renegotiate TLS,
        which we don't support.
        RRcsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRRN(
RRRRRRR	RRRItnoPeerCertificateRt
OnlyOneTLS(RRR
Rp((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_startTooManyTimess 	

		csttdtdt\}}}fd|_|jtjd|j|jj	d|jt
}|j|j|tj
dS(s
        Verify that starting TLS and failing on both sides at handshaking sends
        notifications to all the right places and terminates the connection.
        RRcsS(N(((tbadCert(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRiN(RRRRRRR	RRRRht
assertFailureRtNativeOpenSSLError(RRR
RpR4((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_negotiationFaileds	

cstdtdt\}}}t|jfd|_|jtjd|j|j	j
d|jt}|j|j|t
jdS(s
        Verify that starting TLS and failing by way of a lost connection
        notices that it is probably an SSL problem.
        RRcsS(N(((t
droppyCert(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRiN(RRRRRRRR	RRRRhRRtPeerVerifyError(RRR
RpR4((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_negotiationFailedByClosings

(R R!RRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
ms
				tTLSNotAvailableTestcBs2eZdZdZdZdZdZRS(sP
    Tests what happened when ssl is not available in current installation.
    cCstj|_dt_dS(s%
        Disable ssl in amp.
        N(RR
Rn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscCs|jt_dS(s%
        Restore ssl module.
        N(R
R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttearDownscsgtdtdt\}}}tfd|_|j|jtjddtgt	S(sg
        Check that callRemote raises an exception when called with a
        L{amp.StartTLS}.
        RRcsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsRR(
RRRRRRRR	RR(RRR
Rp((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_callRemoteErrors	cst}tfd|_tj}d|d<d|d<g}|j|_|jt|j	||j
|idd6dd6d	d
6gdS(s|
        When a client with SSL enabled talks to a server without SSL, it
        should return a meaningful error.
        csS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsR	RRRt	TLS_ERRORRRsTLS not availableRN(RRRRR(RRRDRRR(RR
R)R((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_messageReceivedErrors		


	
(R R!R"RRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
			tInheritedErrorcBseZdZRS(s2
    This error is used to check inheritance.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRstOtherInheritedErrorcBseZdZRS(s<
    This is a distinct error for checking inheritance.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRstBaseCommandcBseZdZide6ZRS(s:
    This provides a command that will be subclassed.
    tINHERITED_ERROR(R R!R"RRM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR "stInheritedCommandcBseZdZRS(s`
    This is a command which subclasses another command but does not override
    anything.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR"*stAddErrorsCommandcBs0eZdZdejfgZide6ZRS(s]
    This is a command which subclasses another command but adds errors to the
    list.
    tothertOTHER_INHERITED_ERROR(R R!R"RRHRKRRM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR#2stNormalCommandProtocolcBs$eZdZdZejeRS(s
    This is a protocol which responds to L{BaseCommand}, and is used to test
    that inheritance does not interfere with the normal handling of errors.
    cCs
tdS(N(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytrespAs(R R!R"R'R R~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR&<s	tInheritedCommandProtocolcBs$eZdZdZejeRS(s
    This is a protocol which responds to L{InheritedCommand}, and is used to
    test that inherited commands inherit their bases' errors if they do not
    respond to any of their own.
    cCs
tdS(N(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR'Ms(R R!R"R'R"R~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR(Gs	tAddedCommandProtocolcBs$eZdZdZejeRS(s
    This is a protocol which responds to L{AddErrorsCommand}, and is used to
    test that inherited commands can add their own new types of errors, but
    still respond in the same way to their parents types of errors.
    cCs|rtn	tdS(N(RR(RR$((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR'Ys(R R!R"R'R#R~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR)Ss	tCommandInheritanceTestscBs;eZdZdZdZdZdZdZRS(sM
    These tests verify that commands inherit error conditions properly.
    c
KsPtd|d|\}}}|j||}|j||}	|j|	S(s~
        Check that the appropriate kind of error is raised when a given command
        is sent to a given protocol.
        RR(RRtfailUnlessFailureR(
RRR6tcmdRRRRpR4td2((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
errorCheckgs
cCs|jtttS(sx
        Verify that errors specified in a superclass are respected normally
        even if it has subclasses.
        (R.RR&R (R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_basicErrorPropagationtscCs|jtttS(sp
        Verify that errors specified in a superclass command are propagated to
        its subclasses.
        (R.RR(R"(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_inheritedErrorPropagation}scCs|jtttdtS(s
        Verify that new errors specified in a subclass of an existing command
        are honored even if the superclass defines some errors.
        R$(R.RR)R#RI(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_inheritedErrorAdditionscCs|jtttdtS(s
        Verify that errors specified in a command's superclass are respected
        even if that command defines new errors itself.
        R$(R.RR)R#RP(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_additionWithOriginalErrors(R R!R"R.R/R0R1R2(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR*bs	
						cCs-|jtjtj|`|j|dS(N(RWRtConnectionLostRVR(RR6((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt_loseAndPassstLiveFireBasecBs eZdZdZdZRS(s4
    Utility for connected reactor-using tests.
    csddlm}tj_jj_tj_jj_t	j
j_t	j
j_|jdj_
jj
j|jdj
jjj_jjjfd}t	jjjjjg}|j|S(sB
        Create an amp server and connect a client to it.
        i(R	is	127.0.0.1cs"jj_jj_dS(N(t
clientFactoryRxRt
serverFactoryR
(trlst(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	getProtoss(ttwisted.internetR	Rt
ServerFactoryR7Rt
ClientFactoryR6RRRRwt	listenTCPt
serverPortRt
stopListeningt
connectTCPRBtportt
clientConnt
disconnectRR(RR	R9tdl((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs"cCsg}xj|j|jfD]V}|jdk	rtjjt|}|j|_	|jj
|j|qqWtj|jdS(sn
        Cleanup client and server connections, and check the error got at
        C{connectionLost}.
        cSs
|jjS(N(Rt
subFailure(tfirst((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsN(
RR
RRnRRRR4RRRRt
gatherResults(RRtconnR4((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
(R R!R"RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR5s	cCs1ddl}|jj|d|jjdS(Nis
(tsyststdoutRR(RaRI((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytshowscCsnddlm}|jdd}|jj}|j|}|j||dd}|j|}|S(Ni(R
tCNtsharedcSstS(N(RI(tdn((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRsi(R:R
tDNtKeyPairtgeneratetcertificateRequesttsignCertificateRequesttnewCertificate(R
tsharedDNRtcrtsscrdR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttempSelfSignedstLiveFireTLSTestCasecBs#eZeZeZdZeZRS(csmtfdj_fdj_fd}jjtjddgj|S(sH
        Using real, live TLS, actually negotiate a connection.

        This also looks at the 'peerCertificate' attribute's correctness, since
        that's actually loaded using OpenSSL calls, but the main purpose is to
        make sure that we didn't miss anything obvious in iosim about TLS
        negotiations.
        csgS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscsS(N(((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRscs7jfd}jjtj|S(NcstjjjjjjjjjjjjjjjjdS(N(RRthostCertificatetdigesttpeerCertificateR
(trslt2(RaR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRis(R[RRRhR(trsltRi(RR(Ras9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytsecureds	RR(	ttempcertR
RRRRRR	R(RR_((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_liveFireCustomTLSs
(R R!RRRRaRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRYs	 tSlightlySmartTLScBs'eZdZdZejjeRS(s_
    Specific implementation of server side protocol with different
    management of TLS.
    cCs
tdtS(sS
        @return: the global C{tempcert} certificate as local certificate.
        R(RR`(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR	s(R R!R"RRR	R~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRb		s	tPlainVanillaLiveFirecBs#eZeZeZdZeZRS(cs+fd}jjtjj|S(s
        Verify that out of the box, we can start TLS to at least encrypt the
        connection, even if we don't have any certificates to use.
        csjjtS(N(RRRh(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR_ 	s(RRRR	R(RR_((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_liveFireDefaultTLS	s(R R!RRRRdRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRc	s		tWithServerTLSVerificationcBs#eZeZeZdZeZRS(cs4fd}jjtjdtgj|S(sO
        Verify that anonymous clients can verify server certificates.
        csjjtS(N(RRRh(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR_0	sR(RRRR	R`R(RR_((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_anonymousVerifyingClient,	s(	R R!RRRbRRfRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRe(	s	
tProtocolIncludingArgumentcBs eZdZdZdZRS(s
    An L{amp.Argument} which encodes its parser and serializer
    arguments *including the protocol* into its parsed and serialized
    forms.
    cCs
||fS(s
        Don't decode anything; just return all possible information.

        @return: A two-tuple of the input string and the protocol.
        ((RtstringR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR:A	scCsdt|t|fS(s
        Encode identifying information about L{object} and protocol
        into a string for later verification.

        @type obj: L{object}
        @type protocol: L{amp.AMP}
        s%s:%s(R(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
toStringProtoI	s(R R!R"R:Ri(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRg:	s	tProtocolIncludingCommandcBs2eZdZdefgZdefgZRS(sf
    A command that has argument and response schemas which use
    L{ProtocolIncludingArgument}.
    tweird(R R!R"RgRKRL(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRjU	stMagicSchemaCommandcBsMeZdZdZeeZdZeeZdZeeZRS(sa
    A command which overrides L{parseResponse}, L{parseArguments}, and
    L{makeResponse}.
    cCs||f|_|S(s
        Don't do any parsing, just jam the input strings and protocol
        onto the C{protocol.parseResponseArguments} attribute as a
        two-tuple. Return the original strings.
        (tparseResponseArguments(RR;R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
parseResponsed	scCs||f|_|S(s
        Don't do any parsing, just jam the input strings and protocol
        onto the C{protocol.parseArgumentsArguments} attribute as a
        two-tuple. Return the original strings.
        (tparseArgumentsArguments(tclsR;R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytparseArgumentso	scCs||f|_|S(s
        Don't do any serializing, just jam the input strings and protocol
        onto the C{protocol.makeArgumentsArguments} attribute as a
        two-tuple. Return the original strings.
        (tmakeArgumentsArguments(RpR<R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
makeArgumentsz	s(R R!R"RntclassmethodRqRs(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRl_	s			tNoNetworkProtocolcBs'eZdZdZejdRS(s
    An L{amp.AMP} subclass which overrides private methods to avoid
    testing the network. It also provides a responder for
    L{MagicSchemaCommand} that does nothing, so that tests can test
    aspects of the interaction of L{amp.Command}s and L{amp.AMP}.

    @ivar parseArgumentsArguments: Arguments that have been passed to any
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.

    @ivar parseResponseArguments: Responses that have been returned from a
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.

    @ivar makeArgumentsArguments: Arguments that have been serialized by any
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.
    cCs
tj|S(sJ
        Return a Deferred which fires with the original strings.
        (Rtsucceed(RRFR;RQ((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt_sendBoxCommand	scCsiS(N((RRk((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR	s(R R!R"RwRlR~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRu	s	tMyBoxcBseZdZRS(s!
    A unique dict subclass.
    (R R!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRx	st0ProtocolIncludingCommandWithDifferentCommandTypecBseZdZeZRS(sN
    A L{ProtocolIncludingCommand} subclass whose commandType is L{MyBox}
    (R R!R"RxtcommandType(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRy	stCommandTestCasecBsheZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZRS(s7
    Tests for L{amp.Argument} and L{amp.Command}.
    cCs#|jttjtjdS(sE
        L{Argument} instances provide L{amp.IArgumentType}.
        N(RNRRt
IArgumentTypetArgument(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_argumentInterface	scCsIt}d}i|d6}|jtj||i||fd6dS(s
        There should be a class method of Command which accepts a
        mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        Command's response schema.
        twhateverRkN(R&RRjRn(RRRR;((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_parseResponse	s	
csJtdjtd}fd}|j||S(s
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseResponse} method should call that
        C{parseResponse} method to get the response.
        tweeooRkcs$jjid6fdS(NRk(RRm(R(Rtclienttthingy(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytgotResponse	s(RuRRlR(RRLR((RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!test_callRemoteCallsParseResponse	s	
cCsIt}d}i|d6}|jtj||i||fd6dS(s
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        command's argument schema.
        RRkN(R&RRjRq(RRRR;((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_parseArguments	s	
csYtjtj}t|td}|jfd|S(s
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseArguments} method should call that
        C{parseArguments} method to get the arguments.
        Rkcs jjid6fS(NRk(RRo(R(RRtargument(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR	s(RuRRlRFR&RR(RR~RL((RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!test_responderCallsParseArguments	s		cCs\t}t}i|d6}|jtj||idt|t|fd6dS(s
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to objects and returns a similar
        mapping whose values have been serialized via the command's
        argument schema.
        Rks%d:%dN(R&RRjRsR(RRRR<((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_makeArguments	s		
cCsBt}idd6}tj||}|jt|tdS(s
        L{amp.Command.makeArguments}'s return type should be the type
        of the result of L{amp.Command.commandType}.
        RRkN(R&RyRsRERRx(RRR<R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!test_makeArgumentsUsesCommandType
s
	
csMttjtd}fd}|j||S(s
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{makeArguments} method should call that
        C{makeArguments} method to get the response.
        Rkcs$jjid6fdS(NRk(RRr(R(RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR!
s(RuR&RRlR(RRLR((RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt!test_callRemoteCallsMakeArguments
s		
cCs2|jtjtjtdddtddS(s
        L{Command.makeArguments} raises L{amp.InvalidSignature} if the objects
        dictionary passed to it includes a key which does not correspond to the
        Python identifier for a defined argument.
        R$t
bogusArgumentN(RRRR>RsRR&Rn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_extraArgumentsDisallowed(
sc	Cs3|jtjtjtddidd6ddS(s
        If a command argument conflicts with a Python keyword, the
        untransformed argument name is not allowed as a key in the dictionary
        passed to L{Command.makeArguments}.  If it is supplied,
        L{amp.InvalidSignature} is raised.

        This may be a pointless implementation restriction which may be lifted.
        The current behavior is tested to verify that such arguments are not
        silently dropped on the floor (the previous behavior).
        R$trequiredsprint valueR@N(RRRR>RsRRn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_wireSpellingDisallowed4
s
(
R R!R"R~RRRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR{	s							
		tListOfTestsMixincBs eZdZdZdZRS(s
    Base class for testing L{ListOf}, a parameterized zero-or-more argument
    type.

    @ivar elementType: Subclasses should set this to an L{Argument}
        instance.  The tests will make a L{ListOf} using this.

    @ivar strings: Subclasses should set this to a dictionary mapping some
        number of keys to the correct serialized form for some example
        values.  These should agree with what L{elementType}
        produces/accepts.

    @ivar objects: Subclasses should set this to a dictionary with the same
        keys as C{strings} and with values which are the lists which should
        serialize to the values in the C{strings} dictionary.
    cCshtj|j}tj}x0|jD]%}|j|||jjdq(W|j||j	dS(s
        L{ListOf.toBox} extracts the list of objects from the C{objects}
        dictionary passed to it, using the C{name} key also passed to it,
        serializes each of the elements in that list using the L{Argument}
        instance previously passed to its initializer, combines the serialized
        results, and inserts the result into the C{strings} dictionary using
        the same C{name} key.
        N(
RtListOftelementTypeRR<R=tcopyRnRR;(Rt
stringListR;R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
test_toBoxW
s
	#cCsbtj|j}i}x0|jD]%}|j||jj|dq"W|j||jdS(sX
        L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
        N(	RRRR;tfromBoxRRnRR<(RRR<R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_fromBoxg
s
#(R R!R"RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRF
s	tListOfStringsTestscBs\eZdZejZidd6dd6dd6Zigd6dgd6dd	d
gd6ZRS(s:
    Tests for L{ListOf} combined with L{amp.String}.
    R3temptytfootsingletbarbazquuxtmultipleRIRHtbaztquux(R R!R"RRGRR;R<(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
s

tListOfIntegersTestscBseZdZejZdZidd6dd6dd6defd	6d
d6Zigd6dgd6d
ddgd6egd	6dgd6ZRS(s;
    Tests for L{ListOf} combined with L{amp.Integer}.
    l
]OSt7s
Xg&}R3Rt10Rt120500Rtt%dthuget-1tnegativei
iiiil@[D`Y[[V{!Zyz_dr~saFo$wo536(	R R!R"RRbRRR;R<(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
s 


tListOfUnicodeTestscBs\eZdZejZidd6dd6dd6Zigd6dgd6dd	d
gd6ZRS(s;
    Tests for L{ListOf} combined with L{amp.Unicode}.
    R3RRRt☃HelloworldRufoou☃uHellouworld(R R!R"RRJRR;R<(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
s

tListOfDecimalTestscBseZdZejZidd6dd6dd6dd6d	ejd
jejdjfd6Zigd6ejd
gd6ejdejdgd6ejdejdejdejdejdejdgd6ejd
ejdgd6Z	RS(s;
    Tests for L{ListOf} combined with L{amp.Decimal}.
    R3Rt1.1RtInfinity	-InfinitytextremetC3.141E+5
0.000031413.141E-7	-3.141E+5-0.00003141	-3.141E-7t	scientistt%s%st0e6s1.5E-9tengineers1.1tInfinitys	-Infinitys3.141E5s3.141e-5s3.141E-7s-3.141e5s	-3.141E-5s	-3.141e-7(
R R!R"RtDecimalRtdecimalt
to_eng_stringR;R<(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
s.tListOfDecimalNanTestscBsmeZdZejZidd6Ziejdejdejdejdgd6ZdZ	RS(sS
    Tests for L{ListOf} combined with L{amp.Decimal} for not-a-number values.
    tNaN-NaNsNaN-sNaNtnantNaNs-NaNtsNaNs-sNaNcCsd}d}d}tj|j}i}x0|jD]%}|j||jj|d	q=W|d}|j||do||d|j||do||d|j||do||d|j||do
||dd	S(
sX
        L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
        cSs"dt|ko!dt|kS(NRR(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytis_qnan
scSsdt|kS(NR(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pytis_snan
scSsdt|kS(Nt-(R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt	is_signed
sRiiiiN(RRRR;RRRnRN(RRRRRR<Rtn((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
s			#
('((
R R!R"RRRR;RR<R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
s
tDecimalTestscBseZdZdZRS(s#
    Tests for L{amp.Decimal}.
    cCsRtj}|jt|jd|jt|jd|jt|jddS(s
        L{amp.Decimal.toString} raises L{ValueError} if passed an object which
        is not an instance of C{decimal.Decimal}.
        s1.234gX9v?iN(RRRt
ValueErrorR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_nonDecimals(R R!R"R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyR
stListOfDateTimeTestscBseZdZejZidd6dd6dd6dd6d	d
6Ziejddd
ddddejejddd
ddddej	dddgd6ejddd
ddddej	dddgd6ejddd
ddddej	dddgd6ejddd
ddddej	dddgd6ejddd
ddddej	dddejddd
ddddej	dddgd
6Z
RS(s<
    Tests for L{ListOf} combined with L{amp.DateTime}.
    tD 2010-12-25T00:00:00.000000-00:00 2010-12-25T00:00:00.000000-00:00t	christmast" 2010-12-25T00:00:00.000000+01:00schristmas in eut" 2010-12-25T00:00:00.000000+03:30schristmas in irant" 2010-12-25T00:00:00.000000-05:00schristmas in nyctD 2010-12-25T00:00:00.000000+03:19 2010-12-25T00:00:00.000000-06:59sprevious testsiiiittzinfot+iiiRiiii;(R R!R"RtDateTimeRR;tdatetimetutct_FixedOffsetTZInfoR<(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs,
$tListOfOptionalTestscBs;eZdZdZdZdZdZdZRS(so
    Tests to ensure L{ListOf} AMP arguments can be omitted from AMP commands
    via the 'optional' flag.
    cCsEtjtj}|jt|jdtjidd6ddS(sn
        L{ListOf.toBox} raises C{TypeError} when passed a value of C{None}
        for the argument.
        tomittedN(RRRbRRR=RRn(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt1test_requiredArgumentWithNoneValueRaisesTypeErrorOscCsXtjtjdt}tj}|jd|idd6d|j|idS(s
        L{ListOf.toBox} silently omits serializing any argument with a
        value of C{None} that is designated as optional for the protocol.
        R?RN(RRRbRIRR=RnR(RRR;((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt)test_optionalArgumentWithNoneValueOmittedZscCsEtjtj}|jt|jdtjidd6ddS(s|
        L{ListOf.toBox} raises C{KeyError} if the argument's key is not
        present in the objects dictionary.
        tommiteditsomeOtherKeyN(RRRbRtKeyErrorR=RRn(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt1test_requiredArgumentWithKeyMissingRaisesKeyErrorescCsBtjtjdt}|jdtjidd6ddS(s
        L{ListOf.toBox} silently omits serializing any argument designated
        as optional whose key is not present in the objects dictionary.
        R?RiRN(RRRbRIR=RRn(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt*test_optionalArgumentWithKeyMissingOmittedpscCsRtjtjdt}i}|jdi|d|j|idd6dS(s
        L{ListOf.fromBox} correctly reverses the operation performed by
        L{ListOf.toBox} for optional arguments.
        R?RN(RRRbRIRRnR(RRR<((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt.test_omittedOptionalArgumentDeserializesAsNoneys(R R!R"RRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRJs					t
DateTimeTestsc	BsqeZdZdZejdddZejddddddd	eZd
Z	dZ
dZd
ZRS(sO
    Tests for L{amp.DateTime}, L{amp._FixedOffsetTZInfo}, and L{amp.utc}.
    s 9876-01-23T12:34:56.054321-01:23Riii&ii"i8i1cCs&tj}|jt|jddS(s
        L{amp.DateTime.fromString} raises L{ValueError} when passed a string
        which does not represent a timestamp in the proper format.
        tabcN(RRRRR(RR4((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_invalidStringsc
Cs>tj}|jt|jtjdddddddS(s
        L{amp.DateTime.toString} raises L{ValueError} when passed a naive
        datetime (a datetime with no timezone information).
        iiiiN(RRRRRR(RR4((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_invalidDatetimescCs5tj}|j|j}|j||jdS(s
        L{amp.DateTime.fromString} returns a C{datetime.datetime} with all of
        its fields populated from the string passed to it.
        N(RRRRhRR&(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_fromStringscCs5tj}|j|j}|j||jdS(s
        L{amp.DateTime.toString} returns a C{str} in the wire format including
        all of the information from the C{datetime.datetime} passed into it,
        including the timezone offset.
        N(RRRR&RRh(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt
test_toStrings(
R R!R"RhRRRRR&RRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs$			
	
tFixedOffsetTZInfoTestscBs2eZdZdZdZdZdZRS(s=
    Tests for L{amp._FixedOffsetTZInfo} and L{amp.utc}.
    cCs |jtjjdddS(s8
        L{amp.utc.tzname} returns C{"+00:00"}.
        s+00:00N(RRRttznameRn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_tznamescCs)|jtjjdtjddS(s:
        L{amp.utc.dst} returns a zero timedelta.
        iN(RRRtdstRnRt	timedelta(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_dstscCs)|jtjjdtjddS(s@
        L{amp.utc.utcoffset} returns a zero timedelta.
        iN(RRRt	utcoffsetRnRR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_utcoffsetscCs |jttjddddS(s~
        L{amp._FixedOffsetTZInfo} raises L{ValueError} if passed an offset sign
        other than C{'+'} or C{'-'}.
        t?iN(RRRR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyttest_badSigns(R R!R"RRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyRs
			s2This test case requires SSL support in the reactor(R"RRtzope.interface.verifyRttwisted.python.utilRttwisted.pythonRttwisted.python.failureRttwisted.protocolsRt
twisted.trialRR:RRRR	R
ttwisted.testRttwisted.test.proto_helpersRRnR
tImportErrort	supportedRRRRR#R`R/R0R1R}R2tCommandR>RORRRTRURWRZR[R]RdRhtProtocolSwitchCommandRjR<RlRRuRvRRRRRRRtTestCaseRRR&RRRRRRR"R#R$R+RRR>RRRRRRRR
RRRR R"R#R&R(R)R*R4R5RKRXR`RYRbRcReRgRjRlRuRRxRyR{RRRRRRRRRRRtIReactorSSLR|tskipMsgR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_amp.pyt<module>s(
		-L	
I)YY	k<
6	.		'

'-,1-;1#