
    YfA                    X   d Z ddlmZ ddlm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mZmZmZmZmZ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   G d de           Z! G d de           Z" G d d          Z# G d de           Z$ G d de          Z% G d de           Z&dS )z(
Tests for L{twisted.internet.testing}.
    )annotations)Callable)verifyObject)Protocol)IPv4Address)	IAddress
IConnector	IConsumerIListeningPortIPushProducerIReactorSSLIReactorTCPIReactorUNIX
ITransport)ClientFactoryFactory)MemoryReactorNonStreamingProducerRaisingMemoryReactorStringTransport)namedAny)TestCasec                      e Zd ZdZddZddZddZddZddZdd	Z	dd
Z
ddZddZddZddZddZddZddZddZddZddZddZddZdS )StringTransportTestsz@
    Tests for L{twisted.internet.testing.StringTransport}.
    returnNonec                ,    t                      | _        d S N)r   	transportselfs    T/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_testing.pysetUpzStringTransportTests.setUp+   s    (**    c                   |                      t          t          | j                             |                      t          t          | j                             |                      t          t
          | j                             dS )zq
        L{StringTransport} instances provide L{ITransport}, L{IPushProducer},
        and L{IConsumer}.
        N)
assertTruer   r   r   r   r
   r    s    r"   test_interfacesz$StringTransportTests.test_interfaces.   sd    
 	Z@@AAA]DNCCDDDY??@@@@@r$   c                    t                      }t                      }| j                            ||           |                     | j        j        |           |                     | j        j        |           dS )zz
        L{StringTransport.registerProducer} records the arguments supplied to
        it as instance attributes.
        N)objectr   registerProducerassertIsproducer	streamingr!   r,   r-   s      r"   test_registerProducerz*StringTransportTests.test_registerProducer7   sf    
 88HH	'')<<<dn-x888dn.	:::::r$   c                <   t                      }| j                            |d           |                     t          | j        j        t                      d           |                     | j        j        |           |                     | j        j                   dS )zy
        L{StringTransport.registerProducer} raises L{RuntimeError} if a
        producer is already registered.
        TFN)	r)   r   r*   assertRaisesRuntimeErrorr+   r,   r&   r-   )r!   r,   s     r"   test_disallowedRegisterProducerz4StringTransportTests.test_disallowedRegisterProducerB   s    
 88''$777$.9688U	
 	
 	
 	dn-x888011111r$   c                   t                      }t                      }| j                            |d           | j                                         |                     | j        j                   | j                            |d           |                     | j        j        |           |                     | j        j                   dS )z
        L{StringTransport.unregisterProducer} causes the transport to forget
        about the registered producer and makes it possible to register a new
        one.
        FTN)	r)   r   r*   unregisterProducerassertIsNoner,   r+   r&   r-   )r!   oldProducernewProducers      r"   test_unregisterProducerz,StringTransportTests.test_unregisterProducerO   s     hhhh''U;;;))+++$.1222''T:::dn-{;;;011111r$   c                P    |                      t          | j        j                   dS )z
        L{StringTransport.unregisterProducer} raises L{RuntimeError} if called
        when no producer is registered.
        N)r1   r2   r   r5   r    s    r"   test_invalidUnregisterProducerz3StringTransportTests.test_invalidUnregisterProducer^   s%    
 	,(IJJJJJr$   c                F    |                      | j        j        d           dS )zO
        L{StringTransport.producerState} is initially C{'producing'}.
        	producingN)assertEqualr   producerStater    s    r"   test_initialProducerStatez.StringTransportTests.test_initialProducerStatee   s%     	5{CCCCCr$   c                x    | j                                          |                     | j         j        d           dS )zy
        L{StringTransport.pauseProducing} changes the C{producerState} of the
        transport to C{'paused'}.
        pausedN)r   pauseProducingr>   r?   r    s    r"   test_pauseProducingz(StringTransportTests.test_pauseProducingk   s9    
 	%%'''5x@@@@@r$   c                    | j                                          | j                                          |                     | j         j        d           dS )z}
        L{StringTransport.resumeProducing} changes the C{producerState} of the
        transport to C{'producing'}.
        r=   N)r   rC   resumeProducingr>   r?   r    s    r"   test_resumeProducingz)StringTransportTests.test_resumeProducings   sM    
 	%%'''&&(((5{CCCCCr$   c                x    | j                                          |                     | j         j        d           dS )z{
        L{StringTransport.stopProducing} changes the C{'producerState'} of the
        transport to C{'stopped'}.
        stoppedN)r   stopProducingr>   r?   r    s    r"   test_stopProducingz'StringTransportTests.test_stopProducing|   s9    
 	$$&&&5yAAAAAr$   c                    | j                                          |                     t          | j         j                   dS )zu
        L{StringTransport.pauseProducing} raises L{RuntimeError} if the
        transport has been stopped.
        N)r   rJ   r1   r2   rC   r    s    r"    test_stoppedTransportCannotPausez5StringTransportTests.test_stoppedTransportCannotPause   s9    
 	$$&&&,(EFFFFFr$   c                    | j                                          |                     t          | j         j                   dS )zv
        L{StringTransport.resumeProducing} raises L{RuntimeError} if the
        transport has been stopped.
        N)r   rJ   r1   r2   rF   r    s    r"   !test_stoppedTransportCannotResumez6StringTransportTests.test_stoppedTransportCannotResume   s9    
 	$$&&&,(FGGGGGr$   c                    | j                                          |                     t          | j         j                   dS )zz
        L{StringTransport.pauseProducing} raises L{RuntimeError} if the
        transport is being disconnected.
        N)r   loseConnectionr1   r2   rC   r    s    r"   &test_disconnectingTransportCannotPausez;StringTransportTests.test_disconnectingTransportCannotPause   s9    
 	%%''',(EFFFFFr$   c                    | j                                          |                     t          | j         j                   dS )z{
        L{StringTransport.resumeProducing} raises L{RuntimeError} if the
        transport is being disconnected.
        N)r   rQ   r1   r2   rF   r    s    r"   'test_disconnectingTransportCannotResumez<StringTransportTests.test_disconnectingTransportCannotResume   s9    
 	%%''',(FGGGGGr$   c                    |                      | j        j                   | j                                         |                     | j        j                   dS )zv
        L{StringTransport.loseConnection} toggles the C{disconnecting} instance
        variable to C{True}.
        N)assertFalser   disconnectingrQ   r&   r    s    r"   $test_loseConnectionSetsDisconnectingz9StringTransportTests.test_loseConnectionSetsDisconnecting   sN    
 	5666%%'''455555r$   c                    t                      }|                     t          |                                          |           dS )z
        If a host address is passed to L{StringTransport.__init__}, that
        value is returned from L{StringTransport.getHost}.
        N)r)   r+   r   getHostr!   addresss     r"   test_specifiedHostAddressz.StringTransportTests.test_specifiedHostAddress   s;    
 ((og..6688'BBBBBr$   c                    t                      }|                     t          |                                          |           dS )z
        If a peer address is passed to L{StringTransport.__init__}, that
        value is returned from L{StringTransport.getPeer}.
        )peerAddressN)r)   r+   r   getPeerr[   s     r"   test_specifiedPeerAddressz.StringTransportTests.test_specifiedPeerAddress   s>    
 ((o':::BBDDgNNNNNr$   c                |    t                                                      }|                     |t                     dS )z
        If no host address is passed to L{StringTransport.__init__}, an
        L{IPv4Address} is returned from L{StringTransport.getHost}.
        N)r   rZ   assertIsInstancer   r[   s     r"   test_defaultHostAddressz,StringTransportTests.test_defaultHostAddress   7    
 "##++--g{33333r$   c                |    t                                                      }|                     |t                     dS )z
        If no peer address is passed to L{StringTransport.__init__}, an
        L{IPv4Address} is returned from L{StringTransport.getPeer}.
        N)r   r`   rc   r   r[   s     r"   test_defaultPeerAddressz,StringTransportTests.test_defaultPeerAddress   re   r$   Nr   r   )__name__
__module____qualname____doc__r#   r'   r/   r3   r9   r;   r@   rD   rG   rK   rM   rO   rR   rT   rX   r]   ra   rd   rg    r$   r"   r   r   &   s        + + + +A A A A	; 	; 	; 	;2 2 2 22 2 2 2K K K KD D D DA A A AD D D DB B B BG G G GH H H HG G G GH H H H6 6 6 6C C C CO O O O4 4 4 44 4 4 4 4 4r$   r   c                  B    e Zd ZdZddZddZddZddZddZdd	Z	d
S )ReactorTestszA
    Tests for L{MemoryReactor} and L{RaisingMemoryReactor}.
    r   r   c                    t                      }t          t          |           t          t          |           t          t          |           dS )zt
        L{MemoryReactor} provides all of the attributes described by the
        interfaces it advertises.
        N)r   r   r   r   r   )r!   memoryReactors     r"   test_memoryReactorProvidesz'ReactorTests.test_memoryReactorProvides   sC    
 &[-000[-000\=11111r$   c                    t                      }t          t          |           t          t          |           t          t          |           dS )z{
        L{RaisingMemoryReactor} provides all of the attributes described by the
        interfaces it advertises.
        N)r   r   r   r   r   )r!   raisingReactors     r"   test_raisingReactorProvidesz(ReactorTests.test_raisingReactorProvides   sE    
 .//[.111[.111\>22222r$   c                   t                      }|                    ddt                                |                    ddt                      d          fD ]v}t	          t
          |           |                                }t	          t          |           |                     |j	        d           |                     |j
        d           w|                    dt                                }t	          t
          |           |                                }t	          t          |           |                     |j        d           dS )a  
        L{MemoryReactor.connectTCP}, L{MemoryReactor.connectSSL}, and
        L{MemoryReactor.connectUNIX} will return an L{IConnector} whose
        C{getDestination} method returns an L{IAddress} with attributes which
        reflect the values passed.
        ztest.example.comi   Ns
   /fake/path)r   
connectTCPr   
connectSSLr   r	   getDestinationr   r>   hostportconnectUNIXname)r!   rq   	connectorr\   s       r"   test_connectDestinationz$ReactorTests.test_connectDestination   s$    &$$%7}OO$$%7}PTUU
 	1 	1I Y///..00G7+++W\+=>>>W\40000!--m]__MM	Z+++**,,Xw'''}55555r$   c                   t                      }|                    dt                                |                    dt                      d          fD ]v}t	          t
          |           |                                }t	          t          |           |                     |j	        d           |                     |j
        d           w|                    dt                                }t	          t
          |           |                                }t	          t          |           |                     |j        d           dS )a  
        L{MemoryReactor.listenTCP}, L{MemoryReactor.listenSSL} and
        L{MemoryReactor.listenUNIX} will return an L{IListeningPort} whose
        C{getHost} method returns an L{IAddress}; C{listenTCP} and C{listenSSL}
        will have a default host of C{'0.0.0.0'}, and a port that reflects the
        value passed, and C{listenUNIX} will have a name that reflects the path
        passed.
        i2   Nz0.0.0.0s   /path/to/socket)r   	listenTCPr   	listenSSLr   r   rZ   r   r>   rz   r{   
listenUNIXr}   )r!   rq   r{   r\   s       r"   test_listenDefaultHostz#ReactorTests.test_listenDefaultHost   s    &##D'))44##D'))T::
 	1 	1D ...llnnG7+++W\9555W\40000''(:GIIFF^T***,,..Xw''''9:::::r$   c                ^   t                      }t                      }|                    |           |                    |           |                     |                                |g           |                    |           |                     |                                g            dS )z>
        Adding, removing, and listing readers works.
        N)r)   r   	addReaderr>   
getReadersremoveReader)r!   readerreactors      r"   test_readerszReactorTests.test_readers       //&!!!&!!!++--x888V$$$++--r22222r$   c                ^   t                      }t                      }|                    |           |                    |           |                     |                                |g           |                    |           |                     |                                g            dS )z>
        Adding, removing, and listing writers works.
        N)r)   r   	addWriterr>   
getWritersremoveWriter)r!   writerr   s      r"   test_writerszReactorTests.test_writers'  r   r$   Nrh   )
ri   rj   rk   rl   rr   ru   r   r   r   r   rm   r$   r"   ro   ro      s         2 2 2 23 3 3 36 6 6 6.; ; ; ;23 3 3 3 3 3 3 3 3 3r$   ro   c                  2    e Zd ZdZddZdd	Zdd
ZddZdS )TestConsumerzP
    A very basic test consumer for use with the NonStreamingProducerTests.
    r   r   c                0    g | _         d | _        d | _        d S r   )writesr,   producerStreamingr    s    r"   __init__zTestConsumer.__init__=  s    #% $.2r$   r,   r)   r-   boolc                "    || _         || _        dS )z
        Registers a single producer with this consumer. Just keeps track of it.

        @param producer: The producer to register.
        @param streaming: Whether the producer is a streaming one or not.
        Nr,   r   r.   s      r"   r*   zTestConsumer.registerProducerB  s     !!*r$   c                "    d| _         d| _        dS )zC
        Forget the producer we had previously registered.
        Nr   r    s    r"   r5   zTestConsumer.unregisterProducerL  s     !%r$   databytesc                :    | j                             |           dS )zz
        Some data was written to the consumer: stores it for later use.

        @param data: The data to write.
        N)r   append)r!   r   s     r"   writezTestConsumer.writeS  s      	4     r$   Nrh   )r,   r)   r-   r   r   r   )r   r   r   r   )ri   rj   rk   rl   r   r*   r5   r   rm   r$   r"   r   r   8  sn         3 3 3 3
+ + + +& & & &! ! ! ! ! !r$   r   c                  "    e Zd ZdZddZddZdS )NonStreamingProducerTestszF
    Tests for the L{NonStreamingProducer} to validate behaviour.
    r   r   c                r   t                      }t          |          }|                    |d           |                     |j        |           |                     |j        |           |                     |j                   t          d          D ]}|	                                 g d}| 
                    |j                   | 
                    |j                   | 
                    |j                   |                     |j        |           |                     t          |j	                   dS )z
        When the L{NonStreamingProducer} has resumeProducing called 10 times,
        it writes the counter each time and then fails.
        F
   )
   0   1   2   3   4   5   6   7   8   9N)r   r   r*   r+   r,   consumerrV   r   rangerF   r6   r>   r   r1   r2   )r!   r   r,   _expectedWritess        r"   test_producesOnly10Timesz2NonStreamingProducerTests.test_producesOnly10Timesa  s+   
  >>'11!!(E222h'222h'2223444r 	' 	'A$$&&&& VUU(+,,,(4555(+,,,.999 	,(@AAAAAr$   c                    t                      }t          |          }|                    |d           |                                 |                     t
          |j                   dS )zb
        When the L{NonStreamingProducer} is paused, it raises a
        L{RuntimeError}.
        FN)r   r   r*   rF   r1   r2   rC   )r!   r   r,   s      r"   test_cannotPauseProductionz4NonStreamingProducerTests.test_cannotPauseProduction{  sc    
  >>'11!!(E222 	  """,(?@@@@@r$   Nrh   )ri   rj   rk   rl   r   r   rm   r$   r"   r   r   \  sP         B B B B4A A A A A Ar$   r   c                  &    e Zd Zedd            Z dS )_SupportsNamer   strc                    d S r   rm   r    s    r"   ri   z_SupportsName.__name__  s    r$   N)r   r   )ri   rj   rk   propertyrm   r$   r"   r   r     s2           X  r$   r   c                      e Zd ZdZddZdd	Zdd
ZddZddZddZ	ddZ
ddZddZddZddZddZddZddZddZdS )DeprecationTestsz8
    Deprecations in L{twisted.test.proto_helpers}.
    testCallable[..., object]objr   r   r   c                d   d|j          }|                     |g          }|                     t          |d         d                    |                     dt	          |                     |                     ||d         d                    |                     |t          |                     d S )Nztwisted.internet.testing.r   category   message)ri   flushWarningsr>   DeprecationWarninglenassertInr+   r   )r!   r   r   new_pathwarningss        r"   helperzDeprecationTests.helper  s    =s|==%%tf--+Xa[-DEEECMM***hI 6777c8H--.....r$   c                H    ddl m} |                     | j        |           d S )Nr   )AccumulatingProtocol)twisted.test.proto_helpersr   r   test_accumulatingProtocol)r!   r   s     r"   r   z*DeprecationTests.test_accumulatingProtocol  2    CCCCCCD24HIIIIIr$   c                H    ddl m} |                     | j        |           d S )Nr   )LineSendingProtocol)r   r   r   test_lineSendingProtocol)r!   r   s     r"   r   z)DeprecationTests.test_lineSendingProtocol  s2    BBBBBBD13FGGGGGr$   c                H    ddl m} |                     | j        |           d S )Nr   )FakeDatagramTransport)r   r   r   test_fakeDatagramTransport)r!   r   s     r"   r   z+DeprecationTests.test_fakeDatagramTransport  s2    DDDDDDD35JKKKKKr$   c                H    ddl m} |                     | j        |           d S )Nr   )r   )r   r   r   test_stringTransport)r!   r   s     r"   r   z%DeprecationTests.test_stringTransport  s1    >>>>>>D-?????r$   c                H    ddl m} |                     | j        |           d S )Nr   ) StringTransportWithDisconnection)r   r   r   %test_stringTransportWithDisconnection)r!   r   s     r"   r   z6DeprecationTests.test_stringTransportWithDisconnection  s=    OOOOOO68X	
 	
 	
 	
 	
r$   c                H    ddl m} |                     | j        |           d S )Nr   )StringIOWithoutClosing)r   r   r   test_stringIOWithoutClosing)r!   r   s     r"   r   z,DeprecationTests.test_stringIOWithoutClosing  s2    EEEEEED46LMMMMMr$   c                H    ddl m} |                     | j        |           d S )Nr   )_FakeConnector)r   r   r   test__fakeConnector)r!   r   s     r"   r   z$DeprecationTests.test__fakeConnector  s1    ======D,n=====r$   c                H    ddl m} |                     | j        |           d S )Nr   )	_FakePort)r   r   r   test__fakePort)r!   r   s     r"   r   zDeprecationTests.test__fakePort  s1    888888D'33333r$   c                H    ddl m} |                     | j        |           d S )Nr   )r   )r   r   r   test_memoryReactor)r!   r   s     r"   r   z#DeprecationTests.test_memoryReactor  s1    <<<<<<D+];;;;;r$   c                H    ddl m} |                     | j        |           d S )Nr   )MemoryReactorClock)r   r   r   test_memoryReactorClock)r!   r   s     r"   r   z(DeprecationTests.test_memoryReactorClock  s2    AAAAAAD02DEEEEEr$   c                H    ddl m} |                     | j        |           d S )Nr   )r   )r   r   r   test_raisingMemoryReactor)r!   r   s     r"   r   z*DeprecationTests.test_raisingMemoryReactor  r   r$   c                H    ddl m} |                     | j        |           d S )Nr   )r   )r   r   r   test_nonStreamingProducer)r!   r   s     r"   r   z*DeprecationTests.test_nonStreamingProducer  r   r$   c                H    ddl m} |                     | j        |           d S )Nr   )waitUntilAllDisconnected)r   r   r   test_waitUntilAllDisconnected)r!   r   s     r"   r   z.DeprecationTests.test_waitUntilAllDisconnected  s2    GGGGGGD68PQQQQQr$   c                H    ddl m} |                     | j        |           d S )Nr   )EventLoggingObserver)r   r   r   test_eventLoggingObserver)r!   r   s     r"   r   z*DeprecationTests.test_eventLoggingObserver  r   r$   N)r   r   r   r   r   r   rh   )ri   rj   rk   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   r$   r"   r   r     st        / / / /J J J J
H H H H
L L L L
@ @ @ @

 
 
 
N N N N
> > > >
4 4 4 4
< < < <
F F F F
J J J J
J J J J
R R R R
J J J J J Jr$   r   N)'rl   
__future__r   typingr   zope.interface.verifyr   typing_extensionsr   twisted.internet.addressr   twisted.internet.interfacesr   r	   r
   r   r   r   r   r   r   twisted.internet.protocolr   r   twisted.internet.testingr   r   r   r   twisted.python.reflectr   twisted.trial.unittestr   r   ro   r   r   r   r   rm   r$   r"   <module>r      s    # " " " " "       . . . . . . & & & & & & 0 0 0 0 0 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 = < < < < < < <            , + + + + + + + + + + +e4 e4 e4 e4 e48 e4 e4 e4Pg3 g3 g3 g3 g38 g3 g3 g3T!! !! !! !! !! !! !! !!H+A +A +A +A +A +A +A +A\    H   SJ SJ SJ SJ SJx SJ SJ SJ SJ SJr$   