
    Yf                         d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
  G d dej                  Z G d d	ej        e	j                  Z G d
 dej                  Z G d de          Z G d de          ZdS )z,
Tests for L{twisted.words.xish.xmlstream}.
    )protocol)failure)unittest)domishutility	xmlstreamc                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )XmlStreamTestsc                     d| _         g | _        t          j                    | _        | | j        _        | j        j        | j        j        _        d S )Nz	no reason)connectionLostMsgoutlistr   	XmlStream	transportappendwriteselfs    S/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_xmlstream.pysetUpzXmlStreamTests.setUp   sC    !,",..#' )-)< &&&    c                     | j                             t          j        t	          | j                                       dS )zA
        Stub loseConnection because we are a transport.
        N)r   connectionLostr   Failure	Exceptionr   r   s    r   loseConnectionzXmlStreamTests.loseConnection   s@     	%%OId&<==>>	
 	
 	
 	
 	
r   c                     | j                                          | j                             d           |                     | j        d         d           dS )zq
        Calling L{xmlstream.XmlStream.send} results in the data being written
        to the transport.
        s   <root>r   N)r   connectionMadesendassertEqualr   r   s    r   	test_sendzXmlStreamTests.test_send   sP    
 	%%'''I&&&a)44444r   c                    g fd}| j                             t           j        |           | j                                          | j                             d           |                     dt                               dS )zU
        Receiving the starttag of the root element results in stream start.
        c                 2                         d            d S Nr   )rootelemstreamStarteds    r   streamStartEventz9XmlStreamTests.test_receiveRoot.<locals>.streamStartEvent.   s      &&&&&r   <root>   N)r   addObserverSTREAM_START_EVENTr   dataReceivedr   len)r   r'   r&   s     @r   test_receiveRootzXmlStreamTests.test_receiveRoot(   s     	' 	' 	' 	' 	' 	""9#?AQRRR%%'''##H---C../////r   c                    g g fd}fd}| j                             t           j        |           | j                             t           j        |           | j                                          | j                             d           |                     dt                               |                     dt                               | j                             d           |                     dt                               |                     d         	                    t          j                             |                     dt                               dS )zN
        Receiving malformed XML results in an L{STREAM_ERROR_EVENT}.
        c                 2                         |            d S r#   r$   )reasonstreamErrors    r   streamErrorEventz;XmlStreamTests.test_receiveBadXML.<locals>.streamErrorEvent=   s    v&&&&&r   c                 2                         d            d S r#   r$   )_	streamEnds    r   streamEndEventz9XmlStreamTests.test_receiveBadXML.<locals>.streamEndEvent@   s    T"""""r   r(   r   z<child><unclosed></child>r)   N)r   r*   STREAM_ERROR_EVENTSTREAM_END_EVENTr   r,   r   r-   
assertTruecheckr   ParserError)r   r3   r7   r6   r2   s      @@r   test_receiveBadXMLz!XmlStreamTests.test_receiveBadXML6   s]    		' 	' 	' 	' 	'	# 	# 	# 	# 	# 	""9#?AQRRR""9#=~NNN%%'''##H---C,,---C	NN+++##$?@@@C,,---A,,V-?@@AAAC	NN+++++r   c                    g fd}| j                             t           j        |           | j                                          |                                  |                     dt                               |                     d         t          j	                   |                     d         
                                | j                   dS )z@
        Ending the stream fires a L{STREAM_END_EVENT}.
        c                 2                         |            d S r#   r$   )r1   r6   s    r   r7   z5XmlStreamTests.test_streamEnd.<locals>.streamEndEventV   s    V$$$$$r   r)   r   N)r   r*   r9   r   r   r   r-   assertIsInstancer   r   getErrorMessager   )r   r7   r6   s     @r   test_streamEndzXmlStreamTests.test_streamEndP   s     		% 	% 	% 	% 	% 	""9#=~NNN%%'''C	NN+++ilGO<<<155779OPPPPPr   N)	__name__
__module____qualname__r   r   r    r.   r=   rB    r   r   r
   r
      ss        = = =
 
 
5 5 50 0 0, , ,4Q Q Q Q Qr   r
   c                       e Zd ZdZd ZdS )DummyProtocolz
    I am a protocol with an event dispatcher without further processing.

    This protocol is only used for testing XmlStreamFactoryMixin to make
    sure the bootstrap observers are added to the protocol instance.
    c                 n    || _         || _        g | _        t          j                            |            d S r#   )argskwargs	observersr   EventDispatcher__init__)r   rJ   rK   s      r   rN   zDummyProtocol.__init__i   s4    	((.....r   N)rC   rD   rE   __doc__rN   rF   r   r   rH   rH   a   s-         / / / / /r   rH   c                   $    e Zd ZdZd Zd Zd ZdS )BootstrapMixinTestszq
    Tests for L{xmlstream.BootstrapMixin}.

    @ivar factory: Instance of the factory or mixin under test.
    c                 6    t          j                    | _        d S r#   )r   BootstrapMixinfactoryr   s    r   r   zBootstrapMixinTests.setUpx   s     /11r   c                    g fd}t                      }| j                            d|           | j                            |           |                    dd           |                     dt                               dS )zL
        Dispatching an event fires registered bootstrap observers.
        c                 2                         |            d S r#   r$   datacalleds    r   cbz6BootstrapMixinTests.test_installBootstraps.<locals>.cb       MM$r   //event/myeventNr)   )rH   rT   addBootstrapinstallBootstrapsdispatchr   r-   r   rZ   
dispatcherrY   s      @r   test_installBootstrapsz*BootstrapMixinTests.test_installBootstraps{   s     	  	  	  	  	  #__
!!"3R888&&z222D"3444CKK(((((r   c                 (   g fd}| j                             d|           | j                             d|           t                      }| j                             |           |                    dd           |                                dS )zI
        Test addition and removal of a bootstrap event handler.
        c                 2                         |            d S r#   r$   rW   s    r   rZ   z:BootstrapMixinTests.test_addAndRemoveBootstrap.<locals>.cb   r[   r   r\   N)rT   r]   removeBootstraprH   r^   r_   assertFalser`   s      @r   test_addAndRemoveBootstrapz.BootstrapMixinTests.test_addAndRemoveBootstrap   s    
 	  	  	  	  	  	!!"3R888$$%6;;;"__
&&z222D"3444     r   N)rC   rD   rE   rO   r   rb   rg   rF   r   r   rQ   rQ   q   sK         2 2 2) ) ) ! ! ! ! !r   rQ   c                   $    e Zd ZdZd Zd Zd ZdS )!GenericXmlStreamFactoryTestsMixinz3
    Generic tests for L{XmlStream} factories.
    c                 6    t          j                    | _        d S r#   )r   XmlStreamFactoryrT   r   s    r   r   z'GenericXmlStreamFactoryTestsMixin.setUp   s     133r   c                     g fd}| j                             d|           | j                             d          }|                    dd           |                     dt                               dS )zY
        The protocol factory installs bootstrap event handlers on the protocol.
        c                 2                         |            d S r#   r$   rW   s    r   rZ   zRGenericXmlStreamFactoryTestsMixin.test_buildProtocolInstallsBootstraps.<locals>.cb   r[   r   r\   Nr)   )rT   r]   buildProtocolr_   r   r-   )r   rZ   xsrY   s      @r   $test_buildProtocolInstallsBootstrapszFGenericXmlStreamFactoryTestsMixin.test_buildProtocolInstallsBootstraps   s     	  	  	  	  	  	!!"3R888\''--
D+,,,CKK(((((r   c                 z    | j                             d          }|                     | j         |j                    dS )z@
        The protocol factory is saved in the protocol.
        N)rT   rn   assertIdenticalr   ro   s     r   test_buildProtocolStoresFactoryzAGenericXmlStreamFactoryTestsMixin.test_buildProtocolStoresFactory   s9     \''--T\2:66666r   N)rC   rD   rE   rO   r   rp   rt   rF   r   r   ri   ri      sK         4 4 4) ) ) 7 7 7 7 7r   ri   c                       e Zd ZdZd Zd ZdS )XmlStreamFactoryMixinTestsz7
    Tests for L{xmlstream.XmlStreamFactoryMixin}.
    c                 ^    t          j        d d           | _        t          | j        _        d S )N)test)r   XmlStreamFactoryMixinrT   rH   r   r   s    r   r   z XmlStreamFactoryMixinTests.setUp   s)     6t$GGG -r   c                     | j                             d          }|                     d|j                   |                     ddi|j                   dS )zb
        Arguments passed to the factory are passed to protocol on
        instantiation.
        Nr#   rx   )rT   rn   r   rJ   rK   rs   s     r   "test_buildProtocolFactoryArgumentsz=XmlStreamFactoryMixinTests.test_buildProtocolFactoryArguments   sS    
 \''--"'***&$33333r   N)rC   rD   rE   rO   r   r{   rF   r   r   rv   rv      s<         . . .4 4 4 4 4r   rv   N)rO   twisted.internetr   twisted.pythonr   twisted.trialr   twisted.words.xishr   r   r   TestCaser
   ProtocolrM   rH   rQ   ri   rv   rF   r   r   <module>r      sd   
 & % % % % % " " " " " " " " " " " " 9 9 9 9 9 9 9 9 9 9OQ OQ OQ OQ OQX& OQ OQ OQd/ / / / /H%w'> / / / +! +! +! +! +!(+ +! +! +!\7 7 7 7 7(; 7 7 7@4 4 4 4 4!B 4 4 4 4 4r   