
    Vh                         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y)z,
Tests for L{twisted.words.xish.xmlstream}.
    )protocol)failure)unittest)domishutility	xmlstreamc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)XmlStreamTestsc                     d| _         g | _        t        j                         | _        | | j                  _        | j                  j
                  | j                  j                  _        y )Nz	no reason)connectionLostMsgoutlistr   	XmlStream	transportappendwriteselfs    Q/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_xmlstream.pysetUpzXmlStreamTests.setUp   sI    !,",,.#' )-)<)<  &    c                     | j                   j                  t        j                  t	        | j
                                     y)zA
        Stub loseConnection because we are a transport.
        N)r   connectionLostr   Failure	Exceptionr   r   s    r   loseConnectionzXmlStreamTests.loseConnection   s-     	%%OOId&<&<=>	
r   c                     | j                   j                          | j                   j                  d       | j                  | j                  d   d       y)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   s>    
 	%%'I&a)4r   c                    g fd}| j                   j                  t         j                  |       | j                   j                          | j                   j	                  d       | j                  dt                     y)zU
        Receiving the starttag of the root element results in stream start.
        c                 (    j                  d        y 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(   sc     	' 	""9#?#?AQR%%'##H-C./r   c                    g g fd}fd}| j                   j                  t         j                  |       | j                   j                  t         j                  |       | j                   j	                          | j                   j                  d       | j                  dt                     | j                  dt                     | j                   j                  d       | j                  dt                     | j                  d   j                  t        j                               | j                  dt                     y)zN
        Receiving malformed XML results in an L{STREAM_ERROR_EVENT}.
        c                 (    j                  |        y r#   r$   )reasonstreamErrors    r   streamErrorEventz;XmlStreamTests.test_receiveBadXML.<locals>.streamErrorEvent=   s    v&r   c                 (    j                  d        y 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""9#=#=~N%%'##H-C,-C	N+##$?@C,-A,,V-?-?@AC	N+r   c                    g fd}| j                   j                  t         j                  |       | j                   j                          | j	                          | j                  dt                     | j                  d   t        j                         | j                  d   j                         | j                         y)z@
        Ending the stream fires a L{STREAM_END_EVENT}.
        c                 (    j                  |        y 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%%'C	N+ilGOO<15579O9OPr   N)	__name__
__module____qualname__r   r   r    r.   r=   rB    r   r   r
   r
      s!    =
50,4Qr   r
   c                       e Zd ZdZd Zy)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                 l    || _         || _        g | _        t        j                  j                  |        y r#   )argskwargs	observersr   EventDispatcher__init__)r   rJ   rK   s      r   rN   zDummyProtocol.__init__i   s+    	((.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y)BootstrapMixinTestszq
    Tests for L{xmlstream.BootstrapMixin}.

    @ivar factory: Instance of the factory or mixin under test.
    c                 6    t        j                         | _        y r#   )r   BootstrapMixinfactoryr   s    r   r   zBootstrapMixinTests.setUpx   s     //1r   c                     g fd}t               }| j                  j                  d|       | j                  j                  |       |j	                  dd       | j                  dt                     y)zL
        Dispatching an event fires registered bootstrap observers.
        c                 (    j                  |        y 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{   sd     	  #_
!!"3R8&&z2D"34CK(r   c                    g fd}| j                   j                  d|       | j                   j                  d|       t               }| j                   j	                  |       |j                  dd       | j                         y)zI
        Test addition and removal of a bootstrap event handler.
        c                 (    j                  |        y 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   ss    
 	  	!!"3R8$$%6;"_
&&z2D"34 r   N)rC   rD   rE   rO   r   rb   rg   rF   r   r   rQ   rQ   q   s    2) !r   rQ   c                   "    e Zd ZdZd Zd Zd Zy)!GenericXmlStreamFactoryTestsMixinz3
    Generic tests for L{XmlStream} factories.
    c                 6    t        j                         | _        y r#   )r   XmlStreamFactoryrT   r   s    r   r   z'GenericXmlStreamFactoryTestsMixin.setUp   s     113r   c                     g fd}| j                   j                  d|       | j                   j                  d      }|j                  dd       | j	                  dt                     y)zY
        The protocol factory installs bootstrap event handlers on the protocol.
        c                 (    j                  |        y 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\\''-
D+,CK(r   c                     | j                   j                  d      }| j                  | j                   |j                          y)z@
        The protocol factory is saved in the protocol.
        N)rT   rn   assertIdenticalr   ro   s     r   test_buildProtocolStoresFactoryzAGenericXmlStreamFactoryTestsMixin.test_buildProtocolStoresFactory   s0     \\''-T\\2::6r   N)rC   rD   rE   rO   r   rp   rt   rF   r   r   ri   ri      s    4) 7r   ri   c                       e Zd ZdZd Zd Zy)XmlStreamFactoryMixinTestsz7
    Tests for L{xmlstream.XmlStreamFactoryMixin}.
    c                 f    t        j                  d d       | _        t        | j                  _        y )N)test)r   XmlStreamFactoryMixinrT   rH   r   r   s    r   r   z XmlStreamFactoryMixinTests.setUp   s"     66t$G -r   c                     | j                   j                  d      }| j                  d|j                         | j                  ddi|j                         y)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   sD    
 \\''-"''*&$3r   N)rC   rD   rE   rO   r   r{   rF   r   r   rv   rv      s    .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      sz   
 & " " 9 9OQX&& OQd/H%%w'>'> / +!(++ +!\7(; 7@4!B 4r   