+
    Dfjhw                        R t ^ RIt^ RIHtHt ^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHtHt ^ RIHtHtHtHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHt ^ RIHtHtHtH t H!t! ^ RI"H#t# ^ RI$H%t%H&t&H't'H(t(H)t)H*t*  ]! R4       Rt+ ! R R]PZ                  4      t. ! R R]/4      t0 ! R R]14      t2 ! R R]%4      t3 ! R R]%4      t4 ! R R]%4      t5 ! R R]34      t6 ! R  R!]!Pn                  4      t8 ! R" R#]!PL                  4      t9 ! R$ R%]!PL                  4      t: ! R& R']PZ                  4      t; ! R( R)];4      t< ! R* R+]PZ                  4      t= ! R, R-4      t> ! R. R/]>]PZ                  4      t? ! R0 R1]>]PZ                  4      t@ ! R2 R3];4      tA ! R4 R5];4      tB ! R6 R7]PZ                  4      tC ! R8 R9]PZ                  4      tD ! R: R;]PZ                  4      tER#   ], d    Rt+ ELdi ; i)<z6
Tests for  XML-RPC support in L{twisted.web.xmlrpc}.
N)BytesIOStringIO)skipIf)deferreactor)ConnectionDone)EventLoggingObserverMemoryReactor)FilteringLogObserverLogLevelLogLevelFilterPredicateglobalLogPublisher)failure)nativeStringnetworkString)namedModule)unittest)clienthttpserverstaticxmlrpc)DummyRequest)XMLRPCQueryFactoryaddIntrospectionpayloadTemplatewithRequest	xmlrpclibztwisted.internet.sslFTc                   6   a  ] tR t^.t o RtR tR tR tRtV t	R# )AsyncXMLRPCTestsz-
Tests for L{XMLRPC}'s support of Deferreds.
c                6  a \        R .4      V n        RV P                  n        \        \        R\
        P                  ! R4      3,          4      V P                  n        \        P                  ! 4       ;oV n
         ! V3R lR\        4      pV! 4       V n        R# ) POSTasyncc                   .   <a  ] tR t^<t o V3R ltRtV tR# )-AsyncXMLRPCTests.setUp.<locals>.AsyncResourcec                   < S# N )selfresults   &>/usr/lib/python3/dist-packages/twisted/web/test/test_xmlrpc.pyxmlrpc_async:AsyncXMLRPCTests.setUp.<locals>.AsyncResource.xmlrpc_async=   s        r)   N)__name__
__module____qualname____firstlineno__r-   __static_attributes____classdictcell__)__classdict__r+   s   @r,   AsyncResourcer&   <   s      r/   r7   Nr)   )r   requestmethodr   r   r   dumpscontentr   Deferredr+   r   resource)r*   r7   r+   s   & @r,   setUpAsyncXMLRPCTests.setUp3   sp    #RD)$'w	(;<< 
  %~~//	F 	 &r/   c                   V P                   P                  V P                  4       V P                  V P                  P                  . 4       V P
                  P                  R4       \        P                  ! RP                  V P                  P                  4      4      pV P                  VR4       V P                  V P                  P                  ^4       R# )z
If an L{XMLRPC} C{xmlrpc_*} method returns a L{defer.Deferred}, the
response to the request is the result of that L{defer.Deferred}.
r+   r/   N))r+   N)r=   renderr8   assertEqualwrittenr+   callbackr   loadsjoinfinished)r*   resps   & r,   test_deferredResponse&AsyncXMLRPCTests.test_deferredResponseB   s    
 	T\\*--r2X&sxx(<(<=>23..2r/   c                   V P                   P                  V P                  4       V P                  P                  \        P
                  ! \        R4      4      4       V P                  P                  R4       V P                  V P                  P                  . 4       V P                  V P                  P                  ^ 4       R# )z
While waiting for the L{Deferred} returned by an L{XMLRPC} C{xmlrpc_*}
method to fire, the connection the request was issued over may close.
If this happens, neither C{write} nor C{finish} is called on the
request.
	Simulatedr+   N)r=   rA   r8   processingFailedr   Failurer   r+   rD   rB   rC   rG   r*   s   &r,    test_interruptedDeferredResponse1AsyncXMLRPCTests.test_interruptedDeferredResponseP   s     	T\\*%%goon[6Q&RSX&--r2..2r/   )r8   r=   r+   N)
r0   r1   r2   r3   __doc__r>   rI   rP   r4   r5   r6   s   @r,   r    r    .   s     (33 3r/   r    c                       ] tR t^^tRtR# )TestRuntimeErrorr)   Nr0   r1   r2   r3   r4   r)   r/   r,   rU   rU   ^       r/   rU   c                       ] tR t^btRtR# )TestValueErrorr)   NrV   r)   r/   r,   rY   rY   b   rW   r/   rY   c                      a  ] tR t^ft o Rt^t^*tR tR t. RO. RO.]n	        R t
. RO.]
n	        R tR tR tR tR	 tR
 tR tR tR]n        ]R 4       tR tRtV tR# )Test  c                    V# r(   r)   )r*   args   &&r,   xmlrpc_echoTest.xmlrpc_echon   s    
r/   c                    W,           # )z 
This function add two numbers.
r)   )r*   abs   &&&r,   
xmlrpc_addTest.xmlrpc_addr   s     ur/   c                    W.# )z3
This function puts the two arguments in an array.
r)   )r*   stringnums   &&&r,   xmlrpc_pairTest.xmlrpc_pair~   s     }r/   c                .    \         P                  ! V4      # )Help for defer.)r   succeedr*   xs   &&r,   xmlrpc_deferTest.xmlrpc_defer   s    }}Qr/   c                >    \         P                  ! \        4       4      # r(   )r   failrY   rO   s   &r,   xmlrpc_deferFailTest.xmlrpc_deferFail   s    zz.*++r/   c                    \         hr(   )rU   rO   s   &r,   xmlrpc_failTest.xmlrpc_fail   s    r/   c                0    \         P                  ! ^R4      # )   hellor   FaultrO   s   &r,   xmlrpc_faultTest.xmlrpc_fault   s    ||B((r/   c                X    \         P                  ! \        P                  ! ^R4      4      # )   hi)r   rs   r   r}   rO   s   &r,   xmlrpc_deferFaultTest.xmlrpc_deferFault   s    zz&,,r4011r/   c                D    RpW!8w  d   \         P                  ! ^R4      # V# )z(
Used to test that we can pass Unicode.
   ☃zPayload not unicode snowmanr|   )r*   payloadsnowmans   && r,   xmlrpc_snowmanTest.xmlrpc_snowman   s&     <<$ABBr/   c                    R RR^. .RR/# )rb   rc   cDfoor)   rO   s   &r,   xmlrpc_complexTest.xmlrpc_complex   s    c3B'e44r/   c                    W,          # r(   r)   )r*   mapkeys   &&&r,   xmlrpc_dictTest.xmlrpc_dict   s	    xr/   Help for dict.c                6    VP                   R,           V,           # )z
A method decorated with L{withRequest} which can be called by
a test to verify that the request object really is passed as
an argument.
 )r9   )r*   r8   others   &&&r,   xmlrpc_withRequestTest.xmlrpc_withRequest   s$     NN  		
r/   c                     \         P                  ! W4      #   \        P                   d;    TP	                  R 4      '       d"   \        P
                  ! T P                  R4      hh i ; i)SESSIONzSession non-existent/expired.)r   lookupProcedurer   NoSuchFunction
startswithr}   SESSION_EXPIRED)r*   procedurePaths   &&r,   r   Test.lookupProcedure   s`    	))$>>$$ 	''	22ll((*I  	s    +A'#A'r)   Nintr   r   doubler   r   arrayrg   r   )r0   r1   r2   r3   FAILURE	NOT_FOUNDr   r_   rd   	signatureri   rp   rt   rw   r~   r   r   r   r   helpr   r   r   r4   r5   rS   s   @r,   r[   r[   f   s      GIO 	&J 88K ,)25 (K
 
	 	r/   r[   c                   0   a  ] tR t^t o RtR tR tRtV tR# )TestLookupProcedurezq
This is a resource which customizes procedure lookup to be used by the tests
of support for this customization.
c                    V# r(   r)   rn   s   &&r,   echoTestLookupProcedure.echo   s    r/   c                r    VR8X  d   V P                   # \        P                  ! V P                  RV R24      h)z[
Lookup a procedure from a fixed set of choices, either I{echo} or
I{system.listeMethods}.
r   z
procedure z
 not found)r   r   r   r   )r*   procedureNames   &&r,   r   #TestLookupProcedure.lookupProcedure   s;    
 F"99##NNjzB
 	
r/   r)   N)	r0   r1   r2   r3   rR   r   r   r4   r5   rS   s   @r,   r   r      s     
	
 	
r/   r   c                   *   a  ] tR t^t o RtR tRtV tR# )TestListProcedureszv
This is a resource which customizes procedure enumeration to be used by the
tests of support for this customization.
c                    R.# )zG
Return a list of a single method this resource will claim to support.
r   r)   rO   s   &r,   listProcedures!TestListProcedures.listProcedures   s     wr/   r)   N)r0   r1   r2   r3   rR   r   r4   r5   rS   s   @r,   r   r      s     
 r/   r   c                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )TestAuthHeaderzI
This is used to get the header info so that we can test
authentication.
c                >    \         P                  V 4       R V n        R # r(   )r[   __init__r8   rO   s   &r,   r   TestAuthHeader.__init__   s    dr/   c                8    Wn         \        P                  W4      # r(   )r8   r[   rA   )r*   r8   s   &&r,   rA   TestAuthHeader.render   s    {{4))r/   c                j    V P                   P                  4       V P                   P                  4       3# r(   )r8   getUsergetPasswordrO   s   &r,   xmlrpc_authinfoTestAuthHeader.xmlrpc_authinfo   s'    ||##%t||'?'?'AAAr/   )r8   N)
r0   r1   r2   r3   rR   r   rA   r   r4   r5   rS   s   @r,   r   r      s      
*B Br/   r   c                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )TestQueryProtocolzS
QueryProtocol for tests that saves headers received and sent,
inside the factory.
c                z    V P                   V P                  n         \        P                  P	                  V 4       R # r(   )	transportfactoryr   QueryProtocolconnectionMaderO   s   &r,   r    TestQueryProtocol.connectionMade   s&    !%++D1r/   c                R    W P                   P                  VP                  4       &   R # r(   )r   headerslowerr*   r   vals   &&&r,   handleHeaderTestQueryProtocol.handleHeader  s    ,/SYY[)r/   c                    W P                   P                  VP                  4       &   \        P                  P                  WV4       R# )z1
Keep sent headers so we can inspect them later.
N)r   sent_headersr   r   r   
sendHeaderr   s   &&&r,   r   TestQueryProtocol.sendHeader  s2     25!!#))+.''37r/   r)   N)
r0   r1   r2   r3   rR   r   r   r   r4   r5   rS   s   @r,   r   r      s     
208 8r/   r   c                   .   a  ] tR tRt o Rt]tR tRtV t	R# )TestQueryFactoryi  z=
QueryFactory using L{TestQueryProtocol} for saving headers.
c                j    / V n         / V n        \        P                  P                  ! V .VO5/ VB  R # r(   )r   r   r   r   r   )r*   argskwargss   &*,r,   r   TestQueryFactory.__init__  s/    $$T;D;F;r/   )r   r   N)
r0   r1   r2   r3   rR   r   protocolr   r4   r5   rS   s   @r,   r   r     s      !H< <r/   r   c                   *   a  ] tR tRt o RtR tRtV tR# )TestQueryFactoryCanceli  zo
QueryFactory that saves a reference to the
L{twisted.internet.interfaces.IConnector} to test connection lost.
c                    Wn         R # r(   	connector)r*   r   s   &&r,   startedConnecting(TestQueryFactoryCancel.startedConnecting!  s    "r/   r   N)r0   r1   r2   r3   rR   r   r4   r5   rS   s   @r,   r   r     s     
# #r/   r   c                      a  ] tR tRt o R tR tR tRR ltR tR t	R	 t
R
 tR tR tR tR tR tR t]! ]R4      R 4       tRtV tR# )XMLRPCTestsi%  c                    \         P                  ! ^ \        P                  ! \	        4       4      RR7      V n        V P
                  P                  4       P                  V n        . V n        R#     	127.0.0.1	interfaceN)	r   	listenTCPr   Siter[   pgetHostport	factoriesrO   s   &r,   r>   XMLRPCTests.setUp&  sB    ""1fkk$&&9[QFFNN$))	r/   c                D    . V n         V P                  P                  4       # r(   )r   r   stopListeningrO   s   &r,   tearDownXMLRPCTests.tearDown+  s    vv##%%r/   c                R    \        V/ VB pV P                  P                  V4       V# )z_
Specific queryFactory for proxy that uses our custom
L{TestQueryFactory}, and save factories.
)r   r   append)r*   r   r   r   s   &*, r,   queryFactoryXMLRPCTests.queryFactory/  s*    
 #D3F3g&r/   Nc                    \         P                  ! \        RV P                  ,          4      4      pVf   V P                  Vn        V# Wn        V# )z
Return a new xmlrpc.Proxy for the test site created in
setUp(), using the given factory as the queryFactory, or
self.queryFactory if no factory is provided.
http://127.0.0.1:%d/r   Proxyr   r   r   r*   r   r   s   && r,   proxyXMLRPCTests.proxy8  sF     LL'=		'IJK?!..AN  %Nr/   c                *   RRRR^/R3^3RRR^.3RRRRRR^. .RR/3.p. pV FU  w  r4pV P                  4       P                  ! V.VO5!  pVP                  V P                  V4       VP	                  V4       KW  	  \
        P                  ! VR	R
7      # )addrb   dictpaircomplexrc   r   r   r   TfireOnOneErrback)r  )         )r   )rb   rb   )rb      )r   r   r   r)   r  
callRemoteaddCallbackrB   r   r   DeferredList)r*   inputOutputdlmethr   outpds   &      r,   test_resultsXMLRPCTests.test_resultsE  s    "sAh_a(XQx(-S3R"4c5AB
  +D

''4t4AMM$**D1IIaL !, !!"t<<r/   c                   a  S P                  4       P                  RR4      pV 3R lpV 3R lpVP                  V4       VP                  V4       V# )zk
Verify that headers sent from the client side and the ones we
get back from the server side are correct.

r   r   c                    < SP                  SP                  ^ ,          P                  R,          R4       SP                  SP                  ^ ,          P                  R,          R4       R# )r      content-type   text/xml; charset=utf-8   content-lengths   129N)rB   r   r   )ingr*   s   &r,   check_server_headers6XMLRPCTests.test_headers.<locals>.check_server_headers^  sR    q!))/:<V T^^A.667HI6Rr/   c                 @  < SP                  SP                  ^ ,          P                  R,          R4       SP                  SP                  ^ ,          P                  R,          R4       SP                  SP                  ^ ,          P                  R,          R4       R# )r   s
   user-agents   Twisted/XMLRPClibr  r  r   s   155N)rB   r   r   )ignr*   s   &r,   check_client_headers6XMLRPCTests.test_headers.<locals>.check_client_headersd  s}    q!..}=?S q!..?* T^^A.;;<MNPVWr/   r  r  r  )r*   r  r"  r&  s   f   r,   test_headersXMLRPCTests.test_headersV  sJ     JJL##Ix8	S	X 	
*+	*+r/   c                
  a aa \        4       o\        S\        \        P                  R7      .4      o\
        P                  ! S4       S P                  V3R l4       . pR Fm  w  r#S P                  4       P                  V4      pS P                  V\        P                  4      pVP                  V3V 3R ll4       VP                  V4       Ko  	  \        P                   ! VRR7      pVV 3R lpVP                  V4       V# )z
Verify that for each way a method exposed via XML-RPC can fail, the
correct 'Content-type' header is set in the response and that the
client-side Deferred is errbacked with an appropriate C{Fault}
instance.
defaultLogLevelc                  0   < \         P                  ! S 4      # r(   r   removeObserverfiltereds   r,   <lambda>)XMLRPCTests.test_errors.<locals>.<lambda>~       2 A A( Kr/   c                 <   < SP                  V P                  V4      # r(   )rB   	faultCode)exccoder*   s   &&r,   r3  r4    s    1A1A#--QU1Vr/   Tr  c                   < SP                    F&  pSP                  VP                  R ,          R4       K(  	  SP                  ^\	        S4      4       S^ ,          R,          P
                  pS^,          R,          P
                  p\        V\        4      '       d   SP                  V\        4       M,SP                  V\        4       SP                  V\        4       SP                  \        \        4       R# )r  r  log_failureN)r   rB   r   assertEqualslenvalue
isinstancerY   assertIsInstancerU   flushLoggedErrors)r%  r   f1f2logObserverr*   s   &   r,   cb#XMLRPCTests.test_errors.<locals>.cb  s    >>  OOO46P * a[!12Q.44BQ.44B"n--%%b*:;%%b*:;%%b.9""#3^Dr/   ))r\   rs   )r\   	deferFail)rz   fault)   noSuchMethod)r   
deferFault)*   SESSION_TEST)r   r
   r   r   criticalr   addObserver
addCleanupr  r  assertFailurer   r}   r  r   r   r  )r*   r  r9  
methodNamer  rE  r2  rD  s   f     @@r,   test_errorsXMLRPCTests.test_errorsr  s     +,'1(BSBSTU
 	&&x0KL!
D 

''
3A""1fll3AMM4VWIIaL!
 rD9	E" 	
br/   c                x  a V3R loV P                  S4      P                  R^^4      pV P                  SP                  P                  P
                  R4       VP                  4        V P                  SP                  P                  P
                  R4       V P                  V\        P                  4      pV# )zj
A deferred from the Proxy can be cancelled, disconnecting
the L{twisted.internet.interfaces.IConnector}.
c                  <   < \        V / VB Sn        SP                  # r(   )r   f)r   kwr   s   *,r,   r   (XMLRPCTests.test_cancel.<locals>.factory  s    .;;GI99r/   r  disconnected)r  r  assertNotEqualrW  r   statecancelrB   rQ  r   CancelledError)r*   r  r   s   & @r,   test_cancelXMLRPCTests.test_cancel  s    	 JJw**5!Q7GII//55~F	
,,22NCq%"6"67r/   c                   a  \         P                  ! \        4      pVP                  R\	        RS P
                  3,          4      4      pV 3R lpVP                  V4       V# )z>
A classic GET on the xml server should return a NOT_ALLOWED.
s   GETr   c                 \   < SP                  V P                  \        P                  4       R # r(   )rB   r9  r   NOT_ALLOWED)responser*   s   &r,   checkResponse0XMLRPCTests.test_errorGet.<locals>.checkResponse  s    X]]D,<,<=r/   )r   Agentr   r8   r   r   r  )r*   agentr  re  s   f   r,   test_errorGetXMLRPCTests.test_errorGet  sL     W%MM&-0F$))0U"VW	> 	
m$r/   c           	     @  a  \         P                  ! \        4      pVP                  \	        RS P
                  3,          4      R\         P                  ! \        R4      4      R7      pVP                  \         P                  4       V 3R lpVP                  V4       V# )z<
Test that an invalid XML input returns an L{xmlrpc.Fault}.
r   s   POSTs   foo)urir9   bodyProducerc                 f   < SP                  \        P                  \        P                  V 4       R # r(   )assertRaisesr   r}   r   rE   )r+   r*   s   &r,   rE  ,XMLRPCTests.test_errorXMLContent.<locals>.cb  s    fllIOOVDr/   )
r   rg  r   r8   r   r   FileBodyProducerr   r  readBody)r*   rh  r  rE  s   f   r,   test_errorXMLContent XMLRPCTests.test_errorXMLContent  sz     W%MM4		|CD00A  

 	
foo&	E 	
br/   c                    \         P                  ! 4       pV P                  4       P                  RV4      pVP	                  V P
                  V4       V# )z
If an L{xmlrpclib.DateTime} is passed as an argument to an XML-RPC
call and then returned by the server unmodified, the result should
be equal to the original object.
r   )r   DateTimer  r  r  rB   )r*   whenr  s   &  r,   test_datetimeRoundtrip"XMLRPCTests.test_datetimeRoundtrip  sC     !!#JJL##FD1	d&&-r/   c                  a aa \        4       o\        S\        \        P                  R7      .4      o\
        P                  ! S4       S P                  V3R l4       S P                  4       P                  RR4      pR pS P                  \        RV4       S P                  V\        4      pVV 3R lpVP                  V4       V# )a  
If it is not possible to encode a response to the request (for example,
because L{xmlrpclib.dumps} raises an exception when encoding a
L{Fault}) the exception which prevents the response from being
generated is logged and the request object is finished anyway.
r,  c                  0   < \         P                  ! S 4      # r(   r/  r1  s   r,   r3  6XMLRPCTests.test_doubleEncodingError.<locals>.<lambda>  r5  r/   r   r"   c                      \        R 4      h)zCannot encode anything at all!)RuntimeError)r   r   s   *,r,   	fakeDumps7XMLRPCTests.test_doubleEncodingError.<locals>.fakeDumps  s    ?@@r/   r:   c                    < SP                  ^\        S4      4       SP                  S^ ,          R,          P                  \        4       SP                  \        SP                  \        4      4      ^4       R# )r  r;  N)r<  r=  r@  r>  r~  rB   rA  )ignoredrD  r*   s   &r,   cbFailed6XMLRPCTests.test_doubleEncodingError.<locals>.cbFailed  sW    a[!12!!+a."?"E"E|TS!7!7!EFJr/   )r   r
   r   r   rN  r   rO  rP  r  r  patchr   rQ  	Exceptionr  )r*   r  r  r  r2  rD  s   f   @@r,   test_doubleEncodingError$XMLRPCTests.test_doubleEncodingError  s     +,'1(BSBSTU
 	&&x0KLJJL##FB/	A 	

9gy1
 q),	K 	
hr/   c                r   a  S P                  4       P                  RR4      pV 3R lpVP                  V4      # )zF
The connection to the web server is closed when the request is done.
r   r"   c                    < SP                   w  pSP                  VP                  P                  4       SP	                  VP                  P
                  4       R # r(   )r   assertFalser   	connected
assertTruerZ  )r  r   r*   s   & r,   responseDoneBXMLRPCTests.test_closeConnectionAfterRequest.<locals>.responseDone  s@    IWW..889OOG--::;r/   r(  )r*   r  r  s   f  r,    test_closeConnectionAfterRequest,XMLRPCTests.test_closeConnectionAfterRequest   s3     JJL##FB/	<
 }}\**r/   c                    \        4       p\        P                  ! RRVR7      pVP                  R4       V P	                  VP
                  ^ ,          ^,          R4       R# )z
For I{HTTP} URIs, L{xmlrpc.Proxy.callRemote} passes the value it
received for the C{connectTimeout} parameter as the C{timeout} argument
to the underlying connectTCP call.
s   http://127.0.0.1:69g       @connectTimeoutr   
someMethodN)r	   r   r  r  rB   
tcpClientsr*   r   r  s   &  r,   test_tcpTimeoutXMLRPCTests.test_tcpTimeout  sP      /"3
 	&++A.q137r/   zOpenSSL not presentc                    \        4       p\        P                  ! RRVR7      pVP                  R4       V P	                  VP
                  ^ ,          ^,          R4       R# )z
For I{HTTPS} URIs, L{xmlrpc.Proxy.callRemote} passes the value it
received for the C{connectTimeout} parameter as the C{timeout} argument
to the underlying connectSSL call.
s   https://127.0.0.1:69g      @r  r  N)r	   r   r  r  rB   
sslClientsr  s   &  r,   test_sslTimeoutXMLRPCTests.test_sslTimeout  sP      /#C
 	&++A.q137r/   r   r   r   r(   )r0   r1   r2   r3   r>   r   r   r  r  r)  rS  r_  ri  rs  rx  r  r  r  r   sslSkipr  r4   r5   rS   s   @r,   r   r   %  si     
&="8.`"$	!F+8 G*+8 ,8r/   r   c                   .   a  ] tR tRt o RtRR ltRtV tR# )XMLRPCProxyWithoutSlashTestsi)  z+
Test with proxy that doesn't add a slash.
Nc                    \         P                  ! \        R V P                  ,          4      4      pVf   V P                  Vn        V# Wn        V# )http://127.0.0.1:%dr  r  s   && r,   r  "XMLRPCProxyWithoutSlashTests.proxy.  sD    LL'<tyy'HIJ?!..AN  %Nr/   r)   r(   )r0   r1   r2   r3   rR   r  r4   r5   rS   s   @r,   r  r  )  s      r/   r  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	 XMLRPCPublicLookupProcedureTestsi7  zf
Tests for L{XMLRPC}'s support of subclasses which override
C{lookupProcedure} and C{listProcedures}.
c                p   \         P                  ! ^ \        P                  ! V4      RR7      V n        V P                  V P                  P                  4       V P                  P                  4       P                  V n        \        P                  ! \        RV P                  ,          4      4      V n        R# )r   r   r   r  N)r   r   r   r   r   rP  r   r   r   r   r  r   r  )r*   r=   s   &&r,   createServer-XMLRPCPublicLookupProcedureTests.createServer=  sn    ""1fkk(&;{S,,-FFNN$))	\\-0E		0Q"RS
r/   c                    V P                  \        4       4       RpV P                  P                  RV4      pVP	                  V P
                  V4       V# )z
A subclass of L{XMLRPC} can override C{lookupProcedure} to find
procedures that are not defined using a C{xmlrpc_}-prefixed method name.
r{   r   )r  r   r  r  r  rB   )r*   whatr  s   &  r,   test_lookupProcedure5XMLRPCPublicLookupProcedureTests.test_lookupProcedureC  sJ    
 	-/0JJ!!&$/	d&&-r/   c                    V P                  \        4       4       V P                  P                  RR4      pV P	                  V\
        P                  4      pV# )z
A subclass of L{XMLRPC} can override C{lookupProcedure} to raise
L{NoSuchFunction} to indicate that a requested method is not available
to be called, signalling a fault to the XML-RPC client.
xxxxr{   )r  r   r  r  rQ  r   r}   r*   r  s   & r,   rS  ,XMLRPCPublicLookupProcedureTests.test_errorsN  sG     	-/0JJ!!&'2q&,,/r/   c                   a  \        4       p\        V4       S P                  V4       S P                  P	                  R4      pV 3R lpVP                  V4       V# )z
A subclass of L{XMLRPC} can override C{listProcedures} to define
Overriding listProcedures should prevent introspection from being
broken.
system.listMethodsc                 ,   < SP                  R V 4       R# )r   N)assertIn)
proceduresr*   s   &r,   listedAXMLRPCPublicLookupProcedureTests.test_listMethods.<locals>.listedd  s     MM%,r/   )r   r   r  r  r  r  )r*   r=   r  r  s   f   r,   test_listMethods1XMLRPCPublicLookupProcedureTests.test_listMethodsY  sP     &'"(#JJ!!"67	- 	
fr/   r   r   r  N)r0   r1   r2   r3   rR   r  r  rS  r  r4   r5   rS   s   @r,   r  r  7  s$     
T		 r/   r  c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )SerializationConfigMixinin  aK  
Mixin which defines a couple tests which should pass when a particular flag
is passed to L{XMLRPC}.

These are not meant to be exhaustive serialization tests, since L{xmlrpclib}
does all of the actual serialization work.  They are just meant to exercise
a few codepaths to make sure we are calling into xmlrpclib correctly.

@ivar flagName: A C{str} giving the name of the flag which must be passed to
    L{XMLRPC} to allow the tests to pass.  Subclasses should set this.

@ivar value: A value which the specified flag will allow the serialization
    of.  Subclasses should set this.
c           
        V P                   R/p\        P                  ! ^ \        P                  ! \        R/ VB 4      RR7      V n        V P                  V P                  P                  4       V P                  P                  4       P                  V n
        \        P                  ! \        RV P                  3,          4      3/ VB V n        R# )z?
Create a new XML-RPC server with C{allowNone} set to C{True}.
Tr   r   r   Nr)   )flagNamer   r   r   r   r[   r   rP  r   r   r   r   r  r   r  )r*   r   s   & r,   r>   SerializationConfigMixin.setUp~  s     --&""v{{4>&>*k
 	,,-FFNN$))	\\0DII<?@
DJ

r/   c                    V P                   P                  RV P                  4      pVP                  V P                  V P                  4       V# )zI
C{self.value} can be round-tripped over an XMLRPC method call/response.
r   r  r  r>  r  rB   r  s   & r,   test_roundtripValue,SerializationConfigMixin.test_roundtripValue  s;     JJ!!'4::6	d&&

3r/   c                    V P                   P                  RRV P                  /4      pVP                  V P                  RV P                  /4       V# )zb
A C{dict} which contains C{self.value} can be round-tripped over an
XMLRPC method call/response.
r   rb   r  r  s   & r,   test_roundtripNestedValue2SerializationConfigMixin.test_roundtripNestedValue  sE    
 JJ!!'C+<=	d&&djj(9:r/   r  N)
r0   r1   r2   r3   rR   r>   r  r  r4   r5   rS   s   @r,   r  r  n  s     
 r/   r  c                   "    ] tR tRtRtRtRtRtR# )XMLRPCAllowNoneTestsi  z>
Tests for passing L{None} when the C{allowNone} flag is set.
	allowNoneNr)   )r0   r1   r2   r3   rR   r  r>  r4   r)   r/   r,   r  r    s     HEr/   r  c                   L    ] tR tRtRtRt]P                  ! R^^^^-^;4      tRtR# )XMLRPCUseDateTimeTestsi  zX
Tests for passing a C{datetime.datetime} instance when the C{useDateTime}
flag is set.
useDateTimei  r)   N)	r0   r1   r2   r3   rR   r  datetimer>  r4   r)   r/   r,   r  r    s(    
 HdBAr26Er/   r  c                   J   a  ] tR tRt o RtRtRtR tR tR t	R t
R	 tR
tV tR# )XMLRPCAuthenticatedTestsi  zQ
Test with authenticated proxy. We run this with the same input/output as
above.
s   usernames   asecretc                    \         P                  ! ^ \        P                  ! \	        4       4      RR7      V n        V P
                  P                  4       P                  V n        . V n        R# r   )	r   r   r   r   r   r   r   r   r   rO   s   &r,   r>   XMLRPCAuthenticatedTests.setUp  sH    ""v{{>+,
 FFNN$))	r/   c                B   R \        V P                  4      \        V P                  4      V P                  3,          p\        P
                  ! \        V4      4      pVP                  R4      pVP                  V P                  V P                  V P                  .4       V# )zhttp://%s:%s@127.0.0.1:%d/authinfo)
r   userpasswordr   r   r  r   r  r  rB   )r*   urlr   r  s   &   r,   test_authInfoInURL+XMLRPCAuthenticatedTests.test_authInfoInURL  sy    *#'II.
 

 LLs+,LL$	d&&DMM(BCr/   c                   \         P                  ! \        R V P                  3,          4      V P                  V P
                  4      pVP                  R4      pVP                  V P                  V P                  V P
                  .4       V# )r   r  	r   r  r   r   r  r  r  r  rB   r*   r   r  s   &  r,   test_explicitAuthInfo.XMLRPCAuthenticatedTests.test_explicitAuthInfo  sh    LL0DII<?@IIMM

 LL$	d&&DMM(BCr/   c                   V P                   ^(,          p\        P                  ! \        RV P                  3,          4      V P
                  V4      pVP                  R4      pVP                  V P                  V P
                  V.4       V# )z
C{QueryProtocol} uses the C{base64.b64encode} function to encode user
name and password in the I{Authorization} header, so that it doesn't
embed new lines when using long inputs.
r   r  )	r  r   r  r   r   r  r  r  rB   )r*   longPasswordr   r  s   &   r,   test_longPassword*XMLRPCAuthenticatedTests.test_longPassword  sp     }}r)LL0DII<?@II

 LL$	d&&L(ABr/   c                   \         P                  ! \        R V P                  3,          4      V P                  V P
                  4      pVP                  R4      pVP                  V P                  V P                  V P
                  .4       V# )zhttp://wrong:info@127.0.0.1:%d/r  r  r  s   &  r,   test_explicitAuthInfoOverride6XMLRPCAuthenticatedTests.test_explicitAuthInfoOverride  sh    LL;tyylJKIIMM

 LL$	d&&DMM(BCr/   r  N)r0   r1   r2   r3   rR   r  r  r>   r  r  r  r  r4   r5   rS   s   @r,   r  r    s4     
 DH	  r/   r  c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )XMLRPCIntrospectionTestsi  c                    \        4       p\        V4       \        P                  ! ^ \        P
                  ! V4      RR7      V n        V P                  P                  4       P                  V n        . V n	        R# r   )
r[   r   r   r   r   r   r   r   r   r   )r*   r   s   & r,   r>   XMLRPCIntrospectionTests.setUp  sO     ""1fkk&&9[QFFNN$))	r/   c                t   a  V 3R  lpS P                  4       P                  R4      pVP                  V4       V# )c                 P   < V P                  4        SP                  V . RO4       R# )r  N)r  r
  r   rG  rK  r  r   rs   rH  r	  r   r  system.methodHelpsystem.methodSignaturer   )sortrB   )methsr*   s   &r,   	cbMethods<XMLRPCIntrospectionTests.test_listMethods.<locals>.cbMethods  s"    JJLr/   r  r(  )r*   r  r  s   f  r,   r  )XMLRPCIntrospectionTests.test_listMethods  s2    	. JJL##$89	i r/   c                    . ROp. pV FR  w  r4V P                  4       P                  RV4      pVP                  V P                  V4       VP	                  V4       KT  	  \
        P                  ! VRR7      # )r   r  Tr  ))r   rl   )rs   r"   )r  r   r  r*   inputOutputsr  r  expectedr  s   &     r,   test_methodHelp(XMLRPCIntrospectionTests.test_methodHelp  si    
 *ND

''(;TBAMM$**H5IIaL + !!"t<<r/   c                
   RR. RO. RO.3R. R	O.3.p. pV FR  w  r4V P                  4       P                  RV4      pVP                  V P                  V4       VP	                  V4       KT  	  \
        P                  ! VRR7      # )
r   r  r	  r  Tr  )r   r"   r   r   r   r  r  s   &     r,   test_methodSignature-XMLRPCIntrospectionTests.test_methodSignature#  s    *,JKL012
 *ND

''(@$GAMM$**H5IIaL + !!"t<<r/   r  N)
r0   r1   r2   r3   r>   r  r  r  r4   r5   rS   s   @r,   r  r    s     8== =r/   r  c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )XMLRPCClientErrorHandlingTestsi2  z+
Test error handling on the xmlrpc client.
c                    \         P                  ! R R4      V n        RV P                  n        \        P
                  ! ^ \        P                  ! V P                  4      RR7      V n        R# )s*   This text is not a valid XML-RPC response.s
   text/plainTr   r   N)	r   Datar=   isLeafr   r   r   r   r   rO   s   &r,   r>   $XMLRPCClientErrorHandlingTests.setUp7  sK    9=
  $%%v{{4==)[
	r/   c                6    V P                   P                  4       # r(   )r   r   rO   s   &r,   r   'XMLRPCClientErrorHandlingTests.tearDownA  s    yy&&((r/   c                    \         P                  ! \        RV P                  P	                  4       P                  3,          4      4      pV P                  VP                  R4      \        4      # )zR
Test that calling the xmlrpc client on a static http server raises
an exception.
r   r  )r   r  r   r   r   rQ  r  
ValueError)r*   r  s   & r,   test_erroneousResponse5XMLRPCClientErrorHandlingTests.test_erroneousResponseD  sV    
 0DII4E4E4G4L4L3NNO
 !!%"2"2<"@*MMr/   )r   r=   N)
r0   r1   r2   r3   rR   r>   r   r  r4   r5   rS   s   @r,   r  r  2  s      
)N Nr/   r  c                   B   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
QueryFactoryParseResponseTestsiO  z6
Test the behaviour of L{QueryFactory.parseResponse}.
c           
         \        R R RR R RRR7      V n        \        P                  ! R4      V n        RV n        \        P                  ! \        4       4      V n	        R # )Nr#   F)pathhostr9   r  r  r  r   zinvalid xmlr)   )r"   )
r   r   r   r:   goodContentsbadContentsr   rN   r   reasonrO   s   &r,   r>   $QueryFactoryParseResponseTests.setUpT  sV     )
 &OOE2( oon&67r/   c                    V P                   P                  pVP                  V P                   P                  V P                  4       V P                   P                  V P                  4       V# )zi
We can safely call L{QueryFactory.clientConnectionLost} as a callback
of L{QueryFactory.parseResponse}.
)r   deferredr  clientConnectionLostr  parseResponser  r  s   & r,    test_parseResponseCallbackSafety?QueryFactoryParseResponseTests.test_parseResponseCallbackSafetyh  sT    
 && 	
d''<<dkkJ''(9(9:r/   c                    V P                   P                  pVP                  V P                   P                  V P                  4       V P                   P                  V P                  4       V# )zi
We can safely call L{QueryFactory.clientConnectionLost} as an errback
of L{QueryFactory.parseResponse}.
)r   r  
addErrbackr  r  r  r  r  s   & r,   test_parseResponseErrbackSafety>QueryFactoryParseResponseTests.test_parseResponseErrbackSafetyu  sT    
 && 	
T&&;;T[[I''(8(89r/   c                    V P                   P                  pVP                  V P                   P                  V P                  4       V P                   P                  RR4       V# )ze
We can safely call L{QueryFactory.clientConnectionLost} as an errback
of L{QueryFactory.badStatus}.
statusmessage)r   r  r  r  r  	badStatusr  s   & r,   test_badStatusErrbackSafety:QueryFactoryParseResponseTests.test_badStatusErrbackSafety  sP    
 && 	
T&&;;T[[I##Hi8r/   c                    RpV P                   P                  pV P                   P                  V4       V P                  V\        4      # )z
Some server can send a response without any data:
L{QueryFactory.parseResponse} should catch the error and call the
result errback.
zM
<methodResponse>
 <params>
  <param>
  </param>
 </params>
</methodResponse>)r   r  r  rQ  
IndexError)r*   r;   r  s   &  r,   test_parseResponseWithoutData<QueryFactoryParseResponseTests.test_parseResponseWithoutData  sC     &&''0!!!Z00r/   )r  r  r   r  N)r0   r1   r2   r3   rR   r>   r  r  r  r#  r4   r5   rS   s   @r,   r	  r	  O  s(     8(1 1r/   r	  c                   ,   a  ] tR tRt o R tR tRtV tR# )XMLRPCWithRequestTestsi  c                $    \        4       V n        R # r(   )r[   r=   rO   s   &r,   r>   XMLRPCWithRequestTests.setUp  s    r/   c                   a  \        R4      pRVn        \        \        P                  ! RR4      4      Vn        V 3R lpVP                  4       P                  W!4      pS P                  P                  V4       V# )z
When an XML-RPC method is called and the implementation is
decorated with L{withRequest}, the request object is passed as
the first argument.
z/RPC2r#   r   c                 z   < \         P                  ! VP                  ^ ,          4      pSP                  VR4       R# )r   N))zPOST fooN)r   rE   rC   rB   )nr8   datar*   s   && r,   valid6XMLRPCWithRequestTests.test_withRequest.<locals>.valid  s+    ??7??1#56DT#89r/   )r   )
r   r9   r   r   r:   r;   notifyFinishr  r=   render_POST)r*   r8   r-  r  s   f   r,   test_withRequest'XMLRPCWithRequestTests.test_withRequest  sd     w'"9??8]#KL	:   "..u>!!'*r/   )r=   N)r0   r1   r2   r3   r>   r1  r4   r5   rS   s   @r,   r&  r&    s      r/   r&  )FrR   r  ior   r   r   r   twisted.internetr   r   twisted.internet.errorr   twisted.internet.testingr   r	   twisted.loggerr
   r   r   r   twisted.pythonr   twisted.python.compatr   r   twisted.python.reflectr   twisted.trialtwisted.webr   r   r   r   r   twisted.web.test.test_webr   twisted.web.xmlrpcr   r   r   r   r   r   r  ImportErrorTestCaser    r~  rU   r  rY   r[   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r	  r&  r)   r/   r,   <module>rA     s  

     + 1 H  # = . " < < 2 &' G-3x(( -3`	| 		Z 	\6 \~
& 
*
 
BT B$8,, 8*
<v** 
<#V00 #A8(## A8H; 4x'8'8 4n- -`3X5F5F 75x7H7H 7={ =@>={ >=BNX%6%6 N:O1X%6%6 O1dX.. s  Gs   6G 	G%$G%