Ë
    ãÓñ^W$  ã                   óÆ   — d Z ddlmZ ddlZddlmZmZ ddl	m
Z
mZ i Zi Z G d„ de
«      Z G d„ de«      Z G d	„ d
e«      Zd„ Zd„ Zd„ Zd„ Zedk(  r e«        y e«        y)zý
Provides access to public OUI and IAB registration data published by the IEEE.

More details can be found at the following URLs :-

    - IEEE Home Page - http://www.ieee.org/
    - Registration Authority Home Page - http://standards.ieee.org/regauth/
é    N)Ú_bytes_typeÚ_importlib_resources)Ú
SubscriberÚ	Publisherc                   ó   — e Zd ZdZd„ Zd„ Zy)ÚFileIndexerzš
    A concrete Subscriber that receives OUI record offset information that is
    written to an index data file as a set of comma separated records.
    c                 ó²   — t        |d«      rt        |d«      r|| _        nt        |d«      | _        t        j                  | j                  d¬«      | _        y)z”
        Constructor.

        :param index_file: a file-like object or name of index file where
            index records will be written.
        ÚreadlineÚtellÚwú
)ÚlineterminatorN)ÚhasattrÚfhÚopenÚ_csvÚwriter)ÚselfÚ
index_files     ú2/usr/lib/python3/dist-packages/netaddr/eui/ieee.pyÚ__init__zFileIndexer.__init__6   sB   € ô �:˜zÔ*¬w°zÀ6Ô/JØ ˆD�Gä˜: sÓ+ˆDŒGä—k‘k $§'¡'¸$Ô?ˆ�ó    c                 ó:   — | j                   j                  |«       y)z‡
        Receives and writes index data to a CSV data file.

        :param data: record containing offset record information.
        N)r   Úwriterow)r   Údatas     r   ÚupdatezFileIndexer.updateD   s   € ð 	�‰×Ñ˜TÕ"r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © r   r   r   r   1   s   „ ñò@ó#r   r   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚOUIIndexParseraÞ  
    A concrete Publisher that parses OUI (Organisationally Unique Identifier)
    records from IEEE text-based registration files

    It notifies registered Subscribers as each record is encountered, passing
    on the record's position relative to the start of the file (offset) and
    the size of the record (in bytes).

    The file processed by this parser is available online from this URL :-

        - http://standards.ieee.org/regauth/oui/oui.txt

    This is a sample of the record structure expected::

        00-CA-FE   (hex)        ACME CORPORATION
        00CAFE     (base 16)        ACME CORPORATION
                        1 MAIN STREET
                        SPRINGFIELD
                        UNITED STATES
    c                 óŒ   •— t         t        | �  «        t        |d«      rt        |d«      r|| _        yt        |d«      | _        y)zó
        Constructor.

        :param ieee_file: a file-like object or name of file containing OUI
            records. When using a file-like object always open it in binary
            mode otherwise offsets will probably misbehave.
        r
   r   ÚrbN)Úsuperr#   r   r   r   r   ©r   Ú	ieee_fileÚ	__class__s     €r   r   zOUIIndexParser.__init__b   ó:   ø€ ô 	Œn˜dÑ,Ô.ä�9˜jÔ)¬g°iÀÔ.HØˆD�Gä˜9 dÓ+ˆD�Gr   c                 ó   — d}d}d}t        d«      }t        d«      }t        d«      }	 | j                  j                  «       }|sn§|r||v rd}|rŒ)||v r‰|�"|j                  |«       | j	                  |«       t        |«      }| j                  j                  «       t        |«      z
  }|j                  «       d   }	t        |	j                  ||«      d«      }
|
|g}n|t        |«      z  }ŒÄ|j                  |«       | j	                  |«       y)	z‹
        Starts the parsing process which detects records and notifies
        registered subscribers as it finds each OUI record.
        TNr   ú(hex)ú-Ú Fé   )
r   r   r
   ÚappendÚnotifyÚlenr   ÚsplitÚintÚreplace)r   Úskip_headerÚrecordÚsizeÚmarkerÚhyphenÚempty_stringÚlineÚoffsetÚouiÚindexs              r   ÚparsezOUIIndexParser.parseq   s  € ð
 ˆØˆØˆä˜WÓ%ˆÜ˜SÓ!ˆÜ" 2“ˆàØ—7‘7×#Ñ#Ó%ˆDáØá˜v¨™~Ø#�áàà˜‰~àÐ%à—M‘M $Ô'Ø—K‘K Ô'ä˜4“y�ØŸ'™'Ÿ,™,›.¬3¨t«9Ñ4�Ø—j‘j“l 1‘o�Ü˜CŸK™K¨°Ó=¸rÓB�Ø ˜‘ð œ˜D›	Ñ!�ð7 ð< 	�‰�dÔØ�‰�FÕr   ©r   r   r   r    r   r@   Ú__classcell__©r)   s   @r   r#   r#   M   s   ø„ ñô(,ö,r   r#   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚIABIndexParseraÛ  
    A concrete Publisher that parses IAB (Individual Address Block) records
    from IEEE text-based registration files

    It notifies registered Subscribers as each record is encountered, passing
    on the record's position relative to the start of the file (offset) and
    the size of the record (in bytes).

    The file processed by this parser is available online from this URL :-

        - http://standards.ieee.org/regauth/oui/iab.txt

    This is a sample of the record structure expected::

        00-50-C2   (hex)        ACME CORPORATION
        ABC000-ABCFFF     (base 16)        ACME CORPORATION
                        1 MAIN STREET
                        SPRINGFIELD
                        UNITED STATES
    c                 óŒ   •— t         t        | �  «        t        |d«      rt        |d«      r|| _        yt        |d«      | _        y)zó
        Constructor.

        :param ieee_file: a file-like object or name of file containing IAB
            records. When using a file-like object always open it in binary
            mode otherwise offsets will probably misbehave.
        r
   r   r%   N)r&   rE   r   r   r   r   r'   s     €r   r   zIABIndexParser.__init__µ   r*   r   c                 óÌ  — d}d}d}t        d«      }t        d«      }t        d«      }t        d«      }	 | j                  j                  «       }|snò|r||v rd}|rŒ)||v ro|�"|j                  |«       | j	                  |«       | j                  j                  «       t        |«      z
  }	|j                  «       d   }
|
}||	g}t        |«      }nr||v r`|t        |«      z  }|d   j                  ||«      }|j                  «       d   }|j                  |«      d   }t        ||z   d	«      d
z	  |d<   n|t        |«      z  }�Œ|j                  |«       | j	                  |«       y)z‹
        Starts the parsing process which detects records and notifies
        registered subscribers as it finds each IAB record.
        TNr   r,   z	(base 16)r-   r.   Fr/   é   )
r   r   r
   r0   r1   r   r2   r3   r5   r4   )r   r6   r7   r8   Ú
hex_markerÚbase16_markerr:   r;   r<   r=   Ú
iab_prefixr?   ÚprefixÚsuffixs                 r   r@   zIABIndexParser.parseÄ   sf  € ð
 ˆØˆØˆä  Ó)ˆ
Ü# KÓ0ˆÜ˜SÓ!ˆÜ" 2“ˆàØ—7‘7×#Ñ#Ó%ˆDáØá˜z¨TÑ1Ø#�áàà˜TÑ!àÐ%Ø—M‘M $Ô'Ø—K‘K Ô'àŸ'™'Ÿ,™,›.¬3¨t«9Ñ4�Ø!ŸZ™Z›\¨!™_�
Ø"�Ø ˜�Ü˜4“y‘Ø $Ñ&àœ˜D›	Ñ!�Ø ™×*Ñ*¨6°<Ó@�ØŸ™› a™�ØŸ™ fÓ-¨aÑ0�Ü  ¨&¡°"Ó5¸"Ñ<��q’	ð œ˜D›	Ñ!�ñC ðH 	�‰�dÔØ�‰�FÕr   rA   rC   s   @r   rE   rE       s   ø„ ñô(,ö3r   rE   c                 óh   —  || «      }|j                  t        |«      «       |j                  «        y)z4Generate an index files from the IEEE registry file.N)Úattachr   r@   )Úregistry_fhÚ
index_pathÚparserÚ
oui_parsers       r   Úcreate_index_from_registryrT   ú   s+   € á˜Ó$€JØ×Ñ”k *Ó-Ô.Ø×ÑÕr   c                  ó   — t        t        j                  t        j                  t        «      d«      t        j                  t        j                  t        «      d«      t
        «       t        t        j                  t        j                  t        «      d«      t        j                  t        j                  t        «      d«      t        «       y)z1Create indices for OUI and IAB file based lookupszoui.txtúoui.idxziab.txtúiab.idxN)rT   Ú_pathÚjoinÚdirnameÚ__file__r#   rE   r!   r   r   Úcreate_indicesr\     sv   € äÜ�
‰
”5—=‘=¤Ó*¨IÓ6Ü�
‰
”5—=‘=¤Ó*¨IÓ6Üôô
 Ü�
‰
”5—=‘=¤Ó*¨IÓ6Ü�
‰
”5—=‘=¤Ó*¨IÓ6Üõr   c                 ó^  — 	 t        j                  |D �cg c]  }|j                  d«      ‘Œ c}«      D ]G  }|D �cg c]  }t        |«      ‘Œ c}\  }}}| j	                  |g «       | |   j                  ||f«       ŒI 	 |j                  «        yc c}w c c}w # |j                  «        w xY w)z/Load index from file into index data structure.zUTF-8N)r   ÚreaderÚdecoder4   Ú
setdefaultr0   Úclose)r?   ÚfpÚxÚrowÚ_Úkeyr=   r8   s           r   Ú
load_indexrg     s”   € ðÜ—;‘;¸2Ö>°a §¡¨Õ 1Ò>Ó?ò 	.ˆCØ36Ö"7¨a¤3 q¥6Ò"7ÑˆS�&˜$Ø×Ñ˜S "Ô%Ø�#‰J×Ñ˜v t˜nÕ-ñ	.ð
 	�‰�
ùò  ?ùÚ"7øð 	�‰�
ús&   ‚B •B­B »BÁ1B Â
B ÂB,c                  ó¤   — t        t        t        j                  t        d«      «       t        t
        t        j                  t        d«      «       y)z+Load OUI and IAB lookup indices into memoryrV   rW   N)rg   Ú	OUI_INDEXr   Úopen_binaryÚ__package__Ú	IAB_INDEXr!   r   r   Úload_indicesrm     s2   € äŒyÔ.×:Ñ:¼;È	ÓRÔSÜŒyÔ.×:Ñ:¼;È	ÓRÕSr   Ú__main__)r    Úos.pathÚpathrX   Úcsvr   Únetaddr.compatr   r   Únetaddr.corer   r   ri   rl   r   r#   rE   rT   r\   rg   rm   r   r!   r   r   ú<module>rt      s|   ðñ4õ Û ç <ß .ð €	ð €	ô#�*ô #ô8P�Yô PôfW�Yô WòtòòòTð ˆzÒáÕñ …Nr   