HEX
Server: LiteSpeed
System: Linux premium71.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: consovgw (933)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //proc/thread-self/root/lib/python3.6/site-packages/netaddr/ip/__pycache__/iana.cpython-36.pyc
3

��]5�@s
dZddljZddlZddlmZmZddl	m
Z
mZddlm
Z
mZmZmZddlmZmZiiiid�ZGdd	�d	ej�ZGd
d�de
�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�Zddd�Zdd�Zdd�Z e�dS)a
Routines for accessing data published by IANA (Internet Assigned Numbers
Authority).

More details can be found at the following URLs :-

    - IANA Home Page - http://www.iana.org/
    - IEEE Protocols Information Home Page - http://www.iana.org/protocols/
�N)�make_parser�handler)�	Publisher�
Subscriber)�	IPAddress�	IPNetwork�IPRange�cidr_abbrev_to_verbose)�_dict_items�	_callable)�IPv4�IPv6�IPv6_unicast�	multicastc@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)�SaxRecordParserNcCs.d|_d|_d|_d|_d|_d|_||_dS)NrF)�_level�
_is_active�_record�
_tag_level�_tag_payload�_tag_feeding�	_callback)�self�callback�r�/usr/lib/python3.6/iana.py�__init__3szSaxRecordParser.__init__cCs�|jd7_|jdkrL|dkr�d|_|j|_i|_d|kr�|d|jd<n^|j|jdkr�|dkr�d|kr�d|kr�|jj|dg�}|j|d�q�g|_d|_nd|_dS)	N�F�recordT�date�xref�type�data)rrrr�
setdefault�appendrr)r�nameZattrs�lrrr�startElement<s 
zSaxRecordParser.startElementcCs�|jdkr~|dkrH|j|jkrHd|_d|_t|j�r@|j|j�d|_n6|j|jdkr~|dkr~dj|j�|j|<d|_d|_|jd8_dS)NTrFrr �)	rrrrrr�joinrr)rr%rrr�
endElementQs

zSaxRecordParser.endElementcCs|jdkr|jj|�dS)NT)rrr$)rZcontentrrr�
charactersas
zSaxRecordParser.characters)N)�__name__�
__module__�__qualname__rr'r*r+rrrrr2s
	rcs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
�XMLRecordParserzP
    A configurable Parser that understands how to parse XML based records.
    cs>tt|�j�t�|_|jjt|j��||_|j	j
|�dS)z`
        Constructor.

        fh - a valid, open file handle to XML based record data.
        N)�superr/rr�	xmlparserZsetContentHandlerr�consume_record�fh�__dict__�update)rr3�kwargs)�	__class__rrrks
zXMLRecordParser.__init__cCs|S)a
        This is the callback method invoked for every record. It is usually
        over-ridden by base classes to provide specific record-based logic.

        Any record can be vetoed (not passed to registered Subscriber objects)
        by simply returning None.
        r)r�recrrr�process_recordzszXMLRecordParser.process_recordcCs |j|�}|dk	r|j|�dS)N)r9Znotify)rr8rrrrr2�s
zXMLRecordParser.consume_recordcCs|jj|j�dS)z
        Parse and normalises records, notifying registered subscribers with
        record data as it is encountered.
        N)r1�parser3)rrrrr:�szXMLRecordParser.parse)	r,r-r.�__doc__rr9r2r:�
__classcell__rr)r7rr/fs

r/cs(eZdZdZ�fdd�Zdd�Z�ZS)�
IPv4Parserz�
    A XMLRecordParser that understands how to parse and retrieve data records
    from the IANA IPv4 address space file.

    It can be found online here :-

        - http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xml
    cstt|�j|�dS)z�
        Constructor.

        fh - a valid, open file handle to an IANA IPv4 address space file.

        kwargs - additional parser options.
        N)r0r=r)rr3r6)r7rrr�szIPv4Parser.__init__cCsti}x$d	D]}t|j|d��j�||<q
Wd|dkr`|djd�\}}dt|�t|�f|d<|dj�|d<|S)
zl
        Callback method invoked for every record.

        See base class method for more details.
        �prefix�designationr�whois�statusr(�/z%d/%d)r>r?rr@rA)�str�get�strip�split�int�
capitalize)rr8r�keyZoctetr>rrrr9�s
zIPv4Parser.process_record)r,r-r.r;rr9r<rr)r7rr=�s
r=cs(eZdZdZ�fdd�Zdd�Z�ZS)�
IPv6Parserz�
    A XMLRecordParser that understands how to parse and retrieve data records
    from the IANA IPv6 address space file.

    It can be found online here :-

        - http://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xml
    cstt|�j|�dS)z�
        Constructor.

        fh - a valid, open file handle to an IANA IPv6 address space file.

        kwargs - additional parser options.
        N)r0rJr)rr3r6)r7rrr�szIPv6Parser.__init__cCsFt|jdd��j�t|jdd��j�t|jddg�d�j�d�}|S)zl
        Callback method invoked for every record.

        See base class method for more details.
        r>r(�descriptionZrfcr)r>Z
allocationZ	reference)rCrDrE)rr8rrrrr9�szIPv6Parser.process_record)r,r-r.r;rr9r<rr)r7rrJ�s
rJcs(eZdZdZ�fdd�Zdd�Z�ZS)�IPv6UnicastParsera!
    A XMLRecordParser that understands how to parse and retrieve data records
    from the IANA IPv6 unicast address assignments file.

    It can be found online here :-

        - http://www.iana.org/assignments/ipv6-unicast-address-assignments/ipv6-unicast-address-assignments.xml
    cstt|�j|�dS)z�
        Constructor.

        fh - a valid, open file handle to an IANA IPv6 address space file.

        kwargs - additional parser options.
        N)r0rLr)rr3r6)r7rrr�szIPv6UnicastParser.__init__cCsdt|jdd��j�t|jdd��j�t|jdd��j�t|jdd��j�t|jdd��j�d�}|S)zl
        Callback method invoked for every record.

        See base class method for more details.
        rAr(rKr>rr@)rArKr>rr@)rCrDrE)rr8rrrrr9�sz IPv6UnicastParser.process_record)r,r-r.r;rr9r<rr)r7rrL�s
rLcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�MulticastParserz�
    A XMLRecordParser that knows how to process the IANA IPv4 multicast address
    allocation file.

    It can be found online here :-

        - http://www.iana.org/assignments/multicast-addresses/multicast-addresses.xml
    cstt|�j|�dS)z�
        Constructor.

        fh - a valid, open file handle to an IANA IPv4 multicast address
             allocation file.

        kwargs - additional parser options.
        N)r0rMr)rr3r6)r7rrrs	zMulticastParser.__init__cCs�d|kr^|jd�\}}|j�jd�}|j�jd�}ddjdd�|D��djdd�|D��fS|j�jd�}djdd�|D��SdS)	zX
        Removes variations from address entries found in this particular file.
        �-�.z%s-%scSsg|]}tt|���qSr)rCrG)�.0�irrr�
<listcomp>sz2MulticastParser.normalise_addr.<locals>.<listcomp>cSsg|]}tt|���qSr)rCrG)rPrQrrrrR scSsg|]}tt|���qSr)rCrG)rPrQrrrrR#sN)rFrEr))r�addrZa1Za2Zo1Zo2rrr�normalise_addrszMulticastParser.normalise_addrcCs4d|kr0|jt|d��t|jdd��d�}|SdS)zl
        Callback method invoked for every record.

        See base class method for more details.
        rSrKr()�addressZdescrN)rTrCrD)rr8rrrrr9%szMulticastParser.process_record)r,r-r.r;rrTr9r<rr)r7rrMsrMc@s eZdZdZdd�Zdd�ZdS)�DictUpdaterzc
    Concrete Subscriber that inserts records received from a Publisher into a
    dictionary.
    cCs||_||_||_dS)z�
        Constructor.

        dct - lookup dict or dict like object to insert records into.

        topic - high-level category name of data to be processed.

        unique_key - key name in data dict that uniquely identifies it.
        N)�dct�topic�
unique_key)rrWrXrYrrrr:s
zDictUpdater.__init__cCs�||j}|jdkr,tt|��}||j|<n�|jdkrNtt|��}||j|<n||jdkrlt|�}||j|<n^|jdkr�d}d|kr�|jd�\}}t||�}|j�}t|�dkr�|d}nt	|�}||j|<dS)	z�
        Callback function used by Publisher to notify this Subscriber about
        an update. Stores topic based information into dictionary passed to
        constructor.
        rr
rrNrNrr)
rYrXrr	rWrFr�cidrs�lenr)rr"Zdata_id�cidr�iprange�firstZlastrZrrrr5Hs(






zDictUpdater.updateN)r,r-r.r;rr5rrrrrV4srVcCs�tjt�}tttj|d���}|jttddd��|j	�t
ttj|d���}|jttddd��|j	�tttj|d���}|jttddd��|j	�tttj|d���}|jttd	d	d
��|j	�dS)zd
    Parse and load internal IANA data lookups with the latest information from
    data files.
    zipv4-address-space.xmlrr>zipv6-address-space.xmlr
z$ipv6-unicast-address-assignments.xmlrzmulticast-addresses.xmlrrUN)
�_path�dirname�__file__r=�openr)ZattachrV�	IANA_INFOr:rJrLrM)�PATHZipv4Zipv6Zipv6uaZmcastrrr�	load_infogs
recCs�|dkrtj}x�tt�D]v}|jdt|�d�|j|d�|jdt|�d�t|}x.t|�D]"}||}|jd||d�qhWqWdS)z7
    Pretty prints IANA information to filehandle.
    NrN�
z%-45r)�_sys�stdout�sortedrc�writer[)r3�categoryZiprangesr]Zdetailsrrr�pprint_infosrlcCs4t|d�r||kSt|d�r$||kStd|��dS)Nr^�valuez$Unsupported IP range or address: %r!)�hasattr�	Exception)ZipZip_rangerrr�_within_bounds�s


rpcCs i}|jdkr�x<ttd�D],\}}t||�r|jdg�|dj|�qW|j�r�x�ttd�D],\}}t||�rb|jdg�|dj|�qbWn�|jdk�rx<ttd�D],\}}t||�r�|jdg�|dj|�q�Wx<ttd�D],\}}t||�r�|jdg�|dj|�q�W|S)z7Returns informational data specific to this IP address.�rrZ	Multicast�r
r)�versionr
rcrpr#r$Zis_multicast)Zip_addr�infor\rr]rrr�query�s*




ru)N)!r;Zos.path�pathr_�sysrgZxml.saxrrZnetaddr.corerrZ
netaddr.iprrrr	Znetaddr.compatr
rrcZContentHandlerrr/r=rJrLrMrVrerlrprurrrr�<module>s,
4+)$$23