U _W$@sdZddlmZddlZddlmZmZddl m Z m Z iZ iZ Gddde ZGddde ZGd d d e Zd d Zd dZddZddZedkrenedS)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@s eZdZdZddZddZdS) 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. cCs>t|drt|dr||_n t|d|_tj|jdd|_dS)z Constructor. :param index_file: a file-like object or name of index file where index records will be written. readlinetellw )lineterminatorN)hasattrfhopen_csvwriter)selfZ index_filerh/private/var/folders/y3/n__7lzs1191bf6ypqtmfbcr1rfn98y/T/pip-unpacked-wheel-_tyv3h66/netaddr/eui/ieee.py__init__6s zFileIndexer.__init__cCs|j|dS)z Receives and writes index data to a CSV data file. :param data: record containing offset record information. N)rwriterow)rdatarrrupdateDszFileIndexer.updateN)__name__ __module__ __qualname____doc__rrrrrrr1srcs(eZdZdZfddZddZZS)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 cs:tt|t|dr*t|dr*||_n t|d|_dS)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. rrrbN)superrrr r rrZ ieee_file __class__rrrbszOUIIndexParser.__init__c Csd}d}d}td}td}td}|j}|s4q|rD||krDd}|rJq$||kr|dk rn||||t|}|jt|}|d} t| ||d} | |g}q$|t|7}q$||||dS) z Starts the parsing process which detects records and notifies registered subscribers as it finds each OUI record. TNr(hex)-F) rr rappendnotifylenrsplitintreplace) r skip_headerrecordsizemarkerhyphen empty_stringlineoffsetZouiindexrrrparseqs2       zOUIIndexParser.parserrrrrr5 __classcell__rrr rrMs rcs(eZdZdZfddZddZZS)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 cs:tt|t|dr*t|dr*||_n t|d|_dS)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. rrrN)rr8rr r rrr rrrszIABIndexParser.__init__cCs*d}d}d}td}td}td}td}|j}|s>q|rN||krNd}|rTq,||kr|dk rx|||||jt|} |d} | } | | g}t|}q,||kr|t|7}|d||} |d} | |d} t | | d d ?|d<q,|t|7}q,||||dS) z Starts the parsing process which detects records and notifies registered subscribers as it finds each IAB record. TNrr"z (base 16)r#r$Fr% ) rr rr&r'rr(r)r+r*)rr,r-r.Z hex_markerZ base16_markerr0r1r2r3Z iab_prefixr4prefixsuffixrrrr5s@          zIABIndexParser.parser6rrr rr8s r8cCs"||}|t||dS)z4Generate an index files from the IEEE registry file.N)attachrr5)Z registry_fhZ index_pathparserZ oui_parserrrrcreate_index_from_registrysr>cCsTttttdtttdtttttdtttdtdS)z1Create indices for OUI and IAB file based lookupszoui.txtoui.idxziab.txtiab.idxN)r>_pathjoindirname__file__rr8rrrrcreate_indicessrEcCs`zPtdd|DD]6}dd|D\}}}||g||||fqW5|XdS)z/Load index from file into index data structure.cSsg|]}|dqS)zUTF-8)decode).0xrrr szload_index..cSsg|] }t|qSr)r*)rG_rrrrIsN)closerreader setdefaultr&)r4fprowkeyr3r.rrr load_indexs  rQcCs(ttttdttttddS)z+Load OUI and IAB lookup indices into memoryr?r@N)rQ OUI_INDEXr open_binary __package__ IAB_INDEXrrrr load_indicessrV__main__)ros.pathpathrAcsvrZnetaddr.compatrrZ netaddr.corerrrRrUrrr8r>rErQrVrrrrrs  SZ