U
    
W[                     @   sb   d dl mZ d dlmZ d dlmZmZ d dlmZ eej	G dd dZ
G dd dejZd	S )
    )unittest)
components)ethernetraw)implementerc                   @   s   e Z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                 K   s>   | j std| j d}|||fks:td|||ff d S )Nz(Got a packet when not expecting anymore.r   zExpected %r, got %r)r	   AssertionErrorpop)r
   datakwZexpectr   r   r   datagramReceived   s     zMyProtocol.datagramReceivedN)__name__
__module____qualname__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rNtd	|j d S 
N   foobarr      123456   987654   partialdestsourceZprotocol   123456987654 foobarr   5Should not expect any more packets, but still want %rr   EthernetProtocolr   addProtor   r	   r   r
   proto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rltd|j d S )Nr   r   r   r   r   r      quux      012345   abcdefr    r!      012345abcdef quuxr"   r#   r&   r   r   r   testMultiplePackets-   s2    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rrtd	|j |jrtd	|j d S r   r#   r
   r'   r(   Zp2r   r   r   testMultipleSameProtosK   s8    z$EthernetTests.testMultipleSameProtosc                 C   s<   t  }tg }|d| |jddd |jddd d S )Ni  r    r   r!   r.   r+   )r   r$   r   r%   r   r&   r   r   r   testWrongProtoNotSeenn   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rtd|j |jrtd|j d S )Nr   r   r   r   r   r   r*   r+   r,   r-   i  r    r!   s   012345abcdefquuxs   123456987654foobarr.   r"   r#   r0   r   r   r   testDemuxingx   sb    zEthernetTests.testDemuxingc                 C   s<   t  }z|dd W n tjk
r.   Y n
X tddS )z2Adding a wrong level protocol raises an exception.*   Z	silliness2addProto must raise an exception for bad protocolsN)r   r$   r%   r   ZCannotAdaptr   r
   er   r   r   testAddingBadProtos_WrongLevel   s    z,EthernetTests.testAddingBadProtos_WrongLevelc              
   C   sZ   t  }z|dtg  W n0 tk
rL } z|jdkr:n W 5 d}~X Y n
X tddS )z=Adding a protocol with a negative number raises an exception.)z'Added protocol must be positive or zeroNr5   r   r$   r%   r   	TypeErrorargsr   r6   r   r   r   testAddingBadProtos_TooSmall   s    
z*EthernetTests.testAddingBadProtos_TooSmallc              
   C   sZ   t  }z|dtg  W n0 tk
rL } z|jdkr:n W 5 d}~X Y n
X tddS )<Adding a protocol with a number >=2**16 raises an exception.i   z"Added protocol must fit in 16 bitsNr5   r:   r6   r   r   r   testAddingBadProtos_TooBig   s    
z(EthernetTests.testAddingBadProtos_TooBigc              
   C   sZ   t  }z|dtg  W n0 tk
rL } z|jdkr:n W 5 d}~X Y n
X tddS )r>   i  r?   Nr5   r:   r6   r   r   r   testAddingBadProtos_TooBig2   s    
z)EthernetTests.testAddingBadProtos_TooBig2N)r   r   r   r)   r/   r1   r2   r3   r8   r=   r@   rA   r   r   r   r   r      s   #
6r   N)Ztwisted.trialr   Ztwisted.pythonr   Ztwisted.pairr   r   Zzope.interfacer   ZIRawPacketProtocolr   ZTestCaser   r   r   r   r   <module>   s   