o
    ¯bý  ã                   @   sb   d dl mZ d dlmZmZ d dlmZ d dlmZ eej	ƒG dd„ dƒƒZ
G dd„ dejƒZd	S )
é    )Úimplementer)ÚethernetÚraw)Ú
components)Úunittestc                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú
MyProtocolc                 C   s   t |ƒ| _d S )N)ÚlistÚ	expecting)Úselfr	   © r   úA/usr/lib/python3/dist-packages/twisted/pair/test/test_ethernet.pyÚ__init__   s   zMyProtocol.__init__c                 C   s   dS )z!
        Not implemented
        Nr   )r
   ÚnumÚprotor   r   r   ÚaddProto   s    zMyProtocol.addProtoc           	      C   sR   | j sJ dƒ‚| j  d¡}tƒ }||||dœ}|||fks'J d |||f¡ƒ‚d S )Nz(Got a packet when not expecting anymore.r   ©ÚpartialÚdestÚsourceÚprotocolzExpected {!r}, got {!r})r	   ÚpopÚlocalsÚformat)	r
   Údatar   r   r   r   ÚexpectÚlocalVariablesÚparamsr   r   r   ÚdatagramReceived   s   ü
ÿzMyProtocol.datagramReceivedN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   
   s    r   c                   @   sT   e 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S )ÚEthernetTestsc                 C   sR   t  ¡ }tddddddœfgƒ}| d|¡ |jddd� |jr'J d	|j ƒ‚d S )
Nó   foobarr   ó   123456ó   987654é   r   ó   123456987654 foobar©r   ú5Should not expect any more packets, but still want %r©r   ÚEthernetProtocolr   r   r   r	   ©r
   r   Úp1r   r   r   ÚtestPacketParsing$   s    üþÿÿÿzEthernetTests.testPacketParsingc                 C   sp   t  ¡ }tddddddœfddd	d
ddœfgƒ}| d|¡ |jddd� |jddd� |jr6J d|j ƒ‚d S )Nr"   r   r#   r$   r%   r   ó   quuxé   ó   012345ó   abcdefr&   r'   ó   012345abcdef quuxr(   r)   r+   r   r   r   ÚtestMultiplePackets;   s0   üþ
üþöÿÿz!EthernetTests.testMultiplePacketsc                 C   sŽ   t  ¡ }tddddddœfgƒ}tddddddœfgƒ}| d|¡ | d|¡ |jddd� |jr:J d	 |j¡ƒ‚|jrEJ d	 |j¡ƒ‚d S )
Nr"   r   r#   r$   r%   r   r&   r'   z7Should not expect any more packets, but still want {!r})r   r*   r   r   r   r	   r   ©r
   r   r,   Úp2r   r   r   ÚtestMultipleSameProtos\   sH   üþÿÿüþÿÿÿÿþÿÿþz$EthernetTests.testMultipleSameProtosc                 C   s<   t  ¡ }tg ƒ}| d|¡ |jddd� |jddd� d S )Ni  r&   r   r'   r2   r/   )r   r*   r   r   r   r+   r   r   r   ÚtestWrongProtoNotSeenŠ   s
   z#EthernetTests.testWrongProtoNotSeenc                 C   sÔ   t  ¡ }tddddddœfddd	d
ddœfgƒ}| d|¡ tddd	d
ddœfddddddœfgƒ}| d|¡ |jddd� |jddd� |jddd� |jddd� |jr^J d|j ƒ‚|jrhJ d|j ƒ‚d S )Nr"   r   r#   r$   r%   r   r.   r/   r0   r1   i  r&   r'   s   012345abcdefquuxs   123456987654foobarr2   r(   r)   r4   r   r   r   ÚtestDemuxing’   s^   üþ
üþöÿüþ
üþöÿÿÿzEthernetTests.testDemuxingc                 C   s6   t  ¡ }z| dd¡ W tdƒ‚ tjy   Y dS w )z2Adding a wrong level protocol raises an exception.é*   Ú	sillinessú2addProto must raise an exception for bad protocolsN)r   r*   r   r   ÚCannotAdaptÚAssertionError©r
   Úer   r   r   ÚtestAddingBadProtos_WrongLevelÐ   s   ýÿz,EthernetTests.testAddingBadProtos_WrongLevelc              
   C   óX   t  ¡ }z| dtg ƒ¡ W tdƒ‚ ty+ } z|jdkrn‚ W Y d}~dS d}~ww )z=Adding a protocol with a negative number raises an exception.éÿÿÿÿ)z'Added protocol must be positive or zeroNr;   ©r   r*   r   r   Ú	TypeErrorÚargsr=   r>   r   r   r   ÚtestAddingBadProtos_TooSmallÚ   ó   ú
þ€þz*EthernetTests.testAddingBadProtos_TooSmallc              
   C   rA   )ú<Adding a protocol with a number >=2**16 raises an exception.i   ©z"Added protocol must fit in 16 bitsNr;   rC   r>   r   r   r   ÚtestAddingBadProtos_TooBigç   rG   z(EthernetTests.testAddingBadProtos_TooBigc              
   C   rA   )rH   i  rI   Nr;   rC   r>   r   r   r   ÚtestAddingBadProtos_TooBig2ô   rG   z)EthernetTests.testAddingBadProtos_TooBig2N)r   r   r    r-   r3   r6   r7   r8   r@   rF   rJ   rK   r   r   r   r   r!   #   s    !.>
r!   N)Úzope.interfacer   Útwisted.pairr   r   Útwisted.pythonr   Útwisted.trialr   ÚIRawPacketProtocolr   ÚTestCaser!   r   r   r   r   Ú<module>   s   