HEX
Server: LiteSpeed
System: Linux br-asc-web1845.main-hosting.eu 5.14.0-611.42.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 24 05:30:20 EDT 2026 x86_64
User: u790421558 (790421558)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //lib/python3.9/site-packages/netaddr/ip/__pycache__/__init__.cpython-39.pyc
a

��gj(�@s�dZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZddlmZmZddlmZmZmZmZmZmZGdd�de�ZGdd	�d	e�ZGd
d�de�Zd^d
d�ZGdd�dee�Z Gdd�dee�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd�Z&dd�Z'd_d d!�Z(d"d#�Z)d$d%�Z*d&d'�Z+d(d)�Z,e d*�Z-e d+�e d,�e d-�gZ.e/e.�e d.�e d/�e d0�e!d1d2�fZ0e d3�Z1e d4�Z2e d5�Z3e d6�e d7�e d8�e d9�e d:�e d;�e!d<d=�e!d>d?�fe-e3fZ4d@dA�dBD�Z5dCdA�dDD�Z6e dE�Z7e dF�Z8e8e dG�fZ9e dH�Z:e dI�Z;e dJ�e dK�e dL�e dM�e dN�e dO�e dP�e dQ�e dR�e dS�e dT�e dU�e dV�e dW�e dX�e dY�fZ<dZdA�d[D�Z=d\dA�d]D�Z>dS)`z9Routines for IPv4 and IPv6 addresses, subnets and ranges.�N)�AddrFormatError�AddrConversionError�num_bits�
DictDotLookup�NOHOST�N�	INET_ATON�	INET_PTON�P�ZEROFILL�Z)�ipv4�ipv6)�_sys_maxint�
_iter_next�_iter_range�_is_str�	_int_type�	_str_typec@s�eZdZdZdZdd�Zdd�Zedd�ed	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zed-d.��Zed/d0��Zd1S)2�BaseIPzi
    An abstract base class for common operations shared between various IP
    related subclasses.

    )�_value�_module�__weakref__cCsd|_d|_dS)zConstructor.N)rr��self�r�7/usr/lib/python3.9/site-packages/netaddr/ip/__init__.py�__init__szBaseIP.__init__cCsNt|t�stdt|���d|kr2|jjksDntd|jj��||_dS)N�int 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�rrrrr�<lambda>(�zBaseIP.<lambda>z?a positive integer representing the value of IP address/subnet.��doccCstS�zP
        :return: a key tuple that uniquely identifies this IP address.
        ��NotImplementedrrrr�key+sz
BaseIP.keycCstS)zg
        :return: A key tuple used to compare and sort this `IPAddress`
            correctly.
        r.rrrr�sort_key1szBaseIP.sort_keycCst|���S)zL
        :return: A hash value uniquely identifying this IP object.
        )�hashr0rrrr�__hash__8szBaseIP.__hash__c	Cs2z|��|��kWSttfy,tYS0dS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            equivalent to ``other``, ``False`` otherwise.
        N�r0�AttributeErrorr r/�r�otherrrr�__eq__>sz
BaseIP.__eq__c	Cs2z|��|��kWSttfy,tYS0dS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            not equivalent to ``other``, ``False`` otherwise.
        Nr4r6rrr�__ne__Jsz
BaseIP.__ne__c	Cs2z|��|��kWSttfy,tYS0dS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            less than ``other``, ``False`` otherwise.
        N�r1r5r r/r6rrr�__lt__Vsz
BaseIP.__lt__c	Cs2z|��|��kWSttfy,tYS0dS)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.
        Nr:r6rrr�__le__bsz
BaseIP.__le__c	Cs2z|��|��kWSttfy,tYS0dS)z�
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            greater than ``other``, ``False`` otherwise.
        Nr:r6rrr�__gt__nsz
BaseIP.__gt__c	Cs2z|��|��kWSttfy,tYS0dS)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.
        Nr:r6rrr�__ge__zsz
BaseIP.__ge__cCs
|��S)z<:return: ``True`` if this IP is unicast, ``False`` otherwise)�is_multicastrrrr�
is_unicast�szBaseIP.is_unicastcCs(|jtkr|tvS|jtkr$|tvSdS)z>:return: ``True`` if this IP is multicast, ``False`` otherwiseN)r�_ipv4�IPV4_MULTICAST�_ipv6�IPV6_MULTICASTrrrrr?�s

zBaseIP.is_multicastcCs,|jjdkr|tvS|jjdkr(|tvSdS)z�
        :return: ``True`` if this IP is loopback address (not for network
            transmission), ``False`` otherwise.
            References: RFC 3330 and 4291.

        .. note:: |ipv4_in_ipv6_handling|
        ��N)r�version�
IPV4_LOOPBACK�
IPV6_LOOPBACKrrrr�is_loopback�szBaseIP.is_loopbackcCsZ|jjdkr&tD]}||vrdSqn$|jjdkrJtD]}||vr6dSq6|��rVdSdS)u�
        :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.

        .. note:: |ipv4_in_ipv6_handling|

        .. deprecated:: 0.10.0
            The ``is_private`` method has been mixing several different address types together
            which could lead to unexpected results. There are more precise
            replacements for subset of the addresses handled by ``is_private`` today:

            * :meth:`is_link_local`
            * :meth:`is_ipv4_private_use`
            * :meth:`is_ipv6_unique_local`

            There is also the :meth:`is_global` method that lets you handle all globally
            reachable (or not) addresses.

            The following address blocks currently handled by ``is_private`` have no
            convenience methods and you'll have to handle them manually or request a method
            addition:

            * ``100.64.0.0/10`` – Shared Address Space
            * ``192.0.0.0/24`` – IETF Protocol Assignments
            * ``198.18.0.0/15`` – Benchmarking
            * ``239.0.0.0``-``239.255.255.255``
        rETrFF)rrG�IPV4_PRIVATEISH�IPV6_PRIVATEISH�
is_link_local�r�cidrrrr�
is_private�s
zBaseIP.is_privatecCs,|jjdkr|tvS|jjdkr(|tvSdS)z�
        :return: ``True`` if this IP is link-local address ``False`` otherwise.
            Reference: RFCs 3927 and 4291.

        .. note:: |ipv4_in_ipv6_handling|
        rErFN)rrG�IPV4_LINK_LOCAL�IPV6_LINK_LOCALrrrrrM�szBaseIP.is_link_localcCsN|jjdkr&tD]}||vrdSqn$|jjdkrJtD]}||vr6dSq6dS)z�
        :return: ``True`` if this IP is in IANA reserved range, ``False``
            otherwise. Reference: RFCs 3330 and 3171.

        .. note:: |ipv4_in_ipv6_handling|
        rETrFF)rrG�
IPV4_RESERVED�
IPV6_RESERVEDrNrrr�is_reserved�s
zBaseIP.is_reservedcCs|jjdko|jd?dkS)zp
        :return: ``True`` if this IP is IPv4-compatible IPv6 address, ``False``
            otherwise.
        rF� i���rrGrrrrr�is_ipv4_mapped�szBaseIP.is_ipv4_mappedcCs|jjdko|jd?dkS)zl
        :return: ``True`` if this IP is IPv4-mapped IPv6 address, ``False``
            otherwise.
        rFrVrrWrrrr�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.ianarZr)rrZrrr�info�szBaseIP.infocCs|jjS)z6the IP protocol version represented by this IP object.)rrGrrrrrG�szBaseIP.versionN)�__name__�
__module__�__qualname__�__doc__�	__slots__rr&�propertyr%r0r1r3r8r9r;r<r=r>r@r?rJrPrMrUrXrYr[rGrrrrrs8
�
+
	rcsteZdZdZdZdT�fdd�	Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
e
Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�ZdUd+d,�Zed-d.��Zed/d0��Zed1d2��Zed3d4��Zd5d6�ZdVd8d9�Z dWd:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&dFdG�Z'e'Z(dHdI�Z)dJdK�Z*dLdM�Z+dNdO�Z,dPdQ�Z-dRdS�Z.�Z/S)X�	IPAddressz�
    An individual IPv4 or IPv6 address without a net mask or subnet prefix.

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

    rNrcsXtt|���|ttBtB@r.td|f��|t@rF|t@rFtd��t|t�r�|durl||j	j
krltd��|j|_|j	|_	�n�|dur�|dkr�t|_	n|dkr�t
|_	ntd|��t|�r�d|vr�td	|jj��|j	du�r�t|t��rpzld
t|�k�rtjk�r"nnt|�|_t|_	n4tjt|�k�rBt
jk�rVnnt|�|_t
|_	Wnt�ylYn0nBtt
fD]8}z|�||�|_WnY�qxYn0||_	�q��qx|j	du�rTtd|��n�t|��rz|j	�||�|_Wn(t�ytd||j	j
f��Yn0n>d
t|�k�r6|j	jk�rFnnt|�|_ntd
|f��dS)u�
        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 if passed as a string.

            Matters only in IPv4 context.

            Allowed flag values:

            * The default (``0``) or :data:`INET_ATON`. Follows `inet_aton semantics
              <https://www.netmeister.org/blog/inet_aton.html>`_ and allows all kinds of
              weird-looking addresses to be parsed. For example:

              >>> IPAddress('1')
              IPAddress('0.0.0.1')
              >>> IPAddress('1.0xf')
              IPAddress('1.0.0.15')
              >>> IPAddress('010.020.030.040')
              IPAddress('8.16.24.32')

            * ``INET_ATON | ZEROFILL`` or :data:`ZEROFILL` – like the default, except leading zeros are discarded:

              >>> IPAddress('010', flags=INET_ATON | ZEROFILL)
              IPAddress('0.0.0.10')

            * :data:`INET_PTON` – requires four decimal octets:

              >>> IPAddress('10.0.0.1', flags=INET_PTON)
              IPAddress('10.0.0.1')

              Leading zeros may be ignored or rejected, depending on the platform.

            * ``INET_PTON | ZEROFILL`` – like :data:`INET_PTON`, except leading zeros are
              discarded:

              >>> IPAddress('010.020.030.040', flags=INET_PTON | ZEROFILL)
              IPAddress('10.20.30.40')

        .. versionchanged:: 0.10.0
            The default IPv4 parsing mode is scheduled to become :data:`INET_PTON` in the next
            major release.
        �&Unrecognized IPAddress flags value: %sz.INET_ATON and INET_PTON are mutually exclusiveNz1cannot switch IP versions using copy constructor!rErF�%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)�superrbrr	rr�
ValueErrorrrrrGrrArCr�	__class__r\r�intr"Z
str_to_intr)r�addrrG�flags�module�rhrrr
sh4
�"
$


�

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

        rErFz&unpickling failed for object state: %sN)rrArrCrg�str)r�stater%rGrrr�__setstate__�s�zIPAddress.__setstate__cCs�|��s|jjS|jdkrdS|j}d}|dkrP|d@dkr>qP|d7}|dL}q(|jj|}d|krt|jjks�ntd|��|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�widthrrg)rZi_val�numbitsZmask_lengthrrr�netmask_bits�s"

�zIPAddress.netmask_bitscCs|jd}||d@dkS)zV
        :return: ``True`` if this IP address host mask, ``False`` otherwise.
        rrrr(�rZint_valrrr�is_hostmask�s
zIPAddress.is_hostmaskcCs"|j|jjAd}||d@dkS)zY
        :return: ``True`` if this IP address network mask, ``False`` otherwise.
        rrr)rrr"rwrrrrs�szIPAddress.is_netmaskcCs@t|j|�}d|kr&|jjkr4nn
||_|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.
        r�)result outside valid IP address boundary!N�rirrr"�
IndexError�rZnumZ	new_valuerrr�__iadd__�s
	zIPAddress.__iadd__cCs@t|j|�}d|kr&|jjkr4nn
||_|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.
        rryNrzr|rrr�__isub__�s
	zIPAddress.__isub__cCsFt|j|�}d|kr&|jjkr:nn|�||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.
        rryN�rirrr"rhrGr{r|rrr�__add__�s	zIPAddress.__add__cCsFt|j|�}d|kr&|jjkr:nn|�||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.
        rryNrr|rrr�__sub__�s	zIPAddress.__sub__cCsFt||j�}d|kr&|jjkr:nn|�||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.
        rryNrr|rrr�__rsub__s	zIPAddress.__rsub__cCs|jj|jfSr-rWrrrrr0sz
IPAddress.keycCs|jj|j|jjfS)zI:return: A key tuple used to compare and sort this `IPAddress` correctly.)rrGrrtrrrrr1szIPAddress.sort_keycCs|jS�z<:return: the value of this IP address as an unsigned integerr(rrrr�__int__szIPAddress.__int__cCs|jSr�r(rrrr�__long__#szIPAddress.__long__cCs|jdkrdSd|jS)z;:return: an octal string representation of this IP address.r�0z0%or(rrrr�__oct__'s
zIPAddress.__oct__cCs
d|jS)z@:return: a hexadecimal string representation of this IP address.z0x%xr(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__3szIPAddress.__index__cCs|j�|jjdd�S)zx 
        :return: a bytes object equivalent to this IP address. In network
            byte order, big-endian.
        ��big)r�to_bytesrrtrrrr�	__bytes__;szIPAddress.__bytes__cCs|j�|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�bitsCszIPAddress.bitscCs|j�|j�S)z7The value of this IP address as a packed binary string.)rZ
int_to_packedrrrrr�packedKszIPAddress.packedcCs|j�|j�S)zx
        A list of unsigned integer words (octets for IPv4, hextets for IPv6)
        found in this IP address.
        )rZint_to_wordsrrrrr�wordsPszIPAddress.wordscCs|j�|j�S)z�
        The value of this IP address 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_binrrrrr�binXsz
IPAddress.bincCs|j�|j�S)z1The reverse DNS lookup record for this IP address)rZint_to_arparrrrr�reverse_dnsaszIPAddress.reverse_dnscCs�d}|j}|jjdkr$||jd�}np|jjdkr�d|jkrHtjkrZnn||jd�}n:tj|jkrrdkr�nn||jdd�}ntd|��|S)z�
        Raises an `AddrConversionError` if IPv6 address cannot be converted
        to IPv4.

        :return: A numerically equivalent version 4 `IPAddress` object.
        NrErFr�������2IPv6 address %s unsuitable for conversion to IPv4!)rhrrGrrAr"r)r�ip�klassrrrr
fs�zIPAddress.ipv4FcCs�d}|j}|jjdkrT|rFd|jkr0dkrFnn||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.
        NrFr�r�rE)rhrrGr�rZipv4_compatibler�r�rrrr|s��
zIPAddress.ipv6cCs,|durt|d�std��|jj|j|d�S)z�
        Only relevant for IPv6 addresses. Has no effect for IPv4.

        :param dialect: One of the :ref:`ipv6_formatting_dialects`.

        :return: an alternate string representation for this IP address.
        NZword_fmtz-custom dialects should subclass ipv6_verbose!)�dialect)�hasattrr r�
int_to_strr)rr�rrr�format�s
�zIPAddress.formatcCs|�|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``.
        �rhrrirrGr6rrr�__or__�szIPAddress.__or__cCs|�|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``.
        r�r6rrr�__and__�szIPAddress.__and__cCs|�|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``.
        r�r6rrr�__xor__�szIPAddress.__xor__cCs|�|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``.
        �rhrrrG�rrurrr�
__lshift__�szIPAddress.__lshift__cCs|�|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``.
        r�r�rrr�
__rshift__�szIPAddress.__rshift__cCs
t|j�S)zi:return: ``True`` if the numerical value of this IP address is not             zero, ``False`` otherwise.)�boolrrrrr�__nonzero__�szIPAddress.__nonzero__cCs|j�|j�S)z,:return: IP address in presentational format)rr�rrrrr�__str__�szIPAddress.__str__cCsd|jj|fS��8:return: Python statement to create an equivalent objectz%s('%s')�rhr\rrrr�__repr__�szIPAddress.__repr__cCs|��s|S|��S)aB
        Converts the address to IPv4 if it is an IPv4-mapped IPv6 address (`RFC 4291
        Section 2.5.5.2 <https://datatracker.ietf.org/doc/html/rfc4291.html#section-2.5.5.2>`_),
        otherwise returns the address as-is.

        >>> # IPv4-mapped IPv6
        >>> IPAddress('::ffff:10.0.0.1').to_canonical()
        IPAddress('10.0.0.1')
        >>>
        >>> # Everything else
        >>> IPAddress('::1').to_canonical()
        IPAddress('::1')
        >>> IPAddress('10.0.0.1').to_canonical()
        IPAddress('10.0.0.1')

        .. versionadded:: 0.10.0
        )rXr
rrrr�to_canonical�szIPAddress.to_canonicalcsL�jjdkrt}t}nt}t}t�fdd�|D��pJt�fdd�|D��S)a�
        Returns ``True`` if this address is considered globally reachable, ``False`` otherwise.

        An address is considered globally reachable if it's not a special-purpose address
        or it's a special-purpose address listed as globally reachable in the relevant
        registries:

        * |iana_special_ipv4|
        * |iana_special_ipv6|

        Addresses for which the ``Globally Reachable`` value is ``N/A`` are not considered
        globally reachable.

        Address blocks with set termination date are not taken into consideration.

        Whether or not an address can actually be reached in any local or global context will
        depend on the network configuration and may differ from what this method returns.

        Currently there can be addresses that are neither ``is_global()`` nor :meth:`is_private`.
        There are also addresses that are both. All things being equal ``is_global()`` should
        be considered more trustworthy.

        Examples:

        >>> IPAddress('1.1.1.1').is_global()
        True
        >>> IPAddress('::1').is_global()
        False

        .. note:: |ipv4_in_ipv6_handling|
        rEc3s|]}�|vVqdSr'r��.0�netrrr�	<genexpr>"r*z&IPAddress.is_global.<locals>.<genexpr>c3s|]}�|vVqdSr'rr�rrrr�#r*)rrG�IPV4_NOT_GLOBALLY_REACHABLE�&IPV4_NOT_GLOBALLY_REACHABLE_EXCEPTIONS�IPV6_NOT_GLOBALLY_REACHABLE�&IPV6_NOT_GLOBALLY_REACHABLE_EXCEPTIONS�any)rZ
not_reachable�
exceptionsrrr�	is_global�s �zIPAddress.is_globalcs"�jjdko t�fdd�tD��S)a=
        Returns ``True`` if this address is an IPv4 private-use address as defined in
        :rfc:`1918`.

        The private-use address blocks:

        * ``10.0.0.0/8``
        * ``172.16.0.0/12``
        * ``192.168.0.0/16``

        .. note:: |ipv4_in_ipv6_handling|

        .. versionadded:: 0.10.0
        rEc3s|]}�|vVqdSr'r�r�rOrrrr�5r*z0IPAddress.is_ipv4_private_use.<locals>.<genexpr>)rrGr��IPV4_PRIVATE_USErrrr�is_ipv4_private_use&szIPAddress.is_ipv4_private_usecCs|jjdko|tvS)z�
        Returns ``True`` if this address is an IPv6 unique local address as defined in
        :rfc:`4193` and listed in |iana_special_ipv6|.

        The IPv6 unique local address block: ``fc00::/7``.

        .. versionadded:: 0.10.0
        rF)rrG�IPV6_UNIQUE_LOCALrrrr�is_ipv6_unique_local7s	zIPAddress.is_ipv6_unique_local)Nr)N)F)N)0r\r]r^r_r`rrnrqrvrxrsr}r~r��__radd__r�r�r0r1r�r�r�r�r�r�r�rar�r�r�r�r
rr�r�r�r�r�r�r��__bool__r�r�r�r�r�r��
__classcell__rrrmrrbs^y	






					,rbc@sLeZdZdZdZdd�Zedd��Zdd�Zd	d
�Z	dd�Z
d
d�ZeZdS)�IPListMixinzu
    A mixin class providing shared list-like functionality to classes
    representing groups of IP addresses.

    rcCs*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.
        )rb�firstrrG�last�iter_iprange)r�start_ip�end_iprrr�__iter__JszIPListMixin.__iter__cCst|j|jd�S)zP
        The total number of IP addresses within this ranged IP object.
        rr)rir�r�rrrr�sizeSszIPListMixin.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�rr{)rr�rrr�__len__Zs�zIPListMixin.__len__cCs@d}t|d�r�|jjdkr"td��|�|j�\}}}||dksH||kr`tt|j|jj�g�}n8t|j||jj�}t|j|||jj�}t	|||�}n�z�t
|�}|j|kr�dkr�nnt|j|d|jj�}n>d|kr�|jdk�rnnt|j||jj�}ntd��Wn t
�y:td|��Yn0|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�indicesrFzIPv6 slices are not supported!rrrz'index out range for address range size!zunsupported index type %r!)r�rrGr r�r��iterrbr�r�rir�r{rg)r�index�item�start�stop�stepr�r�rrr�__getitem__fs(
 zIPListMixin.__getitem__cCsdt|t�rX|jj|jjkrdSt|t�r@|j|jko>|j|jkS|j|jkoV|j|jkSt|�|vS)��
        :param other: an `IPAddress` or ranged IP object.

        :return: ``True`` if other falls within the boundary of this one,
            ``False`` otherwise.
        F)rrrrGrbrr�r�r6rrr�__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.
        Trrrrrr��szIPListMixin.__nonzero__N)
r\r]r^r_r`r�rar�r�r�r�r�r�rrrrr�Cs	
%r�FcCs
t|t�r|t|�dkr$td|j��|\}}d|krB|jksRntd|j��d|krh|jksxntd|j���njt|t��r�|r�t|�}d|vr�|�	dd�\}}n|}d}zt
||jtd�}WnHt�y|jd	k�rt
�|�}	t
|	|jtd�}ntd
|��Yn0|j}zt|�}Wn�t�yJ|du�rF|j}Yn`t�y�t
||jtd�}
|
���r�|j|
j}n$|
���r�|j|
j}ntd|��Yn0d|k�r�|jk�s�ntd|j��ntd
t|���|t@�r|j|}||@}||fS)N�zinvalid %s tuple!rz#invalid address value for %s tuple!zinvalid prefix for %s tuple!rerr�rkrEzinvalid IPNetwork address %s!z!addr %r is not a valid IPNetwork!zinvalid prefix for %s address!zunexpected type %s for addr arg)r�tuple�lenrr#r"rtr�cidr_abbrev_to_verbose�splitrbrGr	rAZexpand_partial_addressrrir rgrsZnetmask_to_prefixrxZhostmask_to_prefixr!rZprefix_to_netmask)rlrj�implicit_prefixrkr%�	prefixlenZval1Zval2r�Z
expanded_addr�mask�netmaskrrr�parse_ip_network�sd
��





��

r�csPeZdZdZdZdD�fdd�	Zdd	�Zd
d�Zdd
�Ze	dd�edd�Z
e	dd��Ze	dd��Ze	dd��Z
e	dd��Ze	dd��Ze	dd��Zejdd��Ze	dd ��Ze	d!d"��Ze	d#d$��Ze	d%d&��Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�ZdEd3d4�ZdFd6d7�ZdGd8d9�ZdHd:d;�ZdId<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#�Z$S)J�	IPNetworka�
    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

       .. deprecated:: 0.10.0

    .. warning::

        The next release (0.9.0) will contain a backwards incompatible change
        connected to handling of RFC 6164 IPv6 addresses (/127 and /128 subnets).
        When iterating ``IPNetwork`` and ``IPNetwork.iter_hosts()`` the first
        addresses in the networks will no longer be excluded and ``broadcast``
        will be ``None``.
    ��
_prefixlenFNrcsRtt|���|t@r&td|f��d\}}}t|d�rN|j}|j}|j}n�t|d�rl|j}|j}|j	}n�|dkr�t
t|||d�\}}t}n�|dkr�t
t|||d�\}}t}n�|dur�td	|��zt}t
||||�\}}Wn\t
�y:zt}t
||||�\}}Wnt
�yYn0|du�r6t
d
|f��Yn0||_||_||_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)

            .. deprecated:: 0.10.0

        :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
            :data:`NOHOST` option.

            >>> IPNetwork('1.2.3.4/24')
            IPNetwork('1.2.3.4/24')
            >>> IPNetwork('1.2.3.4/24', flags=NOHOST)
            IPNetwork('1.2.3.0/24')
        rc)NNNr�rrE)r�rkrFNrdzinvalid IPNetwork %s)rfr�rrrgr�rrr�rtr�rArCr)rrjr�rGrkr%r�rlrmrrr sT



�
�
��
zIPNetwork.__init__cCs|j|j|jjfS)z0:return: Pickled state of an `IPNetwork` object.)rr�rrGrrrrrnmszIPNetwork.__getstate__cCst|\}}}||_|dkr t|_n|dkr0t|_ntd|f��d|krV|jjkrbnn||_ntd|f��dS)zT
        :param state: data used to unpickle a pickled `IPNetwork` object.

        rErFz%unpickling failed for object state %srN)rrArrCrgrtr�)rrpr%r�rGrrrrqqs
��zIPNetwork.__setstate__cCsNt|t�stdt|���d|kr2|jjksDntd|jj��||_dS)Nrrz!invalid prefix for an %s address!)	rrr r!rrtrr#r�r$rrr�_set_prefixlen�s
�zIPNetwork._set_prefixlencCs|jSr'r�rrrrr)�r*zIPNetwork.<lambda>zCsize of the bitmask used to separate the network from the host bitsr+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.
        )rbrrrGrrrrr��szIPNetwork.ipcCst|j|j@|jj�S)z/The network address of this `IPNetwork` object.)rbr�_netmask_intrrGrrrr�network�szIPNetwork.networkcCs0|jj|jdkrdSt|j|jB|jj�SdS)aFThe broadcast address of this `IPNetwork` object.

        .. warning::

            The next release (0.9.0) will contain a backwards incompatible change
            connected to handling of RFC 6164 IPv6 addresses (/127 and /128 subnets).
            ``broadcast`` will be ``None`` when dealing with those networks.
        rrN)rrtr�rbr�
_hostmask_intrGrrrr�	broadcast�s
zIPNetwork.broadcastcCs|j|jj|jA@S)ze
        The integer value of first IP address found within this `IPNetwork`
        object.
        )rrr"r�rrrrr��szIPNetwork.firstcCs d|jj|j>d}|j|BS)zd
        The integer value of last IP address found within this `IPNetwork`
        object.
        rr)rrtr�r�r�hostmaskrrrr��szIPNetwork.lastcCs|jj|jA}t||jj�S)z+The subnet mask of this `IPNetwork` object.)rr"r�rbrG)rr�rrrr��szIPNetwork.netmaskcCsJt|�}|j|jkr$td||f��|��s<tdt|���|��|_dS)z%Set the prefixlen using a subnet maskzIP version mismatch: %s and %sz!Invalid subnet mask specified: %sN)rbrGrgrsrorvr�)rr%r�rrrr��scCs|jj|jAS)z+Same as self.netmask, but in integer format)rr"r�rrrrr��szIPNetwork._netmask_intcCs$d|jj|j>d}t||jj�S)z)The host mask of this `IPNetwork` object.rr)rrtr�rbrGr�rrrr��szIPNetwork.hostmaskcCsd|jj|j>dS)z,Same as self.hostmask, but in integer formatrr)rrtr�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.
        �rG)r�rr�r�rrGrrrrrO�s�zIPNetwork.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.
        rrz#increment exceeds address boundary!rzincrement is less than zero!)rir�r�rr"r{rr|rrrr}�szIPNetwork.__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!rrz#decrement exceeds address boundary!)rir�r�r{rr"rr|rrrr~szIPNetwork.__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|�|vS)r�Frr)rrrrGrtr�r�IPRange�_start�_endrbr�)rr7�
shiftwidthZself_netZ	other_netrrrr�s


�


zIPNetwork.__contains__cCs|jj|j|jfS)zR
        :return: A key tuple used to uniquely identify this `IPNetwork`.
        �rrGr�r�rrrrr06sz
IPNetwork.keycCs8|jd}|j|jj|jA@}|j|}|jj|||fS)z[
        :return: A key tuple used to compare and sort this `IPNetwork` correctly.
        rr)r�rrr"r�rG)rZ
net_size_bitsr�Z	host_bitsrrrr1<s

zIPNetwork.sort_keycCs�d}|j}|jjdkr,|d|j|jf�}n�|jjdkr�d|jkrPtjkrxnn$t�|j�}|d||jdf�}nPtj|jkr�dkr�nn(t�|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.
        NrE�%s/%drFr�`r�r�r�)
rhrrGr�r�rrAr"r�r)rr�r�rjrrrr
Es�zIPNetwork.ipv4cCs�d}|j}|jjdkrd|rNd|jkr0dkrNnn||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.
        NrFr�r�r�rEr�)rhrrGrr�r�rrrr\s*��
�
��zIPNetwork.ipv6rrcCs(|�d|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.
        r��rhr�r�rrG�rr�Zip_copyrrr�previous|s
�zIPNetwork.previouscCs(|�d|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.
        r�r�r�rrr�next�s
�zIPNetwork.nextcCsjd|kr|jjks.ntd||jjf��g}|j}||_|j|jkrf|�|j�|jd7_q>|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.
        r�"CIDR prefix /%d invalid for IPv%d!rr)rrtrgrGrOr��append)rr�Z	supernets�supernetrrrr��s

�zIPNetwork.supernetc	cs�d|jkr|jjks0ntd||jjf��|j|ks>dS|jj}d||jd||}|durl|}d|kr�|ks�ntd��|j�|j�}d}||kr�|�d||f|jj�}|j|j	|7_||_|d7}|Vq�dS)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.
        rr�Nr�rrz,count outside of current IP subnet boundary!r�)
r�rrtrgrGr�r�rhr%r�)	rr��count�fmtrtZmax_subnetsZbase_subnet�i�subnetrrrr��s,

�
�zIPNetwork.subnetcCs�tg�}|jd}|jjdkr*|jd}n|j}|jdkrZtt||jj�t||jj��}n"tt|j|jj�t|j|jj��}|S)ag
        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 excluded, excepted           when using /31 or /32 subnets as per RFC 3021.

        - for IPv6, only Subnet-Router anycast address (first address in the           network) is excluded as per RFC 4291 section 2.6.1, excepted when using           /127 or /128 subnets as per RFC 6164.

        .. warning::

            The next release (0.9.0) will contain a backwards incompatible change
            connected to handling of RFC 6164 IPv6 addresses (/127 and /128 subnets).
            When iterating ``IPNetwork`` and ``IPNetwork.iter_hosts()`` the first
            addresses in the networks will no longer be excluded.

        :return: an IPAddress iterator
        rrrE)r�r�rrGr�r�r�rb)rZit_hostsZfirst_usable_addressZlast_usable_addressrrr�
iter_hosts�s

��zIPNetwork.iter_hostscCs|j�|j�}d||jfS)z&:return: this IPNetwork in CIDR format�%s/%s)rr�rr�)rrjrrrr�szIPNetwork.__str__cCsd|jj|fSr�r�rrrrr�szIPNetwork.__repr__)FNr)F)rr)rr)r)NN)%r\r]r^r_r`rrnrqr�rar�r�r�r�r�r�r��setterr�r�r�rOr}r~r�r0r1r
rr�r�r�r�r�r�r�r�rrrmrr��sZ1M
�










		
 



).r�c@sveZdZdZdZddd�Zdd�Zdd	�Zd
d�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. Refer to the :meth:`IPAddress.__init__`
            documentation for details.

        r�z(lower bound IP greater than upper bound!N)rbr�rrGr�rir)rr��endrkrrrrs

zIPRange.__init__cCs|jj|jj|jjfS)z.:return: Pickled state of an `IPRange` object.)r�r%r�rrGrrrrrn,szIPRange.__getstate__cCs0|\}}}t||�|_|jj|_t||�|_dS)zQ
        :param state: data used to unpickle a pickled `IPRange` object.
        N)rbr�rr�)rrpr�r�rGrrrrq0s

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|�|vS)NFrr)rrrrGrbr�rr�r�r�rtr�)rr7r�Zother_startZother_next_startrrrr�:s&

�
�

�zIPRange.__contains__cCs
t|j�S)z?The integer value of first IP address in this `IPRange` object.)rir�rrrrr�Psz
IPRange.firstcCs
t|j�S)z>The integer value of last IP address in this `IPRange` object.)rir�rrrrr�UszIPRange.lastcCs|jj|j|jfS)zP
        :return: A key tuple used to uniquely identify this `IPRange`.
        r�rrrrr0ZszIPRange.keycCs$|jjt|j�}|jj|jj|fS)zY
        :return: A key tuple used to compare and sort this `IPRange` correctly.
        )rrtrr�rGr�r)rZskeyrrrr1`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�cidrsgsz
IPRange.cidrscCsd|j|jfS)z<:return: this `IPRange` in a common representational format.z%s-%sr�rrrrr�nszIPRange.__str__cCsd|jj|j|jfS)r�z%s('%s', '%s'))rhr\r�r�rrrrr�rs�zIPRange.__repr__N)r)r\r]r^r_r`rrnrqr�rar�r�r0r1rr�r�rrrrr�s



r�cgs"t|�D]}|D]
}|VqqdS)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)�argsrOr�rrr�iter_unique_ipsxsrcCsddd�}t|�r$d|vs |dkr$|Szt|�}d|||�fWSt�yDd|vr�|�dd�\}}z,dt|�kr�d	ks�ntd
|f��Wq�ty�|YYS0n|}d}|�d�}t|�d
kr�|YStd
t|��D]}|�d�q�|du�r.z||d�}Wnt�y,|YYS0dd�|�|fYStt	f�y^|YS0dS)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|krdks*ntd|��d|kr>dkrFnndSd|krZdkrbnndSd	|krvd
kr~nndSd|kr�d
kr�nndSdS)Nr�zInvalid octet: %r!�r������������rErV)rir{)Zoctetrrr�classful_prefix�sz/cidr_abbrev_to_verbose.<locals>.classful_prefix�:�z%s.0.0.0/%srerrrrVz.prefixlen in address %r out of range for IPv4!N�.rEr�r�)
rrirgr�r��ranger��joinr r{)Zabbrev_cidrrr�Z	part_addr�prefix�tokensrrrr��s@�


r�cCs�t|d�std��g}|D]8}t|ttf�r2|}nt|�}|�|j|j|j|f�q|�	�t
|�d}|dkr�||d||ddkr�||dd||ddkr�||d||dt||dd||d�f||d<||=|d8}qhg}|D]|}t
|�dk�rB|d}t|t��r6|�|�
��n
|�|�n8|d}t|d|d�}	t|d|d�}
|�t|	|
���q|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, subnets or ranges.

    :return: a summarized list of `IPNetwork` objects.
    r�z#A sequence or iterator is expected!rrrr�rE�r�)r�rgrr�r�r�rGr�r��sortr��min�extendrrbr)�ip_addrsZrangesr�r�r�ZmergedZrange_tuple�originalrGZrange_startZ
range_stoprrrr�s6
<<
rcCst||�\}}}||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_excludes
r#cCs"t|�}t|�}|j|jkr*gg|jgfS|j|jkrD|jgggfS|j|jkr\g|ggfSg}g}|jd}|jj}|j}|j}|}|d||}	|j|k�r|j|	kr�|�t||f|d��|	}
n|�t|	|f|d��|}
|d7}||kr��q|
}|
d||}	q�||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.
    rrr�r�N���)	r�r�r�rOr�rrtrGr�)rrr r"�
new_prefixlenZtarget_module_widthZtarget_firstrGZi_lowerZi_upperZmatchedrrrrs8


rcCs�t|�}ztt|��}tt|��}Wnty>td��Yn0||krR|}|}n|}|}|D]$}t|�}||krv|}||kr^|}q^|j|jkr�td��|j}|j}	|j	}
|j
j}|	dkr�||
kr�|	d8}	|d||	>M}q�t||	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.
    z-IP sequence must contain at least 2 elements!z.IP sequence cannot contain both IPv4 and IPv6!rrrr�)r�r�r�
StopIterationrgrGr r�r�r�rrt)rZ
ip_addrs_iterZ	network_aZ	network_bZmin_networkZmax_networkr�r�Zipnumr�Zlowest_ipnumrtrrr�
spanning_cidrUs6
r'rrccs�t|�}t|�}|j|jkr$td��|j}t|�}|dkrBtd��t|�}t|�}d}|dkrbd}||}||7}|r�||ks�q�n
||ks�q�t||�VqjdS)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)rbrGr rirg)r�r�r�rGr�Z
negative_stepr�rrrr��s*r�cCs�g}t|�}t|�}|j|jg}t||g�}|jj}|j|dkrrt|dd|f|jd�}t||�d}|��}|j|dkr�t|dd|f|jd�}|t||�d7}n
|�	|�|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.
    rrrr�r�)
r�r�r�r'rrtrGr�popr�)r�r�Z	cidr_listZiprangeZ	cidr_spanrtrrrrr�s
rcCsdd}t|d�std|f��t|�}tdd�|D��D](}||vrH|}q6|dur6|j|vr6q`q6|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��,IP address/subnet sequence expected, not %r!cSsg|]}t|��qSr�r�r�rrr�
<listcomp>�r*z*smallest_matching_cidr.<locals>.<listcomp>)r�r rb�sortedr��r�r�matchrOrrr�smallest_matching_cidr�s
�r/cCsPd}t|d�std|f��t|�}tdd�|D��D]}||vr6|}qLq6|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�r)cSsg|]}t|��qSrr*r�rrrr+r*z)largest_matching_cidr.<locals>.<listcomp>)r�r rbr,r-rrr�largest_matching_cidr�s
�r0cCsjg}t|d�std|f��t|�}tdd�|D��D].}||vrN|�|�q6|r6|j|dvr6qfq6|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�r)cSsg|]}t|��qSrr*r�rrrr+!r*z&all_matching_cidrs.<locals>.<listcomp>r$)r�r rbr,r�r�)r�r�matchesrOrrr�all_matching_cidrss
�r2�127.0.0.0/8�
10.0.0.0/8�
172.16.0.0/12�192.168.0.0/16�
100.64.0.0/10�192.0.0.0/24�
198.18.0.0/15z	239.0.0.0z239.255.255.255�169.254.0.0/16z224.0.0.0/4z192.88.99.0/24�	0.0.0.0/8�192.0.2.0/24�240.0.0.0/4�198.51.100.0/24�203.0.113.0/24z233.252.0.0/24z	234.0.0.0z238.255.255.255z	225.0.0.0z231.255.255.255cCsg|]}t|��qSrr*r�rrrr+Rsr+)r;r4r7r3r:r5r8z192.0.0.170/31r<r6r9r>r?r=z255.255.255.255/32cCsg|]}t|��qSrr*r�rrrr+fs)z192.0.0.9/32z
192.0.0.10/32�::1/128�fc00::/7z	fec0::/10�	fe80::/10zff00::/8z	ff00::/12z::/8z0100::/8z0200::/7z0400::/6z0800::/5z1000::/4z4000::/3z6000::/3z8000::/3zA000::/3zC000::/3zE000::/4zF000::/5zF800::/6zFE00::/9cCsg|]}t|��qSrr*r�rrrr+�s�)
r@z::/128z
::ffff:0:0/96z64:ff9b:1::/48z100::/64z	2001::/23z
2001:db8::/32z	2002::/16rArBcCsg|]}t|��qSrr*r�rrrr+�s�)z
2001:1::1/128z
2001:1::2/128z2001:3::/32z2001:4:112::/48z2001:20::/28z2001:30::/28)Fr)rr)?r_�sys�_sysZnetaddr.corerrrrrrrr	r
rrZnetaddr.strategyr
rArrCZnetaddr.compatrrrrrr�objectrrbr�r�r�r�rr�rr#rr'r�rr/r0r2rHr�r�rKrQrBZ	IPV4_6TO4rSr�r�rIr�rLrRrDrTr�r�rrrr�<module>s�4 rCe
D$lT3<.
/$��
��
������