U
    c6{i‘  ã                   @   sp   d Z ddl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	ƒZ
ee	ƒG d
d„ dejƒƒZdS )z1Support for working directly with ethernet framesé    N)Ú	InterfaceÚimplementer)Úprotocol)Úrawc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚIEthernetProtocolz6An interface for protocols that handle Ethernet framesc                 C   s   dS )z"Add an IRawPacketProtocol protocolN© )ÚnumÚprotor   r   ú9/tmp/pip-unpacked-wheel-hfbvu0bz/twisted/pair/ethernet.pyÚaddProto   s    zIEthernetProtocol.addProtoc                 C   s   dS )z#An Ethernet frame has been receivedNr   )ÚdataÚpartialr   r   r
   ÚdatagramReceived   s    z"IEthernetProtocol.datagramReceivedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r
   r      s   r   c                   @   s   e Zd Zdd„ ZdS )ÚEthernetHeaderc                 C   s$   t  d|d d… ¡\| _| _| _d S )Nz!6s6sHé   )ÚstructÚunpackÚdestÚsourcer	   )Úselfr   r   r   r
   Ú__init__   s     
ÿzEthernetHeader.__init__N)r   r   r   r   r   r   r   r
   r      s   r   c                   @   s&   e Zd Zdd„ Zdd„ Zd	dd„ZdS )
ÚEthernetProtocolc                 C   s
   i | _ d S )N)ÚetherProtos)r   r   r   r
   r   %   s    zEthernetProtocol.__init__c                 C   sR   t  |¡}|dk rtdƒ‚|dkr*tdƒ‚|| jkr>g | j|< | j|  |¡ d S )Nr   z'Added protocol must be positive or zeroi   z"Added protocol must fit in 16 bits)r   ZIRawPacketProtocolÚ	TypeErrorr   Úappend)r   r   r	   r   r   r
   r   (   s    


zEthernetProtocol.addProtor   c                 C   sL   t |d d… ƒ}| j |jd¡D ]&}|j|dd … ||j|j|jd� q d S )Nr   r   )r   r   r   r   r   )r   r   Úgetr	   r   r   r   )r   r   r   Úheaderr	   r   r   r
   r   2   s    
ûz!EthernetProtocol.datagramReceivedN)r   )r   r   r   r   r   r   r   r   r   r
   r   #   s   
r   )r   r   Zzope.interfacer   r   Ztwisted.internetr   Ztwisted.pairr   r   r   ZAbstractDatagramProtocolr   r   r   r   r
   Ú<module>   s   
