o
    >h                     @  s   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
 d
eZG dd deZG dd deZdS )zY
Tests for L{twisted.internet.abstract}, a collection of APIs for implementing
reactors.
    )annotations)Union)examplegiven
strategies)FileDescriptorisIPv6Address)SynchronousTestCase   )_FakeFDSetReactorc                   @  sL   e Zd ZdZdddZdddZddd	Zdd
dZdddZdddZ	dS )IPv6AddressTestszw
    Tests for L{isIPv6Address}, a function for determining if a particular
    string is an IPv6 address literal.
    returnNonec                 C     |  td dS )zB
        The empty string is not an IPv6 address literal.
         NassertFalser   self r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/internet/test/test_abstract.py
test_empty      zIPv6AddressTests.test_emptyc                 C  r   )zA
        A single C{":"} is not an IPv6 address literal.
        :Nr   r   r   r   r   
test_colon   r   zIPv6AddressTests.test_colonc                 C  r   )z@
        C{"::1"} is the IPv6 loopback address literal.
        z::1N
assertTruer   r   r   r   r   test_loopback%   r   zIPv6AddressTests.test_loopbackc                 C  .   |  td |  td |  td dS )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   r   r   r   test_scopeID+      zIPv6AddressTests.test_scopeIDc                 C  r   )zv
        An otherwise invalid IPv6 address literal is still invalid with a
        trailing scope identifier.
        z%eth0z:%eth0
hello%eth0Nr   r   r   r   r   test_invalidWithScopeID4   r!   z(IPv6AddressTests.test_invalidWithScopeIDc                 C  sJ   |  td |  td | td | td | td dS )zQ
        L{isIPv6Address} evaluates ASCII-encoded bytes as well as text.
        s	   fe80::2%1r   u   䌡r"   s
   hello%eth0N)r   r   r   r   r   r   r   test_unicodeAndBytes=   s
   z%IPv6AddressTests.test_unicodeAndBytesN)r   r   )
__name__
__module____qualname____doc__r   r   r   r    r#   r$   r   r   r   r   r      s    




		r   c                   @  s,   e Zd ZdZdZdZdd
dZdddZdS )TrackingFileDescriptorz>
    Write a limited amount, and track what gets written.
    TF
operationslist[Union[int, bytes]]writtenlist[bytes]
send_limitintc                 C  s$   || _ || _|| _t| t  d S N)r*   r,   
SEND_LIMITr   __init__r   )r   r*   r,   r.   r   r   r   r2   S   s   zTrackingFileDescriptor.__init__databytesr   c                 C  s@   | j d}t|tsJ t|t|}| j|d |  |S )Nr   )r*   pop
isinstancer/   minlenr,   append)r   r3   toWriter   r   r   writeSomeData[   s
   z$TrackingFileDescriptor.writeSomeDataN)r*   r+   r,   r-   r.   r/   )r3   r4   r   r/   )r%   r&   r'   r(   	connected_writeDisconnectedr2   r;   r   r   r   r   r)   J   s    
r)   c                	   @  sZ   e Zd ZdZeejeejdddej	ddddddd	e
g d
d	dddZdS )WriteBufferingTestszE
    Tests for the complex logic in the L{FileDescriptor} class.
    r
   
   )min_sizemax_sizer   )	min_value	max_value      )r*   )s   abcdefr      gr*   list[Union[bytes, int]]r   r   c                 C  s   d dd |D }g }d}t|||}||d gdt||   7 }|r;t|d tr5||d n|  |s%d |}| || dS )	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).
            c                 s  s    | ]
}t |tr|V  qd S r0   )r6   r4   ).0opr   r   r   	<genexpr>}   s    z:WriteBufferingTests.test_writeBuffering.<locals>.<genexpr>      r
   r   N)	joinr)   r8   r6   r4   writer5   doWriteassertEqual)r   r*   expectedr,   r1   fdresultr   r   r   test_writeBufferingh   s   
z'WriteBufferingTests.test_writeBufferingN)r*   rG   r   r   )r%   r&   r'   r(   r   stlistsone_ofbinaryintegersr   rU   r   r   r   r   r>   c   s    r>   N)r(   
__future__r   typingr   
hypothesisr   r   r   rV   twisted.internet.abstractr   r   twisted.trial.unittestr	   test_tcpr   r   r)   r>   r   r   r   r   <module>   s   7