
    Vh                         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             Z
 G d dej                        Zy	)
    )implementer)ethernetraw)
components)unittestc                       e Zd Zd Zd Zd Zy)
MyProtocolc                 $    t        |      | _        y )N)list	expecting)selfr   s     O/home/dcms/DCMS/lib/python3.12/site-packages/twisted/pair/test/test_ethernet.py__init__zMyProtocol.__init__   s    i    c                      y)z!
        Not implemented
        N )r   numprotos      r   addProtozMyProtocol.addProto   s    r   c                     | j                   sJ d       | j                   j                  d      }t               }||||d}|||fk(  sJ dj                  |||f             y )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paramss	            r   datagramReceivedzMyProtocol.datagramReceived   st    ~~III~##A& 	
 $' 	
)B)I)IT6N*
 	
'r   N)__name__
__module____qualname__r   r   r#   r   r   r   r	   r	   
   s    )

r   r	   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)EthernetTestsc                     t        j                         }t        ddddddfg      }|j                  d|       |j	                  dd       |j
                  rJ d	|j
                  z         y )
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   p1s      r   testPacketParsingzEthernetTests.testPacketParsing$   s    ))+ #$ )"+$*	

 	vr"<aH<< 	
CbllR	
<r   c           	         t        j                         }t        ddddddfddd	d
ddfg      }|j                  d|       |j	                  dd       |j	                  dd       |j
                  rJ d|j
                  z         y )Nr*   r   r+   r,   r-   r      quux      012345   abcdefr.   r/      012345abcdef quuxr0   r1   r3   s      r   testMultiplePacketsz!EthernetTests.testMultiplePackets;   s    ))+ #$ )"+$*	 #$ )"+$*	
, 	vr"<aH:AF<< 	
CbllR	
<r   c                    t        j                         }t        ddddddfg      }t        ddddddfg      }|j                  d|       |j                  d|       |j	                  dd       |j
                  r J d	j                  |j
                               |j
                  r J d	j                  |j
                               y )
Nr*   r   r+   r,   r-   r   r.   r/   z7Should not expect any more packets, but still want {!r})r   r2   r	   r   r#   r   r   r   r   r4   p2s       r   testMultipleSameProtosz$EthernetTests.testMultipleSameProtos\   s    ))+ #$ )"+$*	

  #$ )"+$*	

 	vr"vr"<aH 	
GNNLL
	

 	
GNNLL
	
r   c                     t        j                         }t        g       }|j                  d|       |j	                  dd       |j	                  dd       y )Ni  r.   r   r/   r;   r8   )r   r2   r	   r   r#   r3   s      r   testWrongProtoNotSeenz#EthernetTests.testWrongProtoNotSeen   sO    ))+^vr"<aH:AFr   c           	         t        j                         }t        ddddddfddd	d
ddfg      }|j                  d|       t        ddd	d
ddfddddddfg      }|j                  d|       |j	                  dd       |j	                  dd       |j	                  dd       |j	                  dd       |j
                  rJ d|j
                  z         |j
                  rJ d|j
                  z         y )Nr*   r   r+   r,   r-   r   r7   r8   r9   r:   i  r.   r/   s   012345abcdefquuxs   123456987654foobarr;   r0   r1   r>   s       r   testDemuxingzEthernetTests.testDemuxing   sN   ))+ #$ )"+$*	 #$ )"+$*	
, 	vr" #$ )"+$*	 #$ )"+$*	
, 	vr"<aH:AF<aH:AF<< 	
CbllR	
 << 	
CbllR	
<r   c                     t        j                         }	 |j                  dd       t        d      # t        j
                  $ r Y yw xY w)z2Adding a wrong level protocol raises an exception.*   	silliness2addProto must raise an exception for bad protocolsN)r   r2   r   AssertionErrorr   CannotAdaptr   es     r   testAddingBadProtos_WrongLevelz,EthernetTests.testAddingBadProtos_WrongLevel   sL    %%'	WJJr;' !!UVV %% 		s   3 A	A	c                     t        j                         }	 |j                  dt        g              t	        d      # t
        $ r}|j                  dk(  rn Y d}~yd}~ww xY w)z=Adding a protocol with a negative number raises an exception.rH   )z'Added protocol must be positive or zeroNr   r2   r   r	   rI   	TypeErrorargsrK   s     r   testAddingBadProtos_TooSmallz*EthernetTests.testAddingBadProtos_TooSmall   s`    %%'	WJJr:b>* !!UVV  	vvEE 	   < 	A AA c                     t        j                         }	 |j                  dt        g              t	        d      # t
        $ r}|j                  dk(  rn Y d}~yd}~ww xY w)<Adding a protocol with a number >=2**16 raises an exception.i   rH   z"Added protocol must fit in 16 bitsNrP   rK   s     r   testAddingBadProtos_TooBigz(EthernetTests.testAddingBadProtos_TooBig   s`    %%'	WJJujn- !!UVV  	vv@@ 	rT   c                     t        j                         }	 |j                  dt        g              t	        d      # t
        $ r}|j                  dk(  rn Y d}~yd}~ww xY w)rV   i  rH   rW   NrP   rK   s     r   testAddingBadProtos_TooBig2z)EthernetTests.testAddingBadProtos_TooBig2   s`    %%'	WJJy*R.1 !!UVV  	vv@@ 	rT   N)r$   r%   r&   r5   r<   r@   rB   rD   rM   rS   rX   rZ   r   r   r   r(   r(   #   s7    
.
B,
\G<
|WWWWr   r(   N)zope.interfacer   twisted.pairr   r   twisted.pythonr   twisted.trialr   IRawPacketProtocolr	   TestCaser(   r   r   r   <module>ra      sM    ' & % " S##$
 
 %
0\WH%% \Wr   