
    Vhhw                        d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZmZmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* 	  ed       dZ+ G d dejZ                        Z. G d de/      Z0 G d de1      Z2 G d de%      Z3 G d de%      Z4 G d de%      Z5 G d d e3      Z6 G d! d"e!jn                        Z8 G d# d$e!jL                        Z9 G d% d&e!jL                        Z: G d' d(ejZ                        Z; G d) d*e;      Z< G d+ d,ejZ                        Z= G d- d.      Z> G d/ d0e>ejZ                        Z? G d1 d2e>ejZ                        Z@ G d3 d4e;      ZA G d5 d6e;      ZB G d7 d8ejZ                        ZC G d9 d:ejZ                        ZD G d; d<ejZ                        ZEy# e,$ r dZ+Y aw xY w)=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                   "    e Zd ZdZd Zd Zd Zy)AsyncXMLRPCTestsz5
    Tests for L{XMLRPC}'s support of Deferreds.
    c                 &   t        dg      | _        d| j                  _        t        t        dt        j                  d      fz        | j                  _        t        j                         x| _
         G fddt              } |       | _        y )N POSTasync c                       e Zd Z fdZy)-AsyncXMLRPCTests.setUp.<locals>.AsyncResourcec                     S Nr&   )selfresults    L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_xmlrpc.pyxmlrpc_asyncz:AsyncXMLRPCTests.setUp.<locals>.AsyncResource.xmlrpc_async=   s        N)__name__
__module____qualname__r.   r,   s   r-   AsyncResourcer(   <   s    r/   r4   )r   requestmethodr   r   r   dumpscontentr   Deferredr,   r   resource)r+   r4   r,   s     @r-   setUpzAsyncXMLRPCTests.setUp3   sp    #RD)$'w	(;<< 
  %~~//	F 	 &r/   c                    | j                   j                  | j                         | j                  | j                  j                  g        | j
                  j                  d       t        j                  dj                  | j                  j                              }| j                  |d       | j                  | j                  j                  d       y)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/   )r3   N   N)r:   renderr5   assertEqualwrittenr,   callbackr   loadsjoinfinished)r+   resps     r-   test_deferredResponsez&AsyncXMLRPCTests.test_deferredResponseB   s    
 	T\\*--r2X&sxx(<(<=>23..2r/   c                    | j                   j                  | j                         | j                  j                  t	        j
                  t        d                   | j                  j                  d       | j                  | j                  j                  g        | j                  | j                  j                  d       y)a   
        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,   r   N)r:   r>   r5   processingFailedr   Failurer   r,   rA   r?   r@   rD   r+   s    r-    test_interruptedDeferredResponsez1AsyncXMLRPCTests.test_interruptedDeferredResponseP   s     	T\\*%%goon[6Q&RSX&--r2..2r/   N)r0   r1   r2   __doc__r;   rF   rL   r&   r/   r-   r!   r!   .   s    (33r/   r!   c                       e Zd Zy)TestRuntimeErrorNr0   r1   r2   r&   r/   r-   rO   rO   ^       r/   rO   c                       e Zd Zy)TestValueErrorNrP   r&   r/   r-   rS   rS   b   rQ   r/   rS   c                       e Zd ZdZdZdZd Zd Zg dg dge_        d Z	g d	ge	_        d
 Z
d Zd Zd Zd Zd Zd Zd Zde_        ed        Zd Zy)Test     *   c                     |S r*   r&   )r+   args     r-   xmlrpc_echozTest.xmlrpc_echon   s    
r/   c                     ||z   S )z0
        This function add two numbers.
        r&   )r+   abs      r-   
xmlrpc_addzTest.xmlrpc_addr   s     1ur/   intra   ra   doublerc   rc   c                 
    ||gS )zC
        This function puts the two arguments in an array.
        r&   )r+   stringnums      r-   xmlrpc_pairzTest.xmlrpc_pair~   s     }r/   arrayre   ra   c                 ,    t        j                  |      S )Help for defer.)r   succeedr+   xs     r-   xmlrpc_deferzTest.xmlrpc_defer   s    }}Qr/   c                 <    t        j                  t                     S r*   )r   failrS   rK   s    r-   xmlrpc_deferFailzTest.xmlrpc_deferFail   s    zz.*++r/   c                     t         r*   )rO   rK   s    r-   xmlrpc_failzTest.xmlrpc_fail   s    r/   c                 .    t        j                  dd      S )N   hellor   FaultrK   s    r-   xmlrpc_faultzTest.xmlrpc_fault   s    ||B((r/   c                 T    t        j                  t        j                  dd            S )N   hi)r   rq   r   ry   rK   s    r-   xmlrpc_deferFaultzTest.xmlrpc_deferFault   s    zz&,,r4011r/   c                 @    d}||k7  rt        j                  dd      S |S )z8
        Used to test that we can pass Unicode.
           ☃   zPayload not unicode snowmanrx   )r+   payloadsnowmans      r-   xmlrpc_snowmanzTest.xmlrpc_snowman   s(     g<<$ABBr/   c                     dddg gddS )Nr^   crv   foor]   Dr&   rK   s    r-   xmlrpc_complexzTest.xmlrpc_complex   s    3B'e44r/   c                     ||   S r*   r&   )r+   mapkeys      r-   xmlrpc_dictzTest.xmlrpc_dict   s    3xr/   Help for dict.c                 &    |j                   dz   |z   S )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.
         )r6   )r+   r5   others      r-   xmlrpc_withRequestzTest.xmlrpc_withRequest   s$     NN  		
r/   c                     	 t        j                  | |      S # t        j                  $ r3 |j	                  d      r t        j
                  | j                  d       w xY w)NSESSIONzSession non-existent/expired.)r   lookupProcedurer   NoSuchFunction
startswithry   SESSION_EXPIRED)r+   procedurePaths     r-   r   zTest.lookupProcedure   s_    	))$>>$$ 	''	2ll((*I  	s
    AAN)r0   r1   r2   FAILURE	NOT_FOUNDr   r[   r_   	signaturerg   ro   rr   rt   rz   r~   r   r   r   helpr   r   r   r&   r/   r-   rU   rU   f   s     GIO 	&J 88K ,)25 (K
 
	r/   rU   c                       e Zd ZdZd Zd Zy)TestLookupProcedurez}
    This is a resource which customizes procedure lookup to be used by the tests
    of support for this customization.
    c                     |S r*   r&   rm   s     r-   echozTestLookupProcedure.echo   s    r/   c                 l    |dk(  r| j                   S t        j                  | j                  d| d      )zs
        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   z#TestLookupProcedure.lookupProcedure   s;    
 F"99##NNjzB
 	
r/   N)r0   r1   r2   rM   r   r   r&   r/   r-   r   r      s    
	
r/   r   c                       e Zd ZdZd Zy)TestListProceduresz
    This is a resource which customizes procedure enumeration to be used by the
    tests of support for this customization.
    c                     dgS )zW
        Return a list of a single method this resource will claim to support.
        r   r&   rK   s    r-   listProceduresz!TestListProcedures.listProcedures   s     wr/   N)r0   r1   r2   rM   r   r&   r/   r-   r   r      s    
r/   r   c                   "    e Zd ZdZd Zd Zd Zy)TestAuthHeaderzU
    This is used to get the header info so that we can test
    authentication.
    c                 <    t         j                  |        d | _        y r*   )rU   __init__r5   rK   s    r-   r   zTestAuthHeader.__init__   s    dr/   c                 <    || _         t        j                  | |      S r*   )r5   rU   r>   )r+   r5   s     r-   r>   zTestAuthHeader.render   s    {{4))r/   c                 j    | j                   j                         | j                   j                         fS r*   )r5   getUsergetPasswordrK   s    r-   xmlrpc_authinfozTestAuthHeader.xmlrpc_authinfo   s'    ||##%t||'?'?'AAAr/   N)r0   r1   r2   rM   r   r>   r   r&   r/   r-   r   r      s    
*Br/   r   c                   "    e Zd ZdZd Zd Zd Zy)TestQueryProtocolz_
    QueryProtocol for tests that saves headers received and sent,
    inside the factory.
    c                 x    | j                   | j                  _         t        j                  j	                  |        y r*   )	transportfactoryr   QueryProtocolconnectionMaderK   s    r-   r   z TestQueryProtocol.connectionMade   s&    !%++D1r/   c                 R    || j                   j                  |j                         <   y r*   )r   headerslowerr+   r   vals      r-   handleHeaderzTestQueryProtocol.handleHeader  s    ,/SYY[)r/   c                     || j                   j                  |j                         <   t        j                  j                  | ||       y)zA
        Keep sent headers so we can inspect them later.
        N)r   sent_headersr   r   r   
sendHeaderr   s      r-   r   zTestQueryProtocol.sendHeader  s6     25!!#))+.''c37r/   N)r0   r1   r2   rM   r   r   r   r&   r/   r-   r   r      s    
208r/   r   c                       e Zd ZdZeZd Zy)TestQueryFactoryzE
    QueryFactory using L{TestQueryProtocol} for saving headers.
    c                 f    i | _         i | _        t        j                  j                  | g|i | y r*   )r   r   r   r   r   )r+   argskwargss      r-   r   zTestQueryFactory.__init__  s/    $$T;D;F;r/   N)r0   r1   r2   rM   r   protocolr   r&   r/   r-   r   r     s     !H<r/   r   c                       e Zd ZdZd Zy)TestQueryFactoryCancelz{
    QueryFactory that saves a reference to the
    L{twisted.internet.interfaces.IConnector} to test connection lost.
    c                     || _         y r*   )	connector)r+   r   s     r-   startedConnectingz(TestQueryFactoryCancel.startedConnecting!  s	    "r/   N)r0   r1   r2   rM   r   r&   r/   r-   r   r     s    
#r/   r   c                       e Zd Zd Zd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Z eed      d        Zy)XMLRPCTestsc                     t        j                  dt        j                  t	                     d      | _        | j
                  j                         j                  | _        g | _        y Nr   	127.0.0.1	interface)	r   	listenTCPr   SiterU   pgetHostport	factoriesrK   s    r-   r;   zXMLRPCTests.setUp&  sB    ""1fkk$&&9[QFFNN$))	r/   c                 D    g | _         | j                  j                         S r*   )r   r   stopListeningrK   s    r-   tearDownzXMLRPCTests.tearDown+  s    vv##%%r/   c                 R    t        |i |}| j                  j                  |       |S )zw
        Specific queryFactory for proxy that uses our custom
        L{TestQueryFactory}, and save factories.
        )r   r   append)r+   r   r   r   s       r-   queryFactoryzXMLRPCTests.queryFactory/  s*    
 #D3F3g&r/   Nc                     t        j                  t        d| j                  z              }|| j                  |_        |S ||_        |S )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-   proxyzXMLRPCTests.proxy8  sH     LL'=		'IJK?!..AN  %ANr/   c                 "   dddddidfdfddddgfdd	d
dddg gddfg}g }|D ]T  \  }}} | j                         j                  |g| }|j                  | j                  |       |j	                  |       V t        j                  |d      S )N)add)         )r   )r]   r]   dictr]   r=   pair)r]   r=   )r   r   r   complexr&   r^   r   rv   r   r   TfireOnOneErrbackr   
callRemoteaddCallbackr?   r   r   DeferredList)r+   inputOutputdlmethr   outpds          r-   test_resultszXMLRPCTests.test_resultsE  s    "sAh_a(XQx(-3R"45AB
  + 	D$'

''4t4AMM$**D1IIaL	 !!"t<<r/   c                       j                         j                  dd      } fd} fd}|j                  |       |j                  |       |S )z
        Verify that headers sent from the client side and the ones we
        get back from the server side are correct.

        r   r   c                     j                  j                  d   j                  d   d       j                  j                  d   j                  d   d       y )Nr      content-type   text/xml; charset=utf-8   content-lengths   129)r?   r   r   )ingr+   s    r-   check_server_headersz6XMLRPCTests.test_headers.<locals>.check_server_headers^  sR    q!))/:<V T^^A.667HI6Rr/   c                    j                  j                  d   j                  d   d       j                  j                  d   j                  d   d       j                  j                  d   j                  d   d       y )Nr   s
   user-agents   Twisted/XMLRPClibr   r   r   s   155)r?   r   r   )ignr+   s    r-   check_client_headersz6XMLRPCTests.test_headers.<locals>.check_client_headersd  s}    q!..}=?S q!..?* T^^A.;;<MNPVWr/   r   r   r   )r+   r   r   r  s   `   r-   test_headerszXMLRPCTests.test_headersV  sJ     JJL##Ix8	S	X 	
*+	*+r/   c                     t               t        t        t        j                        g      t        j                          j                  fd       g }dD ]k  \  }} j                         j                  |      } j                  |t        j                        }|j                  |f fd	       |j                  |       m t        j                   |d      } fd}|j                  |       |S )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                  .    t        j                         S r*   r   removeObserverfiltereds   r-   <lambda>z)XMLRPCTests.test_errors.<locals>.<lambda>~       2 A A( K r/   ))rV   rq   )rV   	deferFail)rv   fault)rW   noSuchMethod)r|   
deferFault)rX   SESSION_TESTc                 <    j                  | j                  |      S r*   )r?   	faultCode)exccoder+   s     r-   r  z)XMLRPCTests.test_errors.<locals>.<lambda>  s    1A1A#--QU1V r/   Tr   c                    j                   D ]!  }j                  |j                  d   d       # j                  dt	                     d   d   j
                  }d   d   j
                  }t        |t              rj                  |t               n,j                  |t               j                  |t               j                  t        t               y )Nr   r   r   r   log_failurer=   )r   r?   r   assertEqualslenvalue
isinstancerS   assertIsInstancerO   flushLoggedErrors)r  r   f1f2logObserverr+   s       r-   cbz#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	   r   r   r   criticalr   addObserver
addCleanupr   r   assertFailurer   ry   r   r   r   r   )r+   r   r  
methodNamer   r$  r  r#  s   `     @@r-   test_errorsz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                 v   fd| j                        j                  ddd      }| j                  j                  j                  j
                  d       |j                          | j                  j                  j                  j
                  d       | j                  |t        j                        }|S )z
        A deferred from the Proxy can be cancelled, disconnecting
        the L{twisted.internet.interfaces.IConnector}.
        c                  <    t        | i |_        j                  S r*   )r   f)r   kwr   s     r-   r   z(XMLRPCTests.test_cancel.<locals>.factory  s    .;;GI99r/   r   r   r   disconnected)r   r   assertNotEqualr-  r   statecancelr?   r(  r   CancelledError)r+   r   r   s     @r-   test_cancelzXMLRPCTests.test_cancel  s    	 JJw**5!Q7GII//55~F	
,,22NCq%"6"67r/   c                      t        j                  t              }|j                  dt	        d j
                  fz              } fd}|j                  |       |S )zN
        A classic GET on the xml server should return a NOT_ALLOWED.
        s   GETr   c                 Z    j                  | j                  t        j                         y r*   )r?   r  r   NOT_ALLOWED)responser+   s    r-   checkResponsez0XMLRPCTests.test_errorGet.<locals>.checkResponse  s    X]]D,<,<=r/   )r   Agentr   r5   r   r   r   )r+   agentr   r9  s   `   r-   test_errorGetzXMLRPCTests.test_errorGet  sL     W%MM&-0F$))0U"VW	> 	
m$r/   c           	      2    t        j                  t              }|j                  t	        d j
                  fz        dt        j                  t        d                  }|j                  t         j                          fd}|j                  |       |S )zL
        Test that an invalid XML input returns an L{xmlrpc.Fault}.
        r   s   POSTs   foo)urir6   bodyProducerc                 d    j                  t        j                  t        j                  |        y r*   )assertRaisesr   ry   r   rB   )r,   r+   s    r-   r$  z,XMLRPCTests.test_errorXMLContent.<locals>.cb  s    fllIOOVDr/   )
r   r:  r   r5   r   r   FileBodyProducerr   r   readBody)r+   r;  r   r$  s   `   r-   test_errorXMLContentz XMLRPCTests.test_errorXMLContent  sz     W%MM4		|CD00A  

 	
foo&	E 	
br/   c                     t        j                         }| j                         j                  d|      }|j	                  | j
                  |       |S )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   r?   )r+   whenr   s      r-   test_datetimeRoundtripz"XMLRPCTests.test_datetimeRoundtrip  sC     !!#JJL##FD1	d&&-r/   c                     t               t        t        t        j                        g      t        j                          j                  fd        j                         j                  dd      }d } j                  t        d|        j                  |t              } fd}|j                  |       |S )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                  .    t        j                         S r*   r
  r  s   r-   r  z6XMLRPCTests.test_doubleEncodingError.<locals>.<lambda>  r  r/   r   r#   c                      t        d      )NzCannot encode anything at all!)RuntimeError)r   r   s     r-   	fakeDumpsz7XMLRPCTests.test_doubleEncodingError.<locals>.fakeDumps  s    ?@@r/   r7   c                     j                  dt                     j                  d   d   j                  t               j                  t        j                  t                    d       y )Nr=   r   r  )r  r  r  r  rL  r?   r   )ignoredr#  r+   s    r-   cbFailedz6XMLRPCTests.test_doubleEncodingError.<locals>.cbFailed  sW    a[!12!!+a."?"E"E|TS!7!7!EFJr/   )r	   r   r   r   r%  r   r&  r'  r   r   patchr   r(  	Exceptionr   )r+   r   rM  rP  r  r#  s   `   @@r-   test_doubleEncodingErrorz$XMLRPCTests.test_doubleEncodingError  s     +,'1(BSBSTU
 	&&x0KLJJL##FB/	A 	

9gy1
 q),	K 	
hr/   c                 p      j                         j                  dd      } fd}|j                  |      S )zV
        The connection to the web server is closed when the request is done.
        r   r#   c                     j                   \  }j                  |j                  j                         j	                  |j                  j
                         y r*   )r   assertFalser   	connected
assertTruer/  )rO  r   r+   s     r-   responseDonezBXMLRPCTests.test_closeConnectionAfterRequest.<locals>.responseDone  s@    IWW..889OOG--::;r/   r  )r+   r   rY  s   `  r-    test_closeConnectionAfterRequestz,XMLRPCTests.test_closeConnectionAfterRequest   s3     JJL##FB/	<
 }}\**r/   c                     t               }t        j                  dd|      }|j                  d       | j	                  |j
                  d   d   d       y)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   
someMethodr   r   N)r
   r   r   r   r?   
tcpClientsr+   r   r   s      r-   test_tcpTimeoutzXMLRPCTests.test_tcpTimeout  sP      /"3
 	&++A.q137r/   zOpenSSL not presentc                     t               }t        j                  dd|      }|j                  d       | j	                  |j
                  d   d   d       y)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^  r      N)r
   r   r   r   r?   
sslClientsr`  s      r-   test_sslTimeoutzXMLRPCTests.test_sslTimeout  sP      /#C
 	&++A.q137r/   r*   )r0   r1   r2   r;   r   r   r   r   r  r*  r4  r<  rD  rH  rS  rZ  ra  r   sslSkipre  r&   r/   r-   r   r   %  sf    
&="8.`"$	!F+8 G*+8 ,8r/   r   c                       e Zd ZdZddZy)XMLRPCProxyWithoutSlashTestsz3
    Test with proxy that doesn't add a slash.
    Nc                     t        j                  t        d| j                  z              }|| j                  |_        |S ||_        |S )Nhttp://127.0.0.1:%dr   r   s      r-   r   z"XMLRPCProxyWithoutSlashTests.proxy.  sF    LL'<tyy'HIJ?!..AN  %ANr/   r*   )r0   r1   r2   rM   r   r&   r/   r-   rh  rh  )  s    r/   rh  c                   (    e Zd ZdZd Zd Zd Zd Zy) XMLRPCPublicLookupProcedureTestszr
    Tests for L{XMLRPC}'s support of subclasses which override
    C{lookupProcedure} and C{listProcedures}.
    c                 `   t        j                  dt        j                  |      d      | _        | j                  | j                  j                         | j                  j                         j                  | _        t        j                  t        d| j                  z              | _        y )Nr   r   r   rj  )r   r   r   r   r   r'  r   r   r   r   r   r   r   )r+   r:   s     r-   createServerz-XMLRPCPublicLookupProcedureTests.createServer=  sn    ""1fkk(&;{S,,-FFNN$))	\\-0E		0Q"RS
r/   c                     | j                  t                      d}| j                  j                  d|      }|j	                  | j
                  |       |S )z
        A subclass of L{XMLRPC} can override C{lookupProcedure} to find
        procedures that are not defined using a C{xmlrpc_}-prefixed method name.
        rw   r   )rn  r   r   r   r   r?   )r+   whatr   s      r-   test_lookupProcedurez5XMLRPCPublicLookupProcedureTests.test_lookupProcedureC  sJ    
 	-/0JJ!!&$/	d&&-r/   c                     | j                  t                      | j                  j                  dd      }| j	                  |t
        j                        }|S )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.
        xxxxrw   )rn  r   r   r   r(  r   ry   r+   r   s     r-   r*  z,XMLRPCPublicLookupProcedureTests.test_errorsN  sG     	-/0JJ!!&'2q&,,/r/   c                      t               }t        |        j                  |        j                  j	                  d      } fd}|j                  |       |S )z
        A subclass of L{XMLRPC} can override C{listProcedures} to define
        Overriding listProcedures should prevent introspection from being
        broken.
        system.listMethodsc                 *    j                  d|        y )Nr   )assertIn)
proceduresr+   s    r-   listedzAXMLRPCPublicLookupProcedureTests.test_listMethods.<locals>.listedd  s     MM%,r/   )r   r   rn  r   r   r   )r+   r:   r   rz  s   `   r-   test_listMethodsz1XMLRPCPublicLookupProcedureTests.test_listMethodsY  sP     &'"(#JJ!!"67	- 	
fr/   N)r0   r1   r2   rM   rn  rq  r*  r{  r&   r/   r-   rl  rl  7  s    
T		r/   rl  c                   "    e Zd ZdZd Zd Zd Zy)SerializationConfigMixinas  
    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           
         | j                   di}t        j                  dt        j                  t        di |      d      | _        | j                  | j                  j                         | j                  j                         j                  | _
        t        j                  t        d| j                  fz        fi || _        y)zO
        Create a new XML-RPC server with C{allowNone} set to C{True}.
        Tr   r   r   r   Nr&   )flagNamer   r   r   r   rU   r   r'  r   r   r   r   r   r   r   )r+   r   s     r-   r;   zSerializationConfigMixin.setUp~  s     --&""v{{4>&>*k
 	,,-FFNN$))	\\0DII<?@
DJ

r/   c                     | j                   j                  d| j                        }|j                  | j                  | j                         |S )zY
        C{self.value} can be round-tripped over an XMLRPC method call/response.
        r   r   r   r  r   r?   rt  s     r-   test_roundtripValuez,SerializationConfigMixin.test_roundtripValue  s;     JJ!!'4::6	d&&

3r/   c                     | j                   j                  dd| j                  i      }|j                  | j                  d| j                  i       |S )zz
        A C{dict} which contains C{self.value} can be round-tripped over an
        XMLRPC method call/response.
        r   r]   r  rt  s     r-   test_roundtripNestedValuez2SerializationConfigMixin.test_roundtripNestedValue  sE    
 JJ!!'C+<=	d&&djj(9:r/   N)r0   r1   r2   rM   r;   r  r  r&   r/   r-   r}  r}  n  s    
r/   r}  c                       e Zd ZdZdZdZy)XMLRPCAllowNoneTestszF
    Tests for passing L{None} when the C{allowNone} flag is set.
    	allowNoneN)r0   r1   r2   rM   r  r  r&   r/   r-   r  r    s     HEr/   r  c                   B    e Zd ZdZdZ ej
                  dddddd      Zy	)
XMLRPCUseDateTimeTestszd
    Tests for passing a C{datetime.datetime} instance when the C{useDateTime}
    flag is set.
    useDateTimei  rv      r   -   ;   N)r0   r1   r2   rM   r  datetimer  r&   r/   r-   r  r    s*    
 HHdBAr26Er/   r  c                   6    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
y	)
XMLRPCAuthenticatedTestsz]
    Test with authenticated proxy. We run this with the same input/output as
    above.
    s   usernames   asecretc                     t        j                  dt        j                  t	                     d      | _        | j
                  j                         j                  | _        g | _        y r   )	r   r   r   r   r   r   r   r   r   rK   s    r-   r;   zXMLRPCAuthenticatedTests.setUp  sH    ""v{{>+,
 FFNN$))	r/   c                 8   dt        | j                        t        | j                        | j                  fz  }t	        j
                  t        |            }|j                  d      }|j                  | j                  | j                  | j                  g       |S )Nzhttp://%s:%s@127.0.0.1:%d/authinfo)
r   userpasswordr   r   r   r   r   r   r?   )r+   urlr   r   s       r-   test_authInfoInURLz+XMLRPCAuthenticatedTests.test_authInfoInURL  sy    *#'II.
 

 LLs+,LL$	d&&DMM(BCr/   c                    t        j                  t        d| j                  fz        | j                  | j
                        }|j                  d      }|j                  | j                  | j                  | j
                  g       |S )Nr   r  	r   r   r   r   r  r  r   r   r?   r+   r   r   s      r-   test_explicitAuthInfoz.XMLRPCAuthenticatedTests.test_explicitAuthInfo  sh    LL0DII<?@IIMM

 LL$	d&&DMM(BCr/   c                    | j                   dz  }t        j                  t        d| j                  fz        | j
                  |      }|j                  d      }|j                  | j                  | j
                  |g       |S )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   r?   )r+   longPasswordr   r   s       r-   test_longPasswordz*XMLRPCAuthenticatedTests.test_longPassword  sp     }}r)LL0DII<?@II

 LL$	d&&L(ABr/   c                    t        j                  t        d| j                  fz        | j                  | j
                        }|j                  d      }|j                  | j                  | j                  | j
                  g       |S )Nzhttp://wrong:info@127.0.0.1:%d/r  r  r  s      r-   test_explicitAuthInfoOverridez6XMLRPCAuthenticatedTests.test_explicitAuthInfoOverride  sh    LL;tyylJKIIMM

 LL$	d&&DMM(BCr/   N)r0   r1   r2   rM   r  r  r;   r  r  r  r  r&   r/   r-   r  r    s,    
 DH	 r/   r  c                   $    e Zd Zd Zd Zd Zd Zy)XMLRPCIntrospectionTestsc                     t               }t        |       t        j                  dt	        j
                  |      d      | _        | j                  j                         j                  | _        g | _	        y r   )
rU   r   r   r   r   r   r   r   r   r   )r+   r   s     r-   r;   zXMLRPCIntrospectionTests.setUp  sO     ""1fkk&&9[QFFNN$))	r/   c                 r      fd} j                         j                  d      }|j                  |       |S )Nc                 N    | j                          j                  | g d       y )N)r   r   r   r  r  r   r   rq   r  r   r   rv  system.methodHelpsystem.methodSignaturer   )sortr?   )methsr+   s    r-   	cbMethodsz<XMLRPCIntrospectionTests.test_listMethods.<locals>.cbMethods  s"    JJLr/   rv  r  )r+   r  r   s   `  r-   r{  z)XMLRPCIntrospectionTests.test_listMethods  s2    	. JJL##$89	i r/   c                     g d}g }|D ]R  \  }}| j                         j                  d|      }|j                  | j                  |       |j	                  |       T t        j                  |d      S )N))r   rk   )rq   r#   )r   r   r  Tr   r   r+   inputOutputsr   r   expectedr   s         r-   test_methodHelpz(XMLRPCIntrospectionTests.test_methodHelp  sp    
 * 	ND(

''(;TBAMM$**H5IIaL	 !!"t<<r/   c                    ddg dg dgfdg dgfg}g }|D ]R  \  }}| j                         j                  d|      }|j                  | j                  |       |j	                  |       T t        j                  |d	      S )
N)r   r#   r   r`   rb   r   rh   r  Tr   r   r  s         r-   test_methodSignaturez-XMLRPCIntrospectionTests.test_methodSignature#  s    *,JKL012
 * 	ND(

''(@$GAMM$**H5IIaL	 !!"t<<r/   N)r0   r1   r2   r;   r{  r  r  r&   r/   r-   r  r    s    8==r/   r  c                   "    e Zd ZdZd Zd Zd Zy)XMLRPCClientErrorHandlingTestsz3
    Test error handling on the xmlrpc client.
    c                     t        j                  dd      | _        d| j                  _        t	        j
                  dt        j                  | j                        d      | _        y )Ns*   This text is not a valid XML-RPC response.s
   text/plainTr   r   r   )	r   Datar:   isLeafr   r   r   r   r   rK   s    r-   r;   z$XMLRPCClientErrorHandlingTests.setUp7  sK    9=
  $%%v{{4==)[
	r/   c                 6    | j                   j                         S r*   )r   r   rK   s    r-   r   z'XMLRPCClientErrorHandlingTests.tearDownA  s    yy&&((r/   c                     t        j                  t        d| j                  j	                         j                  fz              }| j                  |j                  d      t              S )zj
        Test that calling the xmlrpc client on a static http server raises
        an exception.
        r   r^  )r   r   r   r   r   r(  r   
ValueError)r+   r   s     r-   test_erroneousResponsez5XMLRPCClientErrorHandlingTests.test_erroneousResponseD  sV    
 0DII4E4E4G4L4L3NNO
 !!%"2"2<"@*MMr/   N)r0   r1   r2   rM   r;   r   r  r&   r/   r-   r  r  2  s    
)Nr/   r  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)QueryFactoryParseResponseTestsz>
    Test the behaviour of L{QueryFactory.parseResponse}.
    c           	          t        d d dd d dd      | _        t        j                  d      | _        d| _        t        j                  t                     | _	        y )Nr$   Fr&   )pathhostr6   r  r  r  r   )r#   zinvalid xml)
r   r   r   r7   goodContentsbadContentsr   rJ   r   reasonrK   s    r-   r;   z$QueryFactoryParseResponseTests.setUpT  sV     )
 &OOE2( oon&67r/   c                     | j                   j                  }|j                  | j                   j                  | j                         | j                   j                  | j                         |S )z
        We can safely call L{QueryFactory.clientConnectionLost} as a callback
        of L{QueryFactory.parseResponse}.
        )r   deferredr   clientConnectionLostr  parseResponser  rt  s     r-    test_parseResponseCallbackSafetyz?QueryFactoryParseResponseTests.test_parseResponseCallbackSafetyh  sT    
 && 	
d''<<dkkJ''(9(9:r/   c                     | j                   j                  }|j                  | j                   j                  | j                         | j                   j                  | j                         |S )z
        We can safely call L{QueryFactory.clientConnectionLost} as an errback
        of L{QueryFactory.parseResponse}.
        )r   r  
addErrbackr  r  r  r  rt  s     r-   test_parseResponseErrbackSafetyz>QueryFactoryParseResponseTests.test_parseResponseErrbackSafetyu  sT    
 && 	
T&&;;T[[I''(8(89r/   c                     | j                   j                  }|j                  | j                   j                  | j                         | j                   j                  dd       |S )z}
        We can safely call L{QueryFactory.clientConnectionLost} as an errback
        of L{QueryFactory.badStatus}.
        statusmessage)r   r  r  r  r  	badStatusrt  s     r-   test_badStatusErrbackSafetyz:QueryFactoryParseResponseTests.test_badStatusErrbackSafety  sP    
 && 	
T&&;;T[[I##Hi8r/   c                     d}| j                   j                  }| j                   j                  |       | j                  |t              S )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  r(  
IndexError)r+   r8   r   s      r-   test_parseResponseWithoutDataz<QueryFactoryParseResponseTests.test_parseResponseWithoutData  sC     &&''0!!!Z00r/   N)	r0   r1   r2   rM   r;   r  r  r  r  r&   r/   r-   r  r  O  s     8(1r/   r  c                       e Zd Zd Zd Zy)XMLRPCWithRequestTestsc                 "    t               | _        y r*   )rU   r:   rK   s    r-   r;   zXMLRPCWithRequestTests.setUp  s    r/   c                      t        d      }d|_        t        t        j                  dd            |_         fd}|j                         j                  ||      } j                  j                  |       |S )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   r   c                 n    t        j                  |j                  d         }j                  |d       y )Nr   ))zPOST fooN)r   rB   r@   r?   )nr5   datar+   s      r-   validz6XMLRPCWithRequestTests.test_withRequest.<locals>.valid  s+    ??7??1#56DT#89r/   )
r   r6   r   r   r7   r8   notifyFinishr   r:   render_POST)r+   r5   r  r   s   `   r-   test_withRequestz'XMLRPCWithRequestTests.test_withRequest  sf     w'"9??8]#KL	:   "..ug>!!'*r/   N)r0   r1   r2   r;   r  r&   r/   r-   r  r    s    r/   r  )FrM   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   rf  ImportErrorTestCaser!   rL  rO   r  rS   rU   r   r   r   r   r   r   r   r   rh  rl  r}  r  r  r  r  r  r  r  r&   r/   r-   <module>r     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"