
    Yfhw                        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+n# e,$ r dZ+Y nw xY w G d dej-                  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!j7                  Z8 G d# d$e!j&                  Z9 G d% d&e!j&                  Z: G d' d(ej-                  Z; G d) d*e;          Z< G d+ d,ej-                  Z= G d- d.          Z> G d/ d0e>ej-                  Z? G d1 d2e>ej-                  Z@ G d3 d4e;          ZA G d5 d6e;          ZB G d7 d8ej-                  ZC G d9 d:ej-                  ZD G d; d<ej-                  ZEdS )=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dS )AsyncXMLRPCTestsz5
    Tests for L{XMLRPC}'s support of Deferreds.
    c                 0   t          dg          | _        d| j        _        t          t          dt          j        d          fz            | j        _        t          j	                    x| _
         G fddt                    } |            | _        d S )N POSTasync c                       e Zd Z fdZdS )-AsyncXMLRPCTests.setUp.<locals>.AsyncResourcec                     S Nr&   )selfresults    N/var/www/html/env/lib/python3.11/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   s    #RD))$'w	(;(;<< 
  
  %~///	 	 	 	 	 	 	F 	 	 	 &r/   c                    | j                             | j                   |                     | j        j        g            | j                            d           t          j        d	                    | j        j                            }|                     |d           |                     | j        j
        d           dS )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22X&&&sxx(<==>>2333.22222r/   c                 j   | j                             | j                   | j                            t	          j        t          d                               | j                            d           | 	                    | j        j
        g            | 	                    | j        j        d           dS )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\***%%gon[6Q6Q&R&RSSSX&&&-r222.22222r/   N)r0   r1   r2   __doc__r;   rF   rL   r&   r/   r-   r!   r!   .   sK         ( ( (3 3 33 3 3 3 3r/   r!   c                       e Zd ZdS )TestRuntimeErrorNr0   r1   r2   r&   r/   r-   rO   rO   ^           Dr/   rO   c                       e Zd ZdS )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dS )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                 B    t          j        t                                S r*   )r   failrS   rK   s    r-   xmlrpc_deferFailzTest.xmlrpc_deferFail   s    z.**+++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                 P    t          j        t          j        dd                    S )N   hi)r   rq   r   ry   rK   s    r-   xmlrpc_deferFaultzTest.xmlrpc_deferFault   s    z&,r400111r/   c                 @    d}||k    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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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"     N  		
r/   c                     	 t          j        | |          S # t          j        $ r1 |                    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   sp    	)$>>>$ 	 	 	''	22 l(*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778K     , , ,  ) ) )2 2 2  5 5 5   (K
 
 [
	 	 	 	 	r/   rU   c                       e Zd ZdZd Zd ZdS )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                 X    |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""9#NBBB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dS )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dS )TestAuthHeaderzU
    This is used to get the header info so that we can test
    authentication.
    c                 H    t                               |            d | _        d S r*   )rU   __init__r5   rK   s    r-   r   zTestAuthHeader.__init__   s    dr/   c                 F    || _         t                              | |          S r*   )r5   rU   r>   )r+   r5   s     r-   r>   zTestAuthHeader.render   s    {{4)))r/   c                 f    | j                                         | j                                         fS r*   )r5   getUsergetPasswordrK   s    r-   xmlrpc_authinfozTestAuthHeader.xmlrpc_authinfo   s)    |##%%t|'?'?'A'AAAr/   N)r0   r1   r2   rM   r   r>   r   r&   r/   r-   r   r      sP         
  * * *B B B B Br/   r   c                   $    e Zd ZdZd Zd Zd ZdS )TestQueryProtocolz_
    QueryProtocol for tests that saves headers received and sent,
    inside the factory.
    c                 f    | j         | j        _         t          j                            |            d S r*   )	transportfactoryr   QueryProtocolconnectionMaderK   s    r-   r   z TestQueryProtocol.connectionMade   s+    !%++D11111r/   c                 H    || j         j        |                                <   d S r*   )r   headerslowerr+   r   vals      r-   handleHeaderzTestQueryProtocol.handleHeader  s    ,/SYY[[)))r/   c                     || j         j        |                                <   t          j                            | ||           dS )zA
        Keep sent headers so we can inspect them later.
        N)r   sent_headersr   r   r   
sendHeaderr   s      r-   r   zTestQueryProtocol.sendHeader  s<     25!#))++.''c377777r/   N)r0   r1   r2   rM   r   r   r   r&   r/   r-   r   r      sK         
2 2 20 0 08 8 8 8 8r/   r   c                       e Zd ZdZeZd ZdS )TestQueryFactoryzE
    QueryFactory using L{TestQueryProtocol} for saving headers.
    c                 V    i | _         i | _        t          j        j        | g|R i | d S 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     s4          !H< < < < <r/   r   c                       e Zd ZdZd ZdS )TestQueryFactoryCancelz{
    QueryFactory that saves a reference to the
    L{twisted.internet.interfaces.IConnector} to test connection lost.
    c                     || _         d S 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dS )XMLRPCTestsc                     t          j        dt          j        t	                                d          | _        | j                                        j        | _        g | _        d S Nr   	127.0.0.1	interface)	r   	listenTCPr   SiterU   pgetHostport	factoriesrK   s    r-   r;   zXMLRPCTests.setUp&  sJ    "1fk$&&&9&9[QQQFNN$$)	r/   c                 B    g | _         | j                                        S r*   )r   r   stopListeningrK   s    r-   tearDownzXMLRPCTests.tearDown+  s    v##%%%r/   c                 R    t          |i |}| 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/  s1    
 #D3F33g&&&r/   Nc                     t          j        t          d| j        z                      }|| j        |_        n||_        |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  s@     L'=	'IJJKK?!.ANN$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 ]V\  }}} |                                  j        |g|R  }|                    | j        |           |                    |           Wt          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AB
  + 	 	D$'

'4t444AMM$*D111IIaLLLL!"t<<<<r/   c                                                                            dd          } fd} fd}|                    |           |                    |           |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        d         j        d         d                                j        d         j        d         d           d S )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^  s^    q!)/:<V   T^A.67HI6RRRRRr/   c                                         j        d         j        d         d                                j        d         j        d         d                                j        d         j        d         d           d S )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WWWWWr/   r   r   r   )r+   r   r   r  s   `   r-   test_headerszXMLRPCTests.test_headersV  s     JJLL##Ix88	S 	S 	S 	S 	S	X 	X 	X 	X 	X 	
*+++	*+++r/   c                 4    t                      t          t          t          j                  g          t          j                                        fd           g }dD ]{\  }}                                 	                    |          } 
                    |t          j                  }|                    |f fd	           |                    |           |t          j        |d          } fd}|                    |           |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( K K r/   ))rV   rq   )rV   	deferFail)rv   fault)rW   noSuchMethod)r|   
deferFault)rX   SESSION_TESTc                 :                         | j        |          S r*   )r?   	faultCode)exccoder+   s     r-   r  z)XMLRPCTests.test_errors.<locals>.<lambda>  s    1A1A#-QU1V1V r/   Tr   c                    j         D ]#}                    |j        d         d           $                    dt	                               d         d         j        }d         d         j        }t          |t                    r                    |t                     n6                    |t                                         |t                     
                    t          t                     d S )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    >    OO46P    a[!1!1222Q.4BQ.4B"n-- :%%b*:;;;;%%b*:;;;%%b.999""#3^DDDD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(BSTTTU
 
 	&x000KKKKLLL!
 	 	D* 

''
33A""1fl33AMM4VVVVVWWWIIaLLLLrD999	E 	E 	E 	E 	E 	E" 	
br/   c                 b   fd|                                                    ddd          }|                     j        j        j        d           |                                 |                     j        j        j        d           |                     |t          j
                  }|S )z
        A deferred from the Proxy can be cancelled, disconnecting
        the L{twisted.internet.interfaces.IConnector}.
        c                  4    t          | i |_        j        S r*   )r   f)r   kwr   s     r-   r   z(XMLRPCTests.test_cancel.<locals>.factory  s    .;;;GI9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7GI/5~FFF	


,2NCCCq%"677r/   c                      t          j        t                    }|                    dt	          d j        fz                      } fd}|                    |           |S )zN
        A classic GET on the xml server should return a NOT_ALLOWED.
        s   GETr   c                 R                         | j        t          j                   d S 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  sk     W%%MM&-0F$)0U"V"VWW	> 	> 	> 	> 	> 	
m$$$r/   c           	      F    t          j        t                    }|                    t	          d j        fz            dt          j        t          d                              }|                    t           j	                    fd}|                    |           |S )zL
        Test that an invalid XML input returns an L{xmlrpc.Fault}.
        r   s   POSTs   foo)urir6   bodyProducerc                 ^                         t          j        t          j        |            d S r*   )assertRaisesr   ry   r   rB   )r,   r+   s    r-   r$  z,XMLRPCTests.test_errorXMLContent.<locals>.cb  s%    flIOVDDDDDr/   )
r   r:  r   r5   r   r   FileBodyProducerr   r   readBody)r+   r;  r   r$  s   `   r-   test_errorXMLContentz XMLRPCTests.test_errorXMLContent  s     W%%MM4	|CDD0AA  
 

 	
fo&&&	E 	E 	E 	E 	E 	
br/   c                     t          j                    }|                                                     d|          }|                    | 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  sK     !##JJLL##FD11	d&---r/   c                     t                      t          t          t          j                  g          t          j                                        fd                                            	                    dd          }d } 
                    t          d|                                |t                    } fd}|                    |           |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                                         dt                                                   d         d         j        t                                         t                              t                              d           d S )Nr=   r   r  )r  r  r  r  rL  r?   r   )ignoredr#  r+   s    r-   cbFailedz6XMLRPCTests.test_doubleEncodingError.<locals>.cbFailed  su    a[!1!1222!!+a."?"E|TTTS!7!7!E!EFFJJJJ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(BSTTTU
 
 	&x000KKKKLLLJJLL##FB//	A 	A 	A 	

9gy111
 q),,	K 	K 	K 	K 	K 	K 	
hr/   c                                                                            dd          } fd}|                    |          S )zV
        The connection to the web server is closed when the request is done.
        r   r#   c                     j         \  }                    |j        j                                       |j        j                   d S r*   )r   assertFalser   	connected
assertTruer/  )rO  r   r+   s     r-   responseDonezBXMLRPCTests.test_closeConnectionAfterRequest.<locals>.responseDone  sD    IWW.8999OOG-:;;;;;r/   r  )r+   r   rY  s   `  r-    test_closeConnectionAfterRequestz,XMLRPCTests.test_closeConnectionAfterRequest   sO     JJLL##FB//	< 	< 	< 	< 	<
 }}\***r/   c                     t                      }t          j        dd|          }|                    d           |                     |j        d         d         d           dS )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  si      //"3
 
 
 	&&&+A.q1377777r/   zOpenSSL not presentc                     t                      }t          j        dd|          }|                    d           |                     |j        d         d         d           dS )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  si      //#C
 
 
 	&&&+A.q137777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   %  s         
& & &     = = ="  8. . .`  "    $	 	 	! ! !F+ + +8 8 8 VG*++8 8 ,+8 8 8r/   r   c                       e Zd ZdZddZdS )XMLRPCProxyWithoutSlashTestsz3
    Test with proxy that doesn't add a slash.
    Nc                     t          j        t          d| j        z                      }|| j        |_        n||_        |S )Nhttp://127.0.0.1:%dr   r   s      r-   r   z"XMLRPCProxyWithoutSlashTests.proxy.  s>    L'<ty'HIIJJ?!.ANN$ANr/   r*   )r0   r1   r2   rM   r   r&   r/   r-   rh  rh  )  s2              r/   rh  c                   *    e Zd ZdZd Zd Zd Zd ZdS ) XMLRPCPublicLookupProcedureTestszr
    Tests for L{XMLRPC}'s support of subclasses which override
    C{lookupProcedure} and C{listProcedures}.
    c                 B   t          j        dt          j        |          d          | _        |                     | j        j                   | j                                        j        | _        t          j
        t          d| j        z                      | _        d S )Nr   r   r   rj  )r   r   r   r   r   r'  r   r   r   r   r   r   r   )r+   r:   s     r-   createServerz-XMLRPCPublicLookupProcedureTests.createServer=  sw    "1fk(&;&;{SSS,---FNN$$)	\-0E	0Q"R"RSS


r/   c                     |                      t                                 d}| j                            d|          }|                    | 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  sW    
 	-//000J!!&$//	d&---r/   c                     |                      t                                 | j                            dd          }|                     |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  sR     	-//000J!!&'22q&,//r/   c                      t                      }t          |                                |            j                            d          } fd}|                    |           |S )z
        A subclass of L{XMLRPC} can override C{listProcedures} to define
        Overriding listProcedures should prevent introspection from being
        broken.
        system.listMethodsc                 4                         d|            d S )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  sz     &''"""(###J!!"677	- 	- 	- 	- 	- 	
fr/   N)r0   r1   r2   rM   rn  rq  r*  r{  r&   r/   r-   rl  rl  7  s]         
T T T	 	 		 	 	    r/   rl  c                   $    e Zd ZdZd Zd Zd ZdS )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           
      f   | j         di}t          j        dt          j        t          di |          d          | _        |                     | j        j                   | j        	                                j
        | _
        t          j        t          d| j
        fz            fi || _        dS )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
 
 
 	,---FNN$$)	\0DI<?@@
 
DJ
 



r/   c                     | j                             d| 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;     J!!'4:66	d&
333r/   c                     | j                             dd| j        i          }|                    | 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    
 J!!'C+<==	d&dj(9:::r/   N)r0   r1   r2   rM   r;   r  r  r&   r/   r-   r}  r}  n  sK         
 
 
      r/   r}  c                       e Zd ZdZdZdZdS )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EEEr/   r  c                   @    e Zd ZdZdZ ej        dddddd          Zd	S )
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66EEEr/   r  c                   8    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
d	S )
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        | _        g | _        d S r   )	r   r   r   r   r   r   r   r   r   rK   s    r-   r;   zXMLRPCAuthenticatedTests.setUp  sU    "v{>++,,
 
 
 FNN$$)	r/   c                 "   dt          | j                  t          | j                  | j        fz  }t	          j        t          |                    }|                    d          }|                    | 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  s    *##''I.
 

 Ls++,,LL$$	d&DM(BCCCr/   c                     t          j        t          d| j        fz            | j        | j                  }|                    d          }|                    | 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  sj    L0DI<?@@IM
 

 LL$$	d&DM(BCCCr/   c                     | j         dz  }t          j        t          d| j        fz            | j        |          }|                    d          }|                    | 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  st     }r)L0DI<?@@I
 

 LL$$	d&L(ABBBr/   c                     t          j        t          d| j        fz            | j        | j                  }|                    d          }|                    | j        | j        | j        g           |S )Nzhttp://wrong:info@127.0.0.1:%d/r  r  r  s      r-   test_explicitAuthInfoOverridez6XMLRPCAuthenticatedTests.test_explicitAuthInfoOverride  sj    L;tylJKKIM
 

 LL$$	d&DM(BCCCr/   N)r0   r1   r2   rM   r  r  r;   r  r  r  r  r&   r/   r-   r  r    su         
 DH  	 	 	         r/   r  c                   &    e Zd Zd Zd Zd Zd ZdS )XMLRPCIntrospectionTestsc                     t                      }t          |           t          j        dt	          j        |          d          | _        | j                                        j        | _        g | _	        d S r   )
rU   r   r   r   r   r   r   r   r   r   )r+   r   s     r-   r;   zXMLRPCIntrospectionTests.setUp  s]       "1fk&&9&9[QQQFNN$$)	r/   c                       fd}                                                      d          }|                    |           |S )Nc                 `    |                                                       | g d           d S )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  sD    JJLLL      r/   rv  r  )r+   r  r   s   `  r-   r{  z)XMLRPCIntrospectionTests.test_listMethods  sQ    	 	 	 	 	. JJLL##$899	i   r/   c                     g d}g }|D ]]\  }}|                                                      d|          }|                    | j        |           |                    |           ^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  s    
 
 
 * 	 	ND(

''(;TBBAMM$*H555IIaLLLL!"t<<<<r/   c                    ddg dg dgfdg dgfg}g }|D ]]\  }}|                                                      d|          }|                    | j        |           |                    |           ^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,J,JKL00012
 * 	 	ND(

''(@$GGAMM$*H555IIaLLLL!"t<<<<r/   N)r0   r1   r2   r;   r{  r  r  r&   r/   r-   r  r    sP            8= = == = = = =r/   r  c                   $    e Zd ZdZd Zd Zd ZdS )XMLRPCClientErrorHandlingTestsz3
    Test error handling on the xmlrpc client.
    c                     t          j        dd          | _        d| j        _        t	          j        dt          j        | j                  d          | _        d S )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  sV    9=
 
  $%v{4=))[
 
 
			r/   c                 4    | j                                         S r*   )r   r   rK   s    r-   r   z'XMLRPCClientErrorHandlingTests.tearDownA  s    y&&(((r/   c                     t          j        t          d| j                                        j        fz                      }|                     |                    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  s`    
 0DI4E4E4G4G4L3NNOO
 
 !!%"2"2<"@"@*MMMr/   N)r0   r1   r2   rM   r;   r   r  r&   r/   r-   r  r  2  sP         
 
 
) ) )N N N N Nr/   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )QueryFactoryParseResponseTestsz>
    Test the behaviour of L{QueryFactory.parseResponse}.
    c           	          t          d d dd d dd          | _        t          j        d          | _        d| _        t          j        t                                | _	        d S )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  si     )
 
 
 &OE22( on&6&677r/   c                     | 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  sL    
 & 	
d'<dkJJJ''(9:::r/   c                     | 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  sL    
 & 	
T&;T[III''(8999r/   c                     | 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  sK    
 & 	
T&;T[III##Hi888r/   c                     d}| 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00!!!Z000r/   N)	r0   r1   r2   rM   r;   r  r  r  r  r&   r/   r-   r  r  O  si         8 8 8(      1 1 1 1 1r/   r  c                       e Zd Zd Zd ZdS )XMLRPCWithRequestTestsc                 ,    t                      | _        d S r*   )rU   r:   rK   s    r-   r;   zXMLRPCWithRequestTests.setUp  s    r/   c                     t          d          }d|_        t          t          j        dd                    |_         fd}|                                                    ||          } 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                 r    t          j        |j        d                   }                    |d           d S )Nr   ))zPOST fooN)r   rB   r@   r?   )nr5   datar+   s      r-   validz6XMLRPCWithRequestTests.test_withRequest.<locals>.valid  s6    ?7?1#566DT#899999r/   )
r   r6   r   r   r7   r8   notifyFinishr   r:   render_POST)r+   r5   r  r   s   `   r-   test_withRequestz'XMLRPCWithRequestTests.test_withRequest  s     w''"9?8]#K#KLL	: 	: 	: 	: 	:   ""..ug>>!!'***r/   N)r0   r1   r2   r;   r  r&   r/   r-   r  r    s2              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 1 1 1 1 1 H H H H H H H H            # " " " " " = = = = = = = = . . . . . . " " " " " " < < < < < < < < < < < < < < 2 2 2 2 2 2               K&''' GG    GGG-3 -3 -3 -3 -3x( -3 -3 -3`	 	 	 	 	| 	 	 		 	 	 	 	Z 	 	 	\ \ \ \ \6 \ \ \~
 
 
 
 
& 
 
 
*
 
 
 
 
 
 
 
B B B B BT B B B$8 8 8 8 8, 8 8 8*
< 
< 
< 
< 
<v* 
< 
< 
<# # # # #V0 # # #A8 A8 A8 A8 A8(# A8 A8 A8H    ;   4 4 4 4 4x'8 4 4 4n- - - - - - - -`    3X5F   7 7 7 7 75x7H 7 7 7= = = = ={ = = =@>= >= >= >= >={ >= >= >=BN N N N NX%6 N N N:O1 O1 O1 O1 O1X%6 O1 O1 O1d    X.     s   6B BB