Viewing File: /usr/lib/python3.6/site-packages/netaddr/strategy/__pycache__/ipv6.cpython-36.opt-1.pyc

3

��]��@sdZddlZdZy>ddlZejs(ed��ejej	ddlmZ
mZm	Z	dZWn(ek
rvddl
mZ
mZm	Z	YnXddlmZddlmZmZmZmZmZmZmZmZ m!Z"d	Z#d
Z$dZ%e	Z&dZ'd
Z(d
Z)de#dZ*e#e$Z+de$dZ,e-dd�e.de#d�D��Z/e-dd�e.de#d�D��Z0e-dd�e.de#d�D��Z1e-dd�e.de#d�D��Z2Gdd�de3�Z4Gdd�de4�Z5Gdd�de4�Z6d9dd�Z7d:dd�Z8d;dd �Z9d!d"�Z:d#d$�Z;d%d&�Z<d'd(�Zd<d)d*�Zd+d,�Zd-d.�Zd/d0�Zd=d1d2�Zd3d4�Zd5d6�Zd7d8�Z!dS)>z
IPv6 address logic.
�NFz
IPv6 disabled)�	inet_pton�	inet_ntop�AF_INET6T)�AddrFormatError)	�valid_words�int_to_words�words_to_int�
valid_bits�bits_to_int�int_to_bits�	valid_bin�
int_to_bin�
bin_to_int���:ZIPv6���cCs$g|]}|tdt|dAf�qS)rr)�max_int�width)�.0�i�r�/usr/lib/python3.6/ipv6.py�
<listcomp>DsrcCs$g|]}tdt|dA|f�qS)rr)rr)rrrrrrHscCs g|]}|dt|df�qS)rr)r)rrrrrrLscCs g|]}dt|d|f�qS)rr)r)rrrrrrPsc@seZdZdZdZdZdS)�ipv6_compactz%An IPv6 dialect class - compact form.z%xTN)�__name__�
__module__�__qualname__�__doc__�word_fmt�compactrrrrrVsrc@seZdZdZdZdS)�	ipv6_fullz*An IPv6 dialect class - 'all zeroes' form.FN)rrrr r"rrrrr#^sr#c@seZdZdZdZdZdS)�ipv6_verbosez5An IPv6 dialect class - extra wide 'all zeroes' form.z%.4xFN)rrrr r!r"rrrrr$dsr$c	Cs.|dkrtd��ytt|�Wn
dSdS)a
    :param addr: An IPv6 address in presentation (string) format.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Future use - currently has no effect.

    :return: ``True`` if IPv6 address is valid, ``False`` otherwise.
    �z Empty strings are not supported!FT)r�
_inet_ptonr)�addr�flagsrrr�	valid_strns	r)cCs8ytt|�}t|�Stk
r2td|��YnXdS)a
    :param addr: An IPv6 address in string form.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Future use - currently has no effect.

    :return: The equivalent unsigned integer for a given IPv6 address.
    z&%r is not a valid IPv6 address string!N)r&r�
packed_to_int�	Exceptionr)r'r(�
packed_intrrr�
str_to_int�s
	
r-cs��dkrt�d}yJt|�}�jr,tt|�}n,ttjd|��}�fdd�|D�}tj	|�}Wn t
k
rztd|��YnX|S)z�
    :param int_val: An unsigned integer.

    :param dialect: (optional) a Python class defining formatting options.

    :return: The IPv6 presentation (string) format address equivalent to the
        unsigned integer provided.
    Nz>8Hcsg|]}�j|�qSr)r!)r�word)�dialectrrr�szint_to_str.<locals>.<listcomp>z+%r is not a valid 128-bit unsigned integer!)r�
int_to_packedr"�
_inet_ntopr�list�_struct�unpack�word_sep�joinr+�
ValueError)�int_valr/r'r,�words�tokensr)r/r�
int_to_str�s	r;cCs:t|t�}t|jdd��}|j�|dddg}dj|�S)z�
    :param int_val: An unsigned integer.

    :return: The reverse DNS lookup for an IPv6 address in network byte
        order integer form.
    rr%Zip6Zarpa�.)r;r$r2�replace�reverser6)r8r'r:rrr�int_to_arpa�s

r?cCst|dd�}tjd|��S)z�
    :param int_val: the integer to be packed.

    :return: a packed string that is equivalent to value represented by an
    unsigned integer.
    �� �>4I)rB)rr3�pack)r8r9rrrr0�sr0cCsJttjd|��}d}x0tt|��D] \}}|}|d|>}||B}q"W|S)a
    :param packed_int: a packed string containing an unsigned integer.
        It is assumed that string is packed in network byte order.

    :return: An unsigned integer equivalent to value of network address
        represented by packed binary string.
    z>4IrrA)r2r3r4�	enumerate�reversed)r,r9r8rZnumr.rrrr*�sr*cCst|tt�S)N)�_valid_words�	word_size�	num_words)r9rrrr�srcCs0|dkrt�d}|dkr$t�d}t|||�S)NrHrG)�globals�
_int_to_words)r8rHrGrrrr�s


rcCst|tt�S)N)�
_words_to_intrGrH)r9rrrr�srcCst|tt�S)N)�_valid_bitsrr5)�bitsrrrr	�sr	cCst|tt�S)N)�_bits_to_intrr5)rMrrrr
�sr
cCs |dkrt�d}t|tt|�S)Nr5)rI�_int_to_bitsrGrH)r8r5rrrr�s
rcCs
t|t�S)N)�
_valid_binr)�bin_valrrrr�srcCs
t|t�S)N)�_int_to_binr)r8rrrr
�sr
cCs
t|t�S)N)�_bin_to_intr)rQrrrrsr)r)r)N)NN)N)=r �structr3ZOPT_IMPORTSZsocketZ_socketZhas_ipv6r+rrr&rr1Znetaddr.fbsocketZnetaddr.corerZnetaddr.strategyrrFrrJrrKr	rLr
rNrrOrrPr
rRrrSrrGr5ZfamilyZfamily_name�versionZ	word_baserrHZmax_word�dict�rangeZprefix_to_netmaskZnetmask_to_prefixZprefix_to_hostmaskZhostmask_to_prefix�objectrr#r$r)r-r;r?r0r*rrrr�<module>sd,






Back to Directory File Manager