
    Vh                        d Z ddlmZ ddlmZ ddlmZmZmZ	 ddl
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e      Zy)zY
Tests for L{twisted.internet.abstract}, a collection of APIs for implementing
reactors.
    )annotations)Union)examplegiven
strategies)FileDescriptorisIPv6Address)SynchronousTestCase   )_FakeFDSetReactorc                  @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
IPv6AddressTestszw
    Tests for L{isIPv6Address}, a function for determining if a particular
    string is an IPv6 address literal.
    c                8    | j                  t        d             y)zB
        The empty string is not an IPv6 address literal.
         NassertFalser	   selfs    S/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_abstract.py
test_emptyzIPv6AddressTests.test_empty   s     	r*+    c                8    | j                  t        d             y)zA
        A single C{":"} is not an IPv6 address literal.
        :Nr   r   s    r   
test_colonzIPv6AddressTests.test_colon   s     	s+,r   c                8    | j                  t        d             y)z@
        C{"::1"} is the IPv6 loopback address literal.
        z::1N
assertTruer	   r   s    r   test_loopbackzIPv6AddressTests.test_loopback%   s     	e,-r   c                    | j                  t        d             | j                  t        d             | j                  t        d             y)z
        An otherwise valid IPv6 address literal may also include a C{"%"}
        followed by an arbitrary scope identifier.
        zfe80::1%eth0	fe80::2%1zfe80::3%en2Nr   r   s    r   test_scopeIDzIPv6AddressTests.test_scopeID+   s7    
 	n56k23m45r   c                    | j                  t        d             | j                  t        d             | j                  t        d             y)zv
        An otherwise invalid IPv6 address literal is still invalid with a
        trailing scope identifier.
        z%eth0z:%eth0
hello%eth0Nr   r   s    r   test_invalidWithScopeIDz(IPv6AddressTests.test_invalidWithScopeID4   s=    
 	w/0x01|45r   c                   | j                  t        d             | j                  t        d             | j                  t        d             | j                  t        d             | j                  t        d             y)zQ
        L{isIPv6Address} evaluates ASCII-encoded bytes as well as text.
        s	   fe80::2%1r    u   䌡r#   s
   hello%eth0N)r   r	   r   r   s    r   test_unicodeAndBytesz%IPv6AddressTests.test_unicodeAndBytes=   s_     	l34k23x01|45}56r   N)returnNone)
__name__
__module____qualname____doc__r   r   r   r!   r$   r&    r   r   r   r      s%    
,-.66
7r   r   c                  4    e Zd ZdZdZdZ	 	 	 	 	 	 ddZddZy)	TrackingFileDescriptorz>
    Write a limited amount, and track what gets written.
    TFc                j    || _         || _        || _        t        j                  | t                      y N)
operationswritten
SEND_LIMITr   __init__r   )r   r2   r3   
send_limits       r   r5   zTrackingFileDescriptor.__init__S   s-     %$&7&9:r   c                    | j                   j                  d      }t        |t              sJ t	        |t        |            }| j                  j                  |d |        |S )Nr   )r2   pop
isinstanceintminlenr3   append)r   datatoWrites      r   writeSomeDataz$TrackingFileDescriptor.writeSomeData[   sS    //%%a('3'''gs4y)D'N+r   N)r2   zlist[Union[int, bytes]]r3   zlist[bytes]r6   r:   )r>   bytesr'   r:   )r)   r*   r+   r,   	connected_writeDisconnectedr5   r@   r-   r   r   r/   r/   J   s6    
 I;1;<G;UX;r   r/   c                      e Zd ZdZ e ej                   ej                   ej                  dd       ej                  dd            dd      	       e
g d
	      dd              Zy)WriteBufferingTestszE
    Tests for the complex logic in the L{FileDescriptor} class.
    r   
   )min_sizemax_sizer   )	min_value	max_value      )r2   )s   abcdefr      gc                d   dj                  d |D              }g }d}t        |||      }||dz  gdt        |      |z  z   z  z  }|rGt        |d   t              r!|j                  |j                  d             n|j                          |rGdj                  |      }| j                  ||       y)a]  
        A sequence of C{write()} and C{doWrite()} will eventually write all the
        data correctly and in order.

        @param operations: A list of C{bytes} (indicating a C{write()}) or
            C{int} (indicating C{doWrite()} with the integer being how much
            C{writeSomeData()} writeSomeData will successfully write).
        r   c              3  B   K   | ]  }t        |t              s|  y wr1   )r9   rA   ).0ops     r   	<genexpr>z:WriteBufferingTests.test_writeBuffering.<locals>.<genexpr>}   s     M2z"e7LBMs         r   r   N)	joinr/   r<   r9   rA   writer8   doWriteassertEqual)r   r2   expectedr3   r4   fdresults          r   test_writeBufferingz'WriteBufferingTests.test_writeBufferingh   s    * 88MMM!
 
#JD 	zA~&!c(mz.I*IJJ
*Q-/*+

	  '"6*r   N)r2   zlist[Union[bytes, int]]r'   r(   )r)   r*   r+   r,   r   stlistsone_ofbinaryintegersr   r\   r-   r   r   rE   rE   c   st     288BII		1r2a26 
	 ,-+ .	+r   rE   N)r,   
__future__r   typingr   
hypothesisr   r   r   r]   twisted.internet.abstractr   r	   twisted.trial.unittestr
   test_tcpr   r   r/   rE   r-   r   r   <module>rh      sH    #  7 7 C 6 '47* 47n^ 2-+- -+r   