o
    Òó·iÕ  ã                   @  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   úiC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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   ZtoWriter   r   r   ÚwriteSomeData[   s
   z$TrackingFileDescriptor.writeSomeDataN)r*   r+   r,   r-   r.   r/   )r3   r4   r   r/   )r%   r&   r'   r(   Ú	connectedZ_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
   é
   )Zmin_sizeÚmax_sizer   )Z	min_valueZ	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   ZdoWriteÚassertEqual)r   r*   Úexpectedr,   r1   ÚfdÚresultr   r   r   Útest_writeBufferingh   s   ü
z'WriteBufferingTests.test_writeBufferingN)r*   rB   r   r   )r%   r&   r'   r(   r   ÚstÚlistsZone_ofÚbinaryZintegersr   rO   r   r   r   r   r<   c   s    þúÿr<   N)r(   Ú
__future__r   Útypingr   Z
hypothesisr   r   r   rP   Ztwisted.internet.abstractr   r   Ztwisted.trial.unittestr	   Ztest_tcpr   r   r)   r<   r   r   r   r   Ú<module>   s   7