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/self/root/lib/python3.6/site-packages/netaddr/ip/__pycache__/__init__.cpython-36.pyc
3

��]��@s@dZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZmZmZmZmZGdd�de�ZGdd	�d	e�ZGd
d�de�ZdUd
d�ZGdd�dee�ZGdd�dee�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dVd d!�Z&d"d#�Z'd$d%�Z(d&d'�Z)d(d)�Z*ed*�Z+ed+�ed,�ed-�ed.�ed/�ed0�ed1d2�fZ,ed3�Z-ed4�Z.ed5�Z/ed6�ed7�ed8�ed9�ed:�ed;�ed<d=�ed>d?�fe+e/fZ0ed@�Z1edA�edB�fZ2edC�Z3edD�Z4edE�edF�edG�edH�edI�edJ�edK�edL�edM�edN�edO�edP�edQ�edR�edS�edT�fZ5dS)Wz9Routines for IPv4 and IPv6 addresses, subnets and ranges.�N)
�AddrFormatError�AddrConversionError�num_bits�
DictDotLookup�NOHOST�N�	INET_PTON�P�ZEROFILL�Z)�ipv4�ipv6)�_sys_maxint�_iter_range�_is_str�	_int_type�	_str_typec@s�eZdZdZd3Zdd�Zdd�Zedd	�ed
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zed.d/��Zed0d1��Zd2S)4�BaseIPzi
    An abstract base class for common operations shared between various IP
    related subclasses.

    �_value�_modulecCsd|_d|_dS)zConstructor.N)rr)�self�r�/usr/lib/python3.6/__init__.py�__init__szBaseIP.__init__cCsPt|t�stdt|���d|ko0|jjknsFtd|jj��||_dS)Nzint argument expected, not %srz&value out of bounds for an %s address!)	�
isinstancer�	TypeError�typer�max_intr�family_namer)r�valuerrr�
_set_value s
zBaseIP._set_valuecCs|jS)N)r)rrrr�<lambda>(szBaseIP.<lambda>z?a positive integer representing the value of IP address/subnet.)�doccCstS)zP
        :return: a key tuple that uniquely identifies this IP address.
        )�NotImplemented)rrrr�key+sz
BaseIP.keycCstS)zg
        :return: A key tuple used to compare and sort this `IPAddress`
            correctly.
        )r#)rrrr�sort_key1szBaseIP.sort_keycCst|j��S)zM
        :return: A hash value uniquely indentifying this IP object.
        )�hashr$)rrrr�__hash__8szBaseIP.__hash__cCs.y|j�|j�kSttfk
r(tSXdS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            equivalent to ``other``, ``False`` otherwise.
        N)r$�AttributeErrorrr#)r�otherrrr�__eq__>sz
BaseIP.__eq__cCs.y|j�|j�kSttfk
r(tSXdS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            not equivalent to ``other``, ``False`` otherwise.
        N)r$r(rr#)rr)rrr�__ne__Jsz
BaseIP.__ne__cCs.y|j�|j�kSttfk
r(tSXdS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            less than ``other``, ``False`` otherwise.
        N)r%r(rr#)rr)rrr�__lt__Vsz
BaseIP.__lt__cCs.y|j�|j�kSttfk
r(tSXdS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            less than or equal to ``other``, ``False`` otherwise.
        N)r%r(rr#)rr)rrr�__le__bsz
BaseIP.__le__cCs.y|j�|j�kSttfk
r(tSXdS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            greater than ``other``, ``False`` otherwise.
        N)r%r(rr#)rr)rrr�__gt__nsz
BaseIP.__gt__cCs.y|j�|j�kSttfk
r(tSXdS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            greater than or equal to ``other``, ``False`` otherwise.
        N)r%r(rr#)rr)rrr�__ge__zsz
BaseIP.__ge__cCs
|j�S)z<:return: ``True`` if this IP is unicast, ``False`` otherwise)�is_multicast)rrrr�
is_unicast�szBaseIP.is_unicastcCs(|jtkr|tkS|jtkr$|tkSdS)z>:return: ``True`` if this IP is multicast, ``False`` otherwiseN)r�_ipv4�IPV4_MULTICAST�_ipv6�IPV6_MULTICAST)rrrrr0�s

zBaseIP.is_multicastcCs,|jjdkr|tkS|jjdkr(|tkSdS)z�
        :return: ``True`` if this IP is loopback address (not for network
            transmission), ``False`` otherwise.
            References: RFC 3330 and 4291.
        ��N)r�version�
IPV4_LOOPBACK�
IPV6_LOOPBACK)rrrr�is_loopback�szBaseIP.is_loopbackcCs^|jjdkr(x@tD]}||krdSqWn&|jjdkrNxtD]}||kr:dSq:W|j�rZdSdS)z�
        :return: ``True`` if this IP is for internal/private use only
            (i.e. non-public), ``False`` otherwise. Reference: RFCs 1918,
            3330, 4193, 3879 and 2365.
        r6Tr7F)rr8�IPV4_PRIVATE�IPV6_PRIVATE�
is_link_local)r�cidrrrr�
is_private�s


zBaseIP.is_privatecCs,|jjdkr|tkS|jjdkr(|tkSdS)z�
        :return: ``True`` if this IP is link-local address ``False`` otherwise.
            Reference: RFCs 3927 and 4291.
        r6r7N)rr8�IPV4_LINK_LOCAL�IPV6_LINK_LOCAL)rrrrr>�szBaseIP.is_link_localcCsR|jjdkr(x@tD]}||krdSqWn&|jjdkrNxtD]}||kr:dSq:WdS)z�
        :return: ``True`` if this IP is in IANA reserved range, ``False``
            otherwise. Reference: RFCs 3330 and 3171.
        r6Tr7F)rr8�
IPV4_RESERVED�
IPV6_RESERVED)rr?rrr�is_reserved�s


zBaseIP.is_reservedcCs|jjdko|jd?dkS)zp
        :return: ``True`` if this IP is IPv4-compatible IPv6 address, ``False``
            otherwise.
        r7� i��)rr8r)rrrr�is_ipv4_mapped�szBaseIP.is_ipv4_mappedcCs|jjdko|jd?dkS)zl
        :return: ``True`` if this IP is IPv4-mapped IPv6 address, ``False``
            otherwise.
        r7rFr)rr8r)rrrr�is_ipv4_compat�szBaseIP.is_ipv4_compatcCsddlm}t||��S)z~
        A record dict containing IANA registration details for this IP address
        if available, None otherwise.
        r)�query)Znetaddr.ip.ianarIr)rrIrrr�info�szBaseIP.infocCs|jjS)z6the IP protocol version represented by this IP object.)rr8)rrrrr8�szBaseIP.versionN)rr)�__name__�
__module__�__qualname__�__doc__�	__slots__rr �propertyrr$r%r'r*r+r,r-r.r/r1r0r;r@r>rErGrHrJr8rrrrrs2


rcsLeZdZdZfZdI�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
e
Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdJd(d)�Zed*d+��Zed,d-��Zed.d/��Zed0d1��Zd2d3�ZdKd5d6�ZdLd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAdB�Z%dCdD�Z&e&Z'dEdF�Z(dGdH�Z)�Z*S)M�	IPAddressz�
    An individual IPv4 or IPv6 address without a net mask or subnet prefix.

    To support these and other network based operations, see `IPNetwork`.

    Nrcstt|�j�t|t�rH|dk	r4||jjkr4td��|j|_|j|_�n�|dk	r||dkr`t	|_n|dkrpt
|_ntd|��t|�r�d|kr�td|jj
��|jdk�r�t|t��r6yhdt|�ko�t	jknr�t|�|_t	|_n4t	jt|�k�ot
jkn�rt|�|_t
|_Wntk
�r2YnXn@x>t	t
fD]2}y|j||�|_Wn�w@Yn
X||_P�q@W|jdk�rtd	|��n�t|��r�y|jj||�|_Wn*tk
�r�td
||jjf��YnXn<dt|�k�o�|jjkn�rt|�|_ntd|��dS)a�
        Constructor.

        :param addr: an IPv4 or IPv6 address which may be represented in an
            accepted string format, as an unsigned integer or as another
            IPAddress object (copy construction).

        :param version: (optional) optimizes version detection if specified
            and distinguishes between IPv4 and IPv6 for addresses with an
            equivalent integer value.

        :param flags: (optional) decides which rules are applied to the
            interpretation of the addr value. Supported constants are
            INET_PTON and ZEROFILL. See the netaddr.core docs for further
            details.

        Nz1cannot switch IP versions using copy constructor!r6r7z%r is an invalid IP version!�/zQ%s() does not support netmasks or subnet prefixes! See documentation for details.rz+failed to detect a valid IP address from %rzbase address %r is not IPv%dzbad address format: %r)�superrQrrrrr8�
ValueErrorrr2r4r�	__class__rKr�intrZ
str_to_intr)r�addrr8�flags�module)rUrrr�sZ

$




$zIPAddress.__init__cCs|j|jjfS)z1:returns: Pickled state of an `IPAddress` object.)rrr8)rrrr�__getstate__AszIPAddress.__getstate__cCsB|\}}||_|dkrt|_n |dkr.t|_ntdt|���dS)zT
        :param state: data used to unpickle a pickled `IPAddress` object.

        r6r7z&unpickling failed for object state: %sN)rr2rr4rT�str)r�staterr8rrr�__setstate__EszIPAddress.__setstate__cCs�|j�s|jjS|jdkrdS|j}d}x*|dkrR|d@dkr@P|d7}|dL}q*W|jj|}d|kov|jjkns�td|��|S)z�
        @return: If this IP is a valid netmask, the number of non-zero
            bits are returned, otherwise it returns the width in bits for
            the IP address version.
        r�z+Unexpected mask length %d for address type!)�
is_netmaskr�widthrrT)rZi_val�numbitsZmask_lengthrrr�netmask_bitsVs 

zIPAddress.netmask_bitscCs|jd}||d@dkS)zV
        :return: ``True`` if this IP address host mask, ``False`` otherwise.
        r^r)r)r�int_valrrr�is_hostmaskus
zIPAddress.is_hostmaskcCs"|j|jjAd}||d@dkS)zY
        :return: ``True`` if this IP address network mask, ``False`` otherwise.
        r^r)rrr)rrcrrrr_|szIPAddress.is_netmaskcCs@t|j|�}d|ko$|jjknr4||_|Std��dS)z�
        Increases the numerical value of this IPAddress by num.

        An IndexError is raised if result exceeds maximum IP address value or
        is less than zero.

        :param num: size of IP address increment.
        rz)result outside valid IP address boundary!N)rVrrr�
IndexError)r�num�	new_valuerrr�__iadd__�s
	zIPAddress.__iadd__cCs@t|j|�}d|ko$|jjknr4||_|Std��dS)z�
        Decreases the numerical value of this IPAddress by num.

        An IndexError is raised if result is less than zero or exceeds maximum
        IP address value.

        :param num: size of IP address decrement.
        rz)result outside valid IP address boundary!N)rVrrrre)rrfrgrrr�__isub__�s
	zIPAddress.__isub__cCsFt|j|�}d|ko$|jjknr:|j||jj�Std��dS)a
        Add the numerical value of this IP address to num and provide the
        result as a new IPAddress object.

        :param num: size of IP address increase.

        :return: a new IPAddress object with its numerical value increased by num.
        rz)result outside valid IP address boundary!N)rVrrrrUr8re)rrfrgrrr�__add__�s	zIPAddress.__add__cCsFt|j|�}d|ko$|jjknr:|j||jj�Std��dS)a
        Subtract the numerical value of this IP address from num providing
        the result as a new IPAddress object.

        :param num: size of IP address decrease.

        :return: a new IPAddress object with its numerical value decreased by num.
        rz)result outside valid IP address boundary!N)rVrrrrUr8re)rrfrgrrr�__sub__�s	zIPAddress.__sub__cCsFt||j�}d|ko$|jjknr:|j||jj�Std��dS)a
        Subtract num (lvalue) from the numerical value of this IP address
        (rvalue) providing the result as a new IPAddress object.

        :param num: size of IP address decrease.

        :return: a new IPAddress object with its numerical value decreased by num.
        rz)result outside valid IP address boundary!N)rVrrrrUr8re)rrfrgrrr�__rsub__�s	zIPAddress.__rsub__cCs|jj|jfS)zP
        :return: a key tuple that uniquely identifies this IP address.
        )rr8r)rrrrr$�sz
IPAddress.keycCs|jj|j|jjfS)zI:return: A key tuple used to compare and sort this `IPAddress` correctly.)rr8rr`)rrrrr%�szIPAddress.sort_keycCs|jS)z<:return: the value of this IP address as an unsigned integer)r)rrrr�__int__�szIPAddress.__int__cCs|jS)z<:return: the value of this IP address as an unsigned integer)r)rrrr�__long__�szIPAddress.__long__cCs|jdkrdSd|jS)z;:return: an octal string representation of this IP address.r�0z0%o)r)rrrr�__oct__�s
zIPAddress.__oct__cCs
d|jS)z@:return: a hexadecimal string representation of this IP address.z0x%x)r)rrrr�__hex__�szIPAddress.__hex__cCs|jS)zx
        :return: return the integer value of this IP address when called by             hex(), oct() or bin().
        )r)rrrr�	__index__�szIPAddress.__index__cCs|jj|j|�S)z�
        :param word_sep: (optional) the separator to insert between words.
            Default: None - use default separator for address type.

        :return: the value of this IP address as a binary digit string.)rZint_to_bitsr)rZword_seprrr�bits�szIPAddress.bitscCs|jj|j�S)z7The value of this IP address as a packed binary string.)rZ
int_to_packedr)rrrr�packed�szIPAddress.packedcCs|jj|j�S)zx
        A list of unsigned integer words (octets for IPv4, hextets for IPv6)
        found in this IP address.
        )rZint_to_wordsr)rrrr�wordsszIPAddress.wordscCs|jj|j�S)z�
        The value of this IP adddress in standard Python binary
        representational form (0bxxx). A back port of the format provided by
        the builtin bin() function found in Python 2.6.x and higher.
        )rZ
int_to_binr)rrrr�binsz
IPAddress.bincCs|jj|j�S)z1The reverse DNS lookup record for this IP address)rZint_to_arpar)rrrr�reverse_dnsszIPAddress.reverse_dnscCs�d}|j}|jjdkr$||jd�}np|jjdkr�d|jkoFtjknrZ||jd�}n:tj|jkopdknr�||jdd�}ntd|��|S)z�
        Raises an `AddrConversionError` if IPv6 address cannot be converted
        to IPv4.

        :return: A numerically equivalent version 4 `IPAddress` object.
        Nr6r7rl���l�z2IPv6 address %s unsuitable for conversion to IPv4!)rUrr8rr2rr)r�ip�klassrrrrszIPAddress.ipv4FcCs�d}|j}|jjdkrT|rFd|jko.dknrF||jdd�}q�||jd�}n,|jjdkr�||jd�}|s�|d|jd�}|S)a�
        .. note:: The IPv4-mapped IPv6 address format is now considered             deprecated. See RFC 4291 or later for details.

        :param ipv4_compatible: If ``True`` returns an IPv4-mapped address
            (::ffff:x.x.x.x), an IPv4-compatible (::x.x.x.x) address
            otherwise. Default: False (IPv4-mapped).

        :return: A numerically equivalent version 6 `IPAddress` object.
        Nr7l�l���r6)rUrr8r)r�ipv4_compatiblerxryrrrr
/szIPAddress.ipv6cCs,|dk	rt|d�std��|jj|j|d�S)z�
        Only relevant for IPv6 addresses. Has no effect for IPv4.

        :param dialect: An ipv6_* dialect class.

        :return: an alternate string representation for this IP address.
        NZword_fmtz-custom dialects should subclass ipv6_verbose!)�dialect)�hasattrrr�
int_to_strr)rr{rrr�formatLs

zIPAddress.formatcCs|j|jt|�B|jj�S)z�
        :param other: An `IPAddress` object (or other int-like object).

        :return: bitwise OR (x | y) between the integer value of this IP
            address and ``other``.
        )rUrrVrr8)rr)rrr�__or__ZszIPAddress.__or__cCs|j|jt|�@|jj�S)z�
        :param other: An `IPAddress` object (or other int-like object).

        :return: bitwise AND (x & y) between the integer value of this IP
            address and ``other``.
        )rUrrVrr8)rr)rrr�__and__cszIPAddress.__and__cCs|j|jt|�A|jj�S)z�
        :param other: An `IPAddress` object (or other int-like object).

        :return: bitwise exclusive OR (x ^ y) between the integer value of
            this IP address and ``other``.
        )rUrrVrr8)rr)rrr�__xor__lszIPAddress.__xor__cCs|j|j|>|jj�S)z�
        :param numbits: size of bitwise shift.

        :return: an `IPAddress` object based on this one with its integer
            value left shifted by ``numbits``.
        )rUrrr8)rrarrr�
__lshift__uszIPAddress.__lshift__cCs|j|j|?|jj�S)z�
        :param numbits: size of bitwise shift.

        :return: an `IPAddress` object based on this one with its integer
            value right shifted by ``numbits``.
        )rUrrr8)rrarrr�
__rshift__~szIPAddress.__rshift__cCs
t|j�S)zi:return: ``True`` if the numerical value of this IP address is not             zero, ``False`` otherwise.)�boolr)rrrr�__nonzero__�szIPAddress.__nonzero__cCs|jj|j�S)z,:return: IP address in presentational format)rr}r)rrrr�__str__�szIPAddress.__str__cCsd|jj|fS)z8:return: Python statement to create an equivalent objectz%s('%s'))rUrK)rrrr�__repr__�szIPAddress.__repr__)Nr)N)F)N)+rKrLrMrNrOrrZr]rbrdr_rhrirj�__radd__rkrlr$r%rmrnrprqrrrsrPrtrurvrwrr
r~rr�r�r�r�r��__bool__r�r��
__classcell__rr)rUrrQ�sLQ	
	

					rQc@sLeZdZdZfZdd�Zedd��Zdd�Zdd	�Z	d
d�Z
dd
�ZeZdS)�IPListMixinzu
    A mixin class providing shared list-like functionality to classes
    representing groups of IP addresses.

    cCs*t|j|jj�}t|j|jj�}t||�S)z�
        :return: An iterator providing access to all `IPAddress` objects
            within range represented by this ranged IP object.
        )rQ�firstrr8�last�iter_iprange)r�start_ip�end_iprrr�__iter__�szIPListMixin.__iter__cCst|j|jd�S)zP
        The total number of IP addresses within this ranged IP object.
        r^)rVr�r�)rrrr�size�szIPListMixin.sizecCs|j}|tkrtdt��|S)z�
        :return: the number of IP addresses in this ranged IP object. Raises
            an `IndexError` if size > system max int (a Python 2.x
            limitation). Use the .size property for subnets of any size.
        zVrange contains more than %d (sys.maxint) IP addresses! Use the .size property instead.)r�rre)rr�rrr�__len__�s
zIPListMixin.__len__cCsBd}t|d�r�|jjdkr"td��|j|j�\}}}||dksH||kr`tt|j|jj�g�}n8t|j||jj�}t|j|||jj�}t	|||�}n�y�t
|�}|j|ko�dknr�t|j|d|jj�}n>d|ko�|jdkn�rt|j||jj�}ntd��Wn"t
k
�r<td|��YnX|S)	z�
        :return: The IP address(es) in this `IPNetwork` object referenced by
            index or slice. As slicing can produce large sequences of objects
            an iterator is returned instead of the more usual `list`.
        N�indicesr7zIPv6 slices are not supported!rr^z'index out range for address range size!zunsupported index type %r!)r|rr8rr�r��iterrQr�r�rVr�rerT)r�index�item�start�stop�stepr�r�rrr�__getitem__�s(
 zIPListMixin.__getitem__cCsdt|t�rX|jj|jjkrdSt|t�r@|j|jko>|j|jkS|j|jkoV|j|jkSt|�|kS)z�
        :param other: an `IPAddress` or ranged IP object.

        :return: ``True`` if other falls within the boundary of this one,
            ``False`` otherwise.
        F)rrrr8rQrr�r�)rr)rrr�__contains__�s

zIPListMixin.__contains__cCsdS)z�
        Ranged IP objects always represent a sequence of at least one IP
        address and are therefore always True in the boolean context.
        Tr)rrrrr��szIPListMixin.__nonzero__N)
rKrLrMrNrOr�rPr�r�r�r�r�r�rrrrr��s	%r�FcCst|t�r�t|�dkr$td|j��|\}}d|ko@|jknsTtd|j��d|koh|jkns|td|j���nrt|t��r�|r�t|�}d|kr�|j	dd�\}}n|}d}yt
||jtd�}WnJtk
�r|jd	k�rt
j|�}	t
|	|jtd�}ntd
|��YnX|j}yt|�}Wn�tk
�rR|dk�rN|j}Ynbtk
�r�t
||jtd�}
|
j��r�|j|
j}n$|
j��r�|j|
j}ntd|��YnXd|k�o�|jkn�s�td|j��ntd
t|���|t@�r|j|}||@}||fS)N�zinvalid %s tuple!rz#invalid address value for %s tuple!zinvalid prefix for %s tuple!rRr^)rXr6zinvalid IPNetwork address %s!z!addr %r is not a valid IPNetwork!zinvalid prefix for %s address!zunexpected type %s for addr arg)r�tuple�lenrrrr`r�cidr_abbrev_to_verbose�splitrQr8rr2Zexpand_partial_addressrrVrrTr_Znetmask_to_prefixrdZhostmask_to_prefixrrZprefix_to_netmask)rYrW�implicit_prefixrXr�	prefixlenZval1Zval2rxZ
expanded_addr�mask�netmaskrrr�parse_ip_network�s\








r�csBeZdZdZdCZdD�fdd�	Zdd	�Zd
d�Zdd
�Ze	dd�edd�Z
e	dd��Ze	dd��Ze	dd��Z
e	dd��Ze	dd��Ze	dd��Ze	dd��Ze	d d!��Ze	d"d#��Ze	d$d%��Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�ZdEd2d3�ZdFd5d6�ZdGd7d8�ZdHd9d:�ZdId;d<�Zd=d>�Z d?d@�Z!dAdB�Z"�Z#S)J�	IPNetworkaf
    An IPv4 or IPv6 network or subnet.

    A combination of an IP address and a network mask.

    Accepts CIDR and several related variants :

    a) Standard CIDR::

        x.x.x.x/y -> 192.0.2.0/24
        x::/y -> fe80::/10

    b) Hybrid CIDR format (netmask address instead of prefix), where 'y'        address represent a valid netmask::

        x.x.x.x/y.y.y.y -> 192.0.2.0/255.255.255.0
        x::/y:: -> fe80::/ffc0::

    c) ACL hybrid CIDR format (hostmask address instead of prefix like        Cisco's ACL bitmasks), where 'y' address represent a valid netmask::

        x.x.x.x/y.y.y.y -> 192.0.2.0/0.0.0.255
        x::/y:: -> fe80::/3f:ffff:ffff:ffff:ffff:ffff:ffff:ffff

    d) Abbreviated CIDR format (as of netaddr 0.7.x this requires the        optional constructor argument ``implicit_prefix=True``)::

        x       -> 192
        x/y     -> 10/8
        x.x/y   -> 192.168/16
        x.x.x/y -> 192.168.0/24

        which are equivalent to::

        x.0.0.0/y   -> 192.0.0.0/24
        x.0.0.0/y   -> 10.0.0.0/8
        x.x.0.0/y   -> 192.168.0.0/16
        x.x.x.0/y   -> 192.168.0.0/24

    �
_prefixlenFNrcs<tt|�j�d	\}}}t|d�r6|j}|j}|j}n�t|d�rT|j}|j}|j}n�|dkrvtt	|||d�\}}t	}n�|dkr�tt
|||d�\}}t
}n�|dk	r�td|��yt	}t||||�\}}Wn^tk
�r$yt
}t||||�\}}Wntk
�rYnX|dk�r td|��YnX||_||_||_dS)
a�
        Constructor.

        :param addr: an IPv4 or IPv6 address with optional CIDR prefix,
            netmask or hostmask. May be an IP address in presentation
            (string) format, an tuple containing and integer address and a
            network prefix, or another IPAddress/IPNetwork object (copy
            construction).

        :param implicit_prefix: (optional) if True, the constructor uses
            classful IPv4 rules to select a default prefix when one is not
            provided. If False it uses the length of the IP address version.
            (default: False)

        :param version: (optional) optimizes version detection if specified
            and distinguishes between IPv4 and IPv6 for addresses with an
            equivalent integer value.

        :param flags: (optional) decides which rules are applied to the
            interpretation of the addr value. Currently only supports the
            NOHOST option. See the netaddr.core docs for further details.

        Nr�rr6)r�rXr7z%r is an invalid IP version!zinvalid IPNetwork %s)NNN)
rSr�rr|rrr�r`r�r2r4rTr)rrWr�r8rXrr�rY)rUrrrlsH



zIPNetwork.__init__cCs|j|j|jjfS)z0:return: Pickled state of an `IPNetwork` object.)rr�rr8)rrrrrZ�szIPNetwork.__getstate__cCsx|\}}}||_|dkr t|_n |dkr0t|_ntdt|���d|koV|jjknrd||_ntdt|���dS)zT
        :param state: data used to unpickle a pickled `IPNetwork` object.

        r6r7z%unpickling failed for object state %srN)rr2rr4rTr[r`r�)rr\rr�r8rrrr]�s
zIPNetwork.__setstate__cCsPt|t�stdt|���d|ko0|jjknsFtd|jj��||_dS)Nzint argument expected, not %srz!invalid prefix for an %s address!)	rrrrrr`rrr�)rrrrr�_set_prefixlen�s
zIPNetwork._set_prefixlencCs|jS)N)r�)rrrrr!�szIPNetwork.<lambda>zCsize of the bitmask used to separate the network from the host bits)r"cCst|j|jj�S)z�
        The IP address of this `IPNetwork` object. This is may or may not be
        the same as the network IP address which varies according to the value
        of the CIDR subnet prefix.
        )rQrrr8)rrrrrx�szIPNetwork.ipcCst|j|j@|jj�S)z/The network address of this `IPNetwork` object.)rQr�_netmask_intrr8)rrrr�network�szIPNetwork.networkcCs<|jjdkr"|jj|jdkr"dSt|j|jB|jj�SdS)z0The broadcast address of this `IPNetwork` objectr6r^N)rr8r`r�rQr�
_hostmask_int)rrrr�	broadcast�szIPNetwork.broadcastcCs|j|jj|jA@S)ze
        The integer value of first IP address found within this `IPNetwork`
        object.
        )rrrr�)rrrrr��szIPNetwork.firstcCs d|jj|j>d}|j|BS)zd
        The integer value of last IP address found within this `IPNetwork`
        object.
        r^)rr`r�r)r�hostmaskrrrr��szIPNetwork.lastcCs|jj|jA}t||jj�S)z+The subnet mask of this `IPNetwork` object.)rrr�rQr8)rr�rrrr��szIPNetwork.netmaskcCs|jj|jAS)z+Same as self.netmask, but in integer format)rrr�)rrrrr�szIPNetwork._netmask_intcCs$d|jj|j>d}t||jj�S)z)The host mask of this `IPNetwork` object.r^)rr`r�rQr8)rr�rrrr�szIPNetwork.hostmaskcCsd|jj|j>dS)z,Same as self.hostmask, but in integer formatr^)rr`r�)rrrrr�szIPNetwork._hostmask_intcCst|j|j@|jf|jjd�S)z�
        The true CIDR address for this `IPNetwork` object which omits any
        host bits to the right of the CIDR subnet prefix.
        )r8)r�rr�r�rr8)rrrrr?szIPNetwork.cidrcCsLt|j�|j|}||jd|jjkr2td��|dkrBtd��||_|S)aP
        Increases the value of this `IPNetwork` object by the current size
        multiplied by ``num``.

        An `IndexError` is raised if result exceeds maximum IP address value
        or is less than zero.

        :param num: (optional) number of `IPNetwork` blocks to increment             this IPNetwork's value by.
        r^z#increment exceeds address boundary!rzincrement is less than zero!)rVr�r�rrrer)rrfrgrrrrhszIPNetwork.__iadd__cCsLt|j�|j|}|dkr$td��||jd|jjkrBtd��||_|S)aP
        Decreases the value of this `IPNetwork` object by the current size
        multiplied by ``num``.

        An `IndexError` is raised if result is less than zero or exceeds
        maximum IP address value.

        :param num: (optional) number of `IPNetwork` blocks to decrement             this IPNetwork's value by.
        rzdecrement is less than zero!r^z#decrement exceeds address boundary!)rVr�r�rerrr)rrfrgrrrri2szIPNetwork.__isub__cCs�t|t�r�|jj|jjkrdS|jj|j}|j|?}t|t�rd||>|jjkob|d|>|j	jkS|j|?}t|t
�r�||kSt|t�r�||ko�|j|jkSt
|�|kS)z�
        :param other: an `IPAddress` or ranged IP object.

        :return: ``True`` if other falls within the boundary of this one,
            ``False`` otherwise.
        Fr^)rrrr8r`r�r�IPRange�_start�_endrQr�)rr)�
shiftwidthZself_netZ	other_netrrrr�Gs





zIPNetwork.__contains__cCs|jj|j|jfS)zR
        :return: A key tuple used to uniquely identify this `IPNetwork`.
        )rr8r�r�)rrrrr$esz
IPNetwork.keycCs8|jd}|j|jj|jA@}|j|}|jj|||fS)z[
        :return: A key tuple used to compare and sort this `IPNetwork` correctly.
        r^)r�rrrr�r8)rZ
net_size_bitsr�Z	host_bitsrrrr%ks

zIPNetwork.sort_keycCs�d}|j}|jjdkr,|d|j|jf�}n�|jjdkr�d|jkoNtjknrxtj|j�}|d||jdf�}nPtj|jko�dknr�tj|jd�}|d||jdf�}nt	d	|��|S)
z�
        :return: A numerically equivalent version 4 `IPNetwork` object.             Raises an `AddrConversionError` if IPv6 address cannot be             converted to IPv4.
        Nr6z%s/%dr7r�`l���l�z2IPv6 address %s unsuitable for conversion to IPv4!)
rUrr8rxr�rr2rr}r)rrxryrWrrrrtszIPNetwork.ipv4cCs�d}|j}|jjdkrd|rNd|jko.dknrN||jd|jfdd�}q�||j|jfdd�}nF|jjdkr�|r�||j|jdfdd�}n|d|j|jdfdd�}|S)a�
        .. note:: the IPv4-mapped IPv6 address format is now considered         deprecated. See RFC 4291 or later for details.

        :param ipv4_compatible: If ``True`` returns an IPv4-mapped address
            (::ffff:x.x.x.x), an IPv4-compatible (::x.x.x.x) address
            otherwise. Default: False (IPv4-mapped).

        :return: A numerically equivalent version 6 `IPNetwork` object.
        Nr7l�l���)r8r6r�)rUrr8rr�)rrzrxryrrrr
�s

zIPNetwork.ipv6r^cCs(|jd|j|jf|jj�}||8}|S)z�
        :param step: the number of IP subnets between this `IPNetwork` object
            and the expected subnet. Default: 1 (the previous IP subnet).

        :return: The adjacent subnet preceding this `IPNetwork` object.
        z%s/%d)rUr�r�rr8)rr��ip_copyrrr�previous�s
zIPNetwork.previouscCs(|jd|j|jf|jj�}||7}|S)z�
        :param step: the number of IP subnets between this `IPNetwork` object
            and the expected subnet. Default: 1 (the next IP subnet).

        :return: The adjacent subnet succeeding this `IPNetwork` object.
        z%s/%d)rUr�r�rr8)rr�r�rrr�next�s
zIPNetwork.nextcCspd|ko|jjkns0td||jjf��g}|j}||_x*|j|jkrj|j|j�|jd7_qBW|S)ab
        Provides a list of supernets for this `IPNetwork` object between the
        size of the current prefix and (if specified) an endpoint prefix.

        :param prefixlen: (optional) a CIDR prefix for the maximum supernet.
            Default: 0 - returns all possible supernets.

        :return: a tuple of supernet `IPNetwork` objects.
        rz"CIDR prefix /%d invalid for IPv%d!r^)rr`rTr8r?r��append)rr�Z	supernets�supernetrrrr��s
zIPNetwork.supernetc	cs�d|jko|jjkns2td||jjf��|j|ks@t�|jj}d||jd||}|dkrn|}d|ko�|kns�td��|jj|j�}d}xL||kr�|jd||f|jj�}|j	|j
|7_	||_|d7}|Vq�WdS)a�
        A generator that divides up this IPNetwork's subnet into smaller
        subnets based on a specified CIDR prefix.

        :param prefixlen: a CIDR prefix indicating size of subnets to be
            returned.

        :param count: (optional) number of consecutive IP subnets to be
            returned.

        :return: an iterator containing IPNetwork subnet objects.
        rz"CIDR prefix /%d invalid for IPv%d!r�Nr^z,count outside of current IP subnet boundary!z%s/%d)r�rr`rTr8�
StopIterationr}r�rUrr�)	rr��countZfmtr`Zmax_subnetsZbase_subnet�i�subnetrrrr��s(



zIPNetwork.subnetcCs�tg�}|jjdkrn|jdkrJtt|jd|jj�t|jd|jj��}q�tt|j|jj�t|j|jj��}n0|jdkr�tt|jd|jj�t|j|jj��}|S)a

        A generator that provides all the IP addresses that can be assigned
        to hosts within the range of this IP object's subnet.

        - for IPv4, the network and broadcast addresses are always excluded.           for subnets that contains less than 4 IP addresses /31 and /32           report in a manner per RFC 3021

        - for IPv6, only the unspecified address '::' or Subnet-Router anycast           address (first address in the network) is excluded.

        :return: an IPAddress iterator
        r6r^r�)r�rr8r�r�rQr�r�)rZit_hostsrrr�
iter_hostss

zIPNetwork.iter_hostscCs|jj|j�}d||jfS)z&:return: this IPNetwork in CIDR formatz%s/%s)rr}rr�)rrWrrrr�(szIPNetwork.__str__cCsd|jj|fS)z8:return: Python statement to create an equivalent objectz%s('%s'))rUrK)rrrrr�-szIPNetwork.__repr__)r�)FNr)F)r^)r^)r)NN)$rKrLrMrNrOrrZr]r�rPr�rxr�r�r�r�r�r�r�r�r?rhrir�r$r%rr
r�r�r�r�r�r�r�r�rr)rUrr�As@(D
		
	
 



)%r�c@sveZdZdZdZddd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
e	dd��Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)r�z�
    An arbitrary IPv4 or IPv6 address range.

    Formed from a lower and upper bound IP address. The upper bound IP cannot
    be numerically smaller than the lower bound and the IP version of both
    must match.

    r�r�rcCsLt||d�|_|jj|_t||jj|d�|_t|j�t|j�krHtd��dS)a�
        Constructor.

        :param start: an IPv4 or IPv6 address that forms the lower
            boundary of this IP range.

        :param end: an IPv4 or IPv6 address that forms the upper
            boundary of this IP range.

        :param flags: (optional) decides which rules are applied to the
            interpretation of the start and end values. Supported constants
            are INET_PTON and ZEROFILL. See the netaddr.core docs for further
            details.

        )rXz(lower bound IP greater than upper bound!N)rQr�rr8r�rVr)rr��endrXrrrr=s

zIPRange.__init__cCs|jj|jj|jjfS)z.:return: Pickled state of an `IPRange` object.)r�rr�rr8)rrrrrZSszIPRange.__getstate__cCs0|\}}}t||�|_|jj|_t||�|_dS)zQ
        :param state: data used to unpickle a pickled `IPRange` object.
        N)rQr�rr�)rr\r�r�r8rrrr]Ws

zIPRange.__setstate__cCs�t|t�r�|jj|jjkrdSt|t�rD|jj|jkoB|jj|jkSt|t�rn|jj|jjkol|jj|jjkSt|t	�r�|jj
|j}|j|?|>}|d|>}|jj|ko�|jj|kSt|�|kS)NFr^)rrrr8rQr�rr�r�r�r`r�)rr)r�Zother_startZother_next_startrrrr�as 



zIPRange.__contains__cCs
t|j�S)z?The integer value of first IP address in this `IPRange` object.)rVr�)rrrrr�wsz
IPRange.firstcCs
t|j�S)z>The integer value of last IP address in this `IPRange` object.)rVr�)rrrrr�|szIPRange.lastcCs|jj|j|jfS)zP
        :return: A key tuple used to uniquely identify this `IPRange`.
        )rr8r�r�)rrrrr$�szIPRange.keycCs$|jjt|j�}|jj|jj|fS)zY
        :return: A key tuple used to compare and sort this `IPRange` correctly.
        )rr`rr�r8r�r)rZskeyrrrr%�szIPRange.sort_keycCst|j|j�S)zx
        The list of CIDR addresses found within the lower and upper bound
        addresses of this `IPRange`.
        )�iprange_to_cidrsr�r�)rrrr�cidrs�sz
IPRange.cidrscCsd|j|jfS)z<:return: this `IPRange` in a common representational format.z%s-%s)r�r�)rrrrr��szIPRange.__str__cCsd|jj|j|jfS)z8:return: Python statement to create an equivalent objectz%s('%s', '%s'))rUrKr�r�)rrrrr��szIPRange.__repr__N)r�r�)r)rKrLrMrNrOrrZr]r�rPr�r�r$r%r�r�r�rrrrr�2s

r�cgs*x$t|�D]}x|D]
}|VqWq
WdS)z�
    :param args: A list of IP addresses and subnets passed in as arguments.

    :return: A generator that flattens out IP subnets, yielding unique
        individual IP addresses (no duplicates).
    N)�
cidr_merge)�argsr?rxrrr�iter_unique_ips�s
r�cCsRdd�}t|�r$d|ks |dkr$|Syt|�}d|||�fStk
�r4d|kr�|jdd�\}}y,dt|�ko~d	kns�td
|��Wq�tk
r�|SXn|}d}|jd�}t|�d
kr�|Sx"td
t|��D]}|jd�q�W|dk�r"y||d�}Wntk
�r |SXddj|�|fStt	fk
�rL|SXdS)a�
    A function that converts abbreviated IPv4 CIDRs to their more verbose
    equivalent.

    :param abbrev_cidr: an abbreviated CIDR.

    Uses the old-style classful IP address rules to decide on a default
    subnet prefix if one is not explicitly provided.

    Only supports IPv4 addresses.

    Examples ::

        10                  - 10.0.0.0/8
        10/16               - 10.0.0.0/16
        128                 - 128.0.0.0/16
        128/8               - 128.0.0.0/8
        192.168             - 192.168.0.0/16

    :return: A verbose CIDR from an abbreviated CIDR or old-style classful         network address. The original value if it was not recognised as a         supported abbreviation.
    cSs�t|�}d|kodkns,td|��d|ko>dknrHdSd|koZdknrddSd	|kovd
knr�dSd|ko�d
knr�dSdS)Nr�zInvalid octet: %r!�������������r6rF)rVre)Zoctetrrr�classful_prefix�sz/cidr_abbrev_to_verbose.<locals>.classful_prefix�:�z%s.0.0.0/%srRr^rrFz.prefixlen in address %r out of range for IPv4!N�.r6roz%s/%s)
rrVrTr�r��ranger��joinrre)Zabbrev_cidrr�r�Z	part_addr�prefix�tokensrrrr��s>

r�c
CsXt|d�std��g}x,|D]$}t|�}|j|j|j|j|f�qW|j�t|�d}x�|dkr�||d||ddkr�||dd||ddkr�||d||dt	||dd||d�f||d<||=|d8}qZWg}xb|D]Z}t|�dk�r|j|d�q�|d}t
|d|d�}t
|d|d�}	|jt||	��q�W|S)	a
    A function that accepts an iterable sequence of IP addresses and subnets
    merging them into the smallest possible list of CIDRs. It merges adjacent
    subnets where possible, those contained within others and also removes
    any duplicates.

    :param ip_addrs: an iterable sequence of IP addresses and subnets.

    :return: a summarized list of `IPNetwork` objects.
    r�z#A sequence or iterator is expected!r^rr�r6�)r8)
r|rTr�r�r8r�r��sortr��minrQ�extendr�)
�ip_addrsZrangesrxr?r�ZmergedZrange_tupler8Zrange_startZ
range_stoprrrr��s,


<<
r�cCst||�\}}}||S)a
    Removes an exclude IP address or subnet from target IP subnet.

    :param target: the target IP address or subnet to be divided up.

    :param exclude: the IP address or subnet to be removed from target.

    :return: list of `IPNetwork` objects remaining after exclusion.
    )�cidr_partition)�target�exclude�left�_�rightrrr�cidr_exclude+s
r�cCs$t|�}t|�}|j|jkr*gg|jgfS|j|jkrD|jgggfS|j|jkr\g|ggfSg}g}|jd}|jj}|j}|j}|}|d||}	xv|j|k�r|j|	kr�|jt||f|d��|	}
n|jt|	|f|d��|}
|d7}||kr�P|
}|
d||}	q�W||g|ddd�fS)ac
    Partitions a target IP subnet on an exclude IP address.

    :param target: the target IP address or subnet to be divided up.

    :param exclude: the IP address or subnet to partition on

    :return: list of `IPNetwork` objects before, the partition and after, sorted.

    Adding the three lists returns the equivalent of the original subnet.
    r^r�)r8N���)	r�r�r�r?r�rr`r8r�)r�r�r�r�Z
new_prefixlenZtarget_module_widthZtarget_firstr8Zi_lowerZi_upperZmatchedrrrr�9s8


r�cCs�tdd�|D��}t|�dks&td��|d}|d}|j|jkrJtd��|j}|j}|j}|jj	}x.|dkr�||kr�|d8}|d||>M}qfWt
||f|jd�S)	aO
    Function that accepts a sequence of IP addresses and subnets returning
    a single `IPNetwork` subnet that is large enough to span the lower and
    upper bound IP addresses with a possible overlap on either end.

    :param ip_addrs: sequence of IP addresses and subnets.

    :return: a single spanning `IPNetwork` subnet.
    cSsg|]}t|��qSr)r�)�.0rxrrr�
<listcomp>�sz!spanning_cidr.<locals>.<listcomp>r^z-IP sequence must contain at least 2 elements!rz.IP sequence cannot contain both IPv4 and IPv6!)r8r�)�sortedr�rTr8rr�r�r�rr`r�)r�Z
sorted_ipsZ	lowest_ipZ
highest_ipZipnumr�Zlowest_ipnumr`rrr�
spanning_cidrus 
r�r^ccs�t|�}t|�}|j|jkr$td��|j}t|�}|dkrBtd��t|�}t|�}d}|dkrbd}||}x2||7}|r�||ks�Pn
||ks�Pt||�VqlWdS)a�
    A generator that produces IPAddress objects between an arbitrary start
    and stop IP address with intervals of step between them. Sequences
    produce are inclusive of boundary IPs.

    :param start: start IP address.

    :param end: end IP address.

    :param step: (optional) size of step between IP addresses. Default: 1

    :return: an iterator of one or more `IPAddress` objects.
    z(start and stop IP versions do not match!rzstep argument cannot be zeroFTN)rQr8rrVrT)r�r�r�r8r�Z
negative_stepr�rrrr��s,r�cCs�g}t|�}t|�}|j|jg}t||g�}|jj}|j|dkrrt|dd|f|jd�}t||�d}|j�}|j|dkr�t|dd|f|jd�}|t||�d7}n
|j	|�|S)a`
    A function that accepts an arbitrary start and end IP address or subnet
    and returns a list of CIDR subnets that fit exactly between the boundaries
    of the two with no overlap.

    :param start: the start IP address or subnet.

    :param end: the end IP address or subnet.

    :return: a list of one or more IP addresses and subnets.
    rr^)r8r�)
r�r�r�r�rr`r8r��popr�)r�r�Z	cidr_listZiprangeZ	cidr_spanr`r�rrrr��s
r�cCsdd}t|d�std|��t|�}x<tdd�|D��D]&}||krH|}q6|dk	r6|j|kr6Pq6W|S)ab
    Matches an IP address or subnet against a given sequence of IP addresses
    and subnets.

    :param ip: a single IP address or subnet.

    :param cidrs: a sequence of IP addresses and/or subnets.

    :return: the smallest (most specific) matching IPAddress or IPNetwork
        object from the provided sequence, None if there was no match.
    Nr�z,IP address/subnet sequence expected, not %r!cSsg|]}t|��qSr)r�)r�r?rrrr��sz*smallest_matching_cidr.<locals>.<listcomp>)r|rrQr�r�)rxr��matchr?rrr�smallest_matching_cidr�s
r�cCsPd}t|d�std|��t|�}x(tdd�|D��D]}||kr6|}Pq6W|S)ab
    Matches an IP address or subnet against a given sequence of IP addresses
    and subnets.

    :param ip: a single IP address or subnet.

    :param cidrs: a sequence of IP addresses and/or subnets.

    :return: the largest (least specific) matching IPAddress or IPNetwork
        object from the provided sequence, None if there was no match.
    Nr�z,IP address/subnet sequence expected, not %r!cSsg|]}t|��qSr)r�)r�r?rrrr�sz)largest_matching_cidr.<locals>.<listcomp>)r|rrQr�)rxr�r�r?rrr�largest_matching_cidrs
r�cCsjg}t|d�std|��t|�}xBtdd�|D��D],}||krN|j|�q6|r6|j|dkr6Pq6W|S)aM
    Matches an IP address or subnet against a given sequence of IP addresses
    and subnets.

    :param ip: a single IP address.

    :param cidrs: a sequence of IP addresses and/or subnets.

    :return: all matching IPAddress and/or IPNetwork objects from the provided
        sequence, an empty list if there was no match.
    r�z,IP address/subnet sequence expected, not %r!cSsg|]}t|��qSr)r�)r�r?rrrr�5sz&all_matching_cidrs.<locals>.<listcomp>r^r�)r|rrQr�r�r�)rxr�Zmatchesr?rrr�all_matching_cidrs"s
r�z127.0.0.0/8z
10.0.0.0/8z
100.64.0.0/10z
172.16.0.0/12z192.0.0.0/24z192.168.0.0/16z
198.18.0.0/15z	239.0.0.0z239.255.255.255z169.254.0.0/16z224.0.0.0/4z192.88.99.0/24z	0.0.0.0/8z192.0.2.0/24z240.0.0.0/4z198.51.100.0/24z203.0.113.0/24z233.252.0.0/24z	234.0.0.0z238.255.255.255z	225.0.0.0z231.255.255.255z::1zfc00::/7z	fec0::/10z	fe80::/10zff00::/8z	ff00::/12z::/8z0100::/8z0200::/7z0400::/6z0800::/5z1000::/4z4000::/3z6000::/3z8000::/3zA000::/3zC000::/3zE000::/4zF000::/5zF800::/6zFE00::/9)Fr)r^)6rN�sys�_sysZnetaddr.corerrrrrrrr	r
rZnetaddr.strategyrr2r
r4Znetaddr.compatrrrrr�objectrrQr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r9r<rAr3Z	IPV4_6TO4rCr:r=rBr5rDrrrr�<module>sz0U4e
DtmT,<"
/$