o
    g                    @   sD  d Z ddlZddlmZmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZmZmZmZmZmZ G dd deZG dd	 d	eZG d
d deZdUddZG dd deeZG dd deeZ dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dVd d!Z'd"d# Z(d$d% Z)d&d' Z*d(d) Z+ed*Z,ed+ed,ed-ed.ed/ed0e d1d2fZ-ed3Z.ed4Z/ed5Z0ed6ed7ed8ed9ed:ed;e d<d=e d>d?fe,e0f Z1ed@Z2edAedBfZ3edCZ4edDZ5edEedFedGedHedIedJedKedLedMedNedOedPedQedRedSedTfZ6dS )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_next_iter_range_is_str	_int_type	_str_typec                   @   s   e Zd ZdZdZdd Zdd Zedd ed	d
Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zed-d. Zed/d0 Zd1S )2BaseIPzi
    An abstract base class for common operations shared between various IP
    related subclasses.

    )_value_module__weakref__c                 C   s   d| _ d| _dS )zConstructor.N)r   r   self r   Q/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/netaddr/ip/__init__.py__init__   s   
zBaseIP.__init__c                 C   N   t |tstdt| d|  kr| jjks"n td| jj || _d S )Nint argument expected, not %sr   z&value out of bounds for an %s address!)	
isinstancer   	TypeErrortyper   max_intr   family_namer   r   valuer   r   r   
_set_value       

zBaseIP._set_valuec                 C      | j S Nr   r   r   r   r   <lambda>(       zBaseIP.<lambda>z?a positive integer representing the value of IP address/subnet.docc                 C      t S zP
        :return: a key tuple that uniquely identifies this IP address.
        NotImplementedr   r   r   r   key+   s   z
BaseIP.keyc                 C   r/   )zg
        :return: A key tuple used to compare and sort this `IPAddress`
            correctly.
        r1   r   r   r   r   sort_key1   s   zBaseIP.sort_keyc                 C   s   t |  S )zM
        :return: A hash value uniquely indentifying this IP object.
        )hashr3   r   r   r   r   __hash__8   s   zBaseIP.__hash__c              	   C   s.   z	|   |  kW S  ttfy   t Y S w )z
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            equivalent to ``other``, ``False`` otherwise.
        r3   AttributeErrorr    r2   r   otherr   r   r   __eq__>   
   zBaseIP.__eq__c              	   C   s.   z	|   |  kW S  ttfy   t Y S w )z
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            not equivalent to ``other``, ``False`` otherwise.
        r7   r9   r   r   r   __ne__J   r<   zBaseIP.__ne__c              	   C   s.   z	|   |  k W S  ttfy   t Y S w )z
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            less than ``other``, ``False`` otherwise.
        r4   r8   r    r2   r9   r   r   r   __lt__V   r<   zBaseIP.__lt__c              	   C   s.   z	|   |  kW S  ttfy   t Y S w )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.
        r>   r9   r   r   r   __le__b   r<   zBaseIP.__le__c              	   C   s.   z	|   |  kW S  ttfy   t Y S w )z
        :param other: an `IPAddress` or `IPNetwork` object.

        :return: ``True`` if this `IPAddress` or `IPNetwork` object is
            greater than ``other``, ``False`` otherwise.
        r>   r9   r   r   r   __gt__n   r<   zBaseIP.__gt__c              	   C   s.   z	|   |  kW S  ttfy   t Y S w )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.
        r>   r9   r   r   r   __ge__z   r<   zBaseIP.__ge__c                 C   s
   |    S )z<:return: ``True`` if this IP is unicast, ``False`` otherwise)is_multicastr   r   r   r   
is_unicast   s   
zBaseIP.is_unicastc                 C   s(   | j tkr	| tv S | j tkr| tv S dS )z>:return: ``True`` if this IP is multicast, ``False`` otherwiseN)r   _ipv4IPV4_MULTICAST_ipv6IPV6_MULTICASTr   r   r   r   rC      s
   

zBaseIP.is_multicastc                 C   s,   | j jdkr
| tv S | j jdkr| tkS dS )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_LOOPBACKr   r   r   r   is_loopback   s
   zBaseIP.is_loopbackc                 C   sZ   | j jdkrtD ]	}| |v r dS qn| j jdkr%tD ]	}| |v r$ dS q|  r+dS dS )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.
        rI   TrJ   F)r   rK   IPV4_PRIVATEIPV6_PRIVATEis_link_localr   cidrr   r   r   
is_private   s   zBaseIP.is_privatec                 C   s,   | j jdkr
| tv S | j jdkr| tv S dS )z
        :return: ``True`` if this IP is link-local address ``False`` otherwise.
            Reference: RFCs 3927 and 4291.
        rI   rJ   N)r   rK   IPV4_LINK_LOCALIPV6_LINK_LOCALr   r   r   r   rQ      s
   zBaseIP.is_link_localc                 C   sP   | j jdkrtD ]	}| |v r dS qdS | j jdkr&tD ]	}| |v r% dS qdS )z
        :return: ``True`` if this IP is in IANA reserved range, ``False``
            otherwise. Reference: RFCs 3330 and 3171.
        rI   TrJ   F)r   rK   IPV4_RESERVEDIPV6_RESERVEDrR   r   r   r   is_reserved   s   zBaseIP.is_reservedc                 C      | j jdko| jd? dkS )zp
        :return: ``True`` if this IP is IPv4-compatible IPv6 address, ``False``
            otherwise.
        rJ       i  r   rK   r   r   r   r   r   is_ipv4_mapped      zBaseIP.is_ipv4_mappedc                 C   rZ   )zl
        :return: ``True`` if this IP is IPv4-mapped IPv6 address, ``False``
            otherwise.
        rJ   r[   r   r\   r   r   r   r   is_ipv4_compat   r^   zBaseIP.is_ipv4_compatc                 C   s   ddl m} t|| S )z~
        A record dict containing IANA registration details for this IP address
        if available, None otherwise.
        r   )query)netaddr.ip.ianar`   r   )r   r`   r   r   r   info   s   zBaseIP.infoc                 C   s   | j jS )z6the IP protocol version represented by this IP object.)r   rK   r   r   r   r   rK      s   zBaseIP.versionN)__name__
__module____qualname____doc__	__slots__r   r&   propertyr%   r3   r4   r6   r;   r=   r?   r@   rA   rB   rD   rC   rN   rT   rQ   rY   r]   r_   rb   rK   r   r   r   r   r      s:    


	r   c                       sT  e Zd ZdZdZdL fdd	Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZeZdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZdMd+d,Zed-d. Zed/d0 Zed1d2 Zed3d4 Zd5d6 ZdNd8d9Z dMd:d;Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'e'Z(dHdI Z)dJdK Z*  Z+S )O	IPAddressz
    An individual IPv4 or IPv6 address without a net mask or subnet prefix.

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

    r   Nr   c                    s  t t|   t|tr$|dur||jjkrtd|j| _|j| _dS |dur>|dkr0t	| _n|dkr8t
| _ntd| t|rNd|v rNtd| jj | jdu rt|trz2dt|  krft	jkrqn n	t|| _t	| _nt	jt|  k rt
jkrn nt|| _t
| _W n" ty   Y nw t	t
fD ]}z	|||| _W n   Y q|| _ | jdu rtd	| dS t|rz| j||| _W dS  ty   td
|| jjf w dt|  kr| jjkrn nt|| _dS td|f )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!rI   rJ   %r is an invalid IP version!/zQ%s() does not support netmasks or subnet prefixes! See documentation for details.r   z+failed to detect a valid IP address from %rzbase address %r is not IPv%dzbad address format: %r)superri   r   r   r   r   rK   
ValueErrorr   rE   rG   r   	__class__rc   r   intr"   
str_to_intr   )r   addrrK   flagsmodulern   r   r   r      sh   



 


 zIPAddress.__init__c                 C   s   | j | jjfS )z1:returns: Pickled state of an `IPAddress` object.)r   r   rK   r   r   r   r   __getstate__A     zIPAddress.__getstate__c                 C   sB   |\}}|| _ |dkrt| _dS |dkrt| _dS tdt| )zT
        :param state: data used to unpickle a pickled `IPAddress` object.

        rI   rJ   z&unpickling failed for object state: %sN)r   rE   r   rG   rm   str)r   stater%   rK   r   r   r   __setstate__E  s   

zIPAddress.__setstate__c                 C   s   |   s| jjS | jdkrdS | j}d}|dkr+|d@ dkrn|d7 }|dL }|dks| jj| }d|  kr=| jjksDn td| |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   widthr   rm   )r   i_valnumbitsmask_lengthr   r   r   netmask_bitsV  s$   
zIPAddress.netmask_bitsc                 C   s   | j d }||d @ dkS )zV
        :return: ``True`` if this IP address host mask, ``False`` otherwise.
        rz   r   r*   r   int_valr   r   r   is_hostmasku  s   
zIPAddress.is_hostmaskc                 C   s"   | j | jjA d }||d @ dkS )zY
        :return: ``True`` if this IP address network mask, ``False`` otherwise.
        rz   r   )r   r   r"   r   r   r   r   r{   |  s   zIPAddress.is_netmaskc                 C   sB   t | j| }d|  kr| jjkrn td|| _| S td)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!ro   r   r   r"   
IndexErrorr   num	new_valuer   r   r   __iadd__     	zIPAddress.__iadd__c                 C   sB   t | j| }d|  kr| jjkrn td|| _| S td)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.
        r   r   r   r   r   r   r   __isub__  r   zIPAddress.__isub__c                 C   sH   t | j| }d|  kr| jjkr n td| || jjS td)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.
        r   r   ro   r   r   r"   rn   rK   r   r   r   r   r   __add__  
   	zIPAddress.__add__c                 C   sH   t | j| }d|  kr| jjkr n td| || jjS td)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.
        r   r   r   r   r   r   r   __sub__  r   zIPAddress.__sub__c                 C   sH   t || j }d|  kr| jjkr n td| || jjS td)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.
        r   r   r   r   r   r   r   __rsub__  r   zIPAddress.__rsub__c                 C   s   | j j| jfS r0   r\   r   r   r   r   r3        zIPAddress.keyc                 C   s   | j j| j| j jfS )zI:return: A key tuple used to compare and sort this `IPAddress` correctly.)r   rK   r   r|   r   r   r   r   r4     s   zIPAddress.sort_keyc                 C   r(   z<:return: the value of this IP address as an unsigned integerr*   r   r   r   r   __int__     zIPAddress.__int__c                 C   r(   r   r*   r   r   r   r   __long__  r   zIPAddress.__long__c                 C   s   | j dkrdS d| j  S )z;:return: an octal string representation of this IP address.r   0z0%or*   r   r   r   r   __oct__  s   

zIPAddress.__oct__c                 C   s
   d| j  S )z@:return: a hexadecimal string representation of this IP address.z0x%xr*   r   r   r   r   __hex__     
zIPAddress.__hex__c                 C   r(   )zx
        :return: return the integer value of this IP address when called by             hex(), oct() or bin().
        r*   r   r   r   r   	__index__  s   zIPAddress.__index__c                 C   s   | j | jjd dS )zt 
        :return: a bytes object equivalent to this IP address. In network
        byte order, big-endian.
           big)r   to_bytesr   r|   r   r   r   r   	__bytes__  s   zIPAddress.__bytes__c                 C   s   | 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.)r   int_to_bitsr   )r   word_sepr   r   r   bits  s   zIPAddress.bitsc                 C      | j | jS )z7The value of this IP address as a packed binary string.)r   int_to_packedr   r   r   r   r   packed     zIPAddress.packedc                 C   r   )zx
        A list of unsigned integer words (octets for IPv4, hextets for IPv6)
        found in this IP address.
        )r   int_to_wordsr   r   r   r   r   words  s   zIPAddress.wordsc                 C   r   )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.
        )r   
int_to_binr   r   r   r   r   bin  r   zIPAddress.binc                 C   r   )z1The reverse DNS lookup record for this IP address)r   int_to_arpar   r   r   r   r   reverse_dns  r   zIPAddress.reverse_dnsc                 C   s   d}| j }| jjdkr|| jd}|S | jjdkrMd| j  kr%tjkr/n n|| jd}|S tj| j  kr;dkrGn n
|| jd d}|S td|  |S )z
        Raises an `AddrConversionError` if IPv6 address cannot be converted
        to IPv4.

        :return: A numerically equivalent version 4 `IPAddress` object.
        NrI   rJ   r               2IPv6 address %s unsuitable for conversion to IPv4!)rn   r   rK   r   rE   r"   r   )r   ipklassr   r   r   r   !  s    	zIPAddress.ipv4Fc                 C   s   d}| j }| jjdkr,|r$d| j  krdkr$n n
|| jd d}|S || jd}|S | jjdkrB|| jd}|sB|d| j d}|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.
        NrJ   r   r   rI   )rn   r   rK   r   r   ipv4_compatibler   r   r   r   r   r   7  s   
zIPAddress.ipv6c                 C   s,   |durt |dstd| jj| 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.
        Nword_fmtz-custom dialects should subclass ipv6_verbose!)dialect)hasattrr    r   
int_to_strr   )r   r   r   r   r   formatT  s   
zIPAddress.formatc                 C   s   |  | jt|B | jj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``.
        rn   r   ro   r   rK   r9   r   r   r   __or__b     zIPAddress.__or__c                 C   s   |  | jt|@ | jj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   r9   r   r   r   __and__k  r   zIPAddress.__and__c                 C   s   |  | jt|A | jj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   r9   r   r   r   __xor__t  r   zIPAddress.__xor__c                 C   s   |  | j|> | jjS )z
        :param numbits: size of bitwise shift.

        :return: an `IPAddress` object based on this one with its integer
            value left shifted by ``numbits``.
        rn   r   r   rK   r   r~   r   r   r   
__lshift__}     zIPAddress.__lshift__c                 C   s   |  | j|? | jj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   r   r   r   
__rshift__  r   zIPAddress.__rshift__c                 C   
   t | jS )zi:return: ``True`` if the numerical value of this IP address is not             zero, ``False`` otherwise.)boolr   r   r   r   r   __nonzero__  s   
zIPAddress.__nonzero__c                 C   r   )z,:return: IP address in presentational format)r   r   r   r   r   r   r   __str__  rv   zIPAddress.__str__c                 C      d| j j| f S 8:return: Python statement to create an equivalent objectz%s('%s')rn   rc   r   r   r   r   __repr__     zIPAddress.__repr__)Nr   r)   F),rc   rd   re   rf   rg   r   ru   ry   r   r   r{   r   r   r   __radd__r   r   r3   r4   r   r   r   r   r   r   r   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   __bool__r   r   __classcell__r   r   rt   r   ri      sX    Q	






					ri   c                   @   sL   e Zd ZdZdZdd Zedd Zdd Zd	d
 Z	dd Z
dd ZeZdS )IPListMixinzu
    A mixin class providing shared list-like functionality to classes
    representing groups of IP addresses.

    r   c                 C   s*   t | j| jj}t | j| jj}t||S )z
        :return: An iterator providing access to all `IPAddress` objects
            within range represented by this ranged IP object.
        )ri   firstr   rK   lastiter_iprange)r   start_ipend_ipr   r   r   __iter__  s   
zIPListMixin.__iter__c                 C   s   t | j| j d S )zP
        The total number of IP addresses within this ranged IP object.
        rz   )ro   r   r   r   r   r   r   size  s   zIPListMixin.sizec                 C   s   | j }|tkrtdt |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   r   r   )r   r   r   r   r   __len__  s   zIPListMixin.__len__c                 C   sB  d}t |drO| jjdkrtd|| j\}}}|| dk s$||kr1tt| j| jjg}|S t| j| | jj}t| j| | | jj}t	|||}|S zDt
|}| j |  kr`dk rqn nt| j| d | jj}W |S d|  kr~| jd krn tdt| j| | jj}W |S td ty   td| w )	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indicesrJ   zIPv6 slices are not supported!r   rz   z'index out range for address range size!zunsupported index type %r!)r   r   rK   r    r   r   iterri   r   r   ro   r   r   rm   )r   indexitemstartstopstepr   r   r   r   r   __getitem__  s2   
	zIPListMixin.__getitem__c                 C   sd   t |tr,| jj|jjkrdS t |tr |j| jko|j| jkS |j| jko+|j| jkS t|| v S )
        :param other: an `IPAddress` or ranged IP object.

        :return: ``True`` if other falls within the boundary of this one,
            ``False`` otherwise.
        F)r   r   r   rK   ri   r   r   r   r9   r   r   r   __contains__  s   

zIPListMixin.__contains__c                 C   s   dS )z
        Ranged IP objects always represent a sequence of at least one IP
        address and are therefore always True in the boolean context.
        Tr   r   r   r   r   r     s   zIPListMixin.__nonzero__N)rc   rd   re   rf   rg   r   rh   r   r   r   r   r   r   r   r   r   r   r     s    	
%r   Fc                 C   s  t |tr=t|dkrtd| j |\}}d|  kr!| jks)n td| j d|  kr4| jks<n td| j nt |tr|rHt|}d|v rU|	dd\}}n|}d }z
t
|| jtd}W n" ty   | jd	kr}t|}	t
|	| jtd}ntd
| Y nw |j}zt|}W n< ty   |d u r| j}Y n- ty   t
|| jtd}
|
 r| j|
j }n|
 r| j|
j }ntd| Y nw d|  kr| jksn td| j ntdt| |t@ r| j| }||@ }||fS )N   zinvalid %s tuple!r   z#invalid address value for %s tuple!zinvalid prefix for %s tuple!rk   rz   rr   rI   zinvalid IPNetwork address %s!z!addr %r is not a valid IPNetwork!zinvalid prefix for %s address!zunexpected type %s for addr arg)r   tuplelenr   r#   r"   r|   r   cidr_abbrev_to_verbosesplitri   rK   r   rE   expand_partial_addressr   ro   r    rm   r{   netmask_to_prefixr   hostmask_to_prefixr!   r   prefix_to_netmask)rs   rq   implicit_prefixrr   r%   	prefixlenval1val2r   expanded_addrmasknetmaskr   r   r   parse_ip_network  sr   




r   c                       sP  e Zd ZdZdZdD fdd	Zdd	 Zd
d Zdd Ze	dd eddZ
e	dd Ze	dd Ze	dd Ze	dd Ze	dd Ze	dd Zejdd Ze	dd  Ze	d!d" Ze	d#d$ Ze	d%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 ZdEd3d4ZdFd6d7ZdFd8d9ZdGd:d;ZdHd<d=Z d>d? Z!d@dA Z"dBdC Z#  Z$S )I	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

    .. 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``.
    
_prefixlenFNr   c                    s4  t t|   d\}}}t|dr|j}|j}|j}ntt|dr*|j}|j}|j}ne|dkr;tt	|||d\}}t	}nT|dkrLtt
|||d\}}t
}nC|durVtd| zt	}t||||\}}W n+ ty   zt
}t||||\}}W n	 ty   Y nw |du rtd	|f Y nw || _|| _|| _dS )
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.

        )NNNr   r   rI   )r   rr   rJ   Nrj   zinvalid IPNetwork %s)rl   r   r   r   r   r   r   r|   r   rE   rG   rm   r   )r   rq   r   rK   rr   r%   r   rs   rt   r   r   r   {  sV   





zIPNetwork.__init__c                 C   s   | j | j| jjfS )z0:return: Pickled state of an `IPNetwork` object.)r   r   r   rK   r   r   r   r   ru     s   zIPNetwork.__getstate__c                 C   sr   |\}}}|| _ |dkrt| _n|dkrt| _ntd|f d|  kr+| jjkr2n n|| _dS td|f )zT
        :param state: data used to unpickle a pickled `IPNetwork` object.

        rI   rJ   z%unpickling failed for object state %sr   N)r   rE   r   rG   rm   r|   r   )r   rx   r%   r   rK   r   r   r   ry     s   

zIPNetwork.__setstate__c                 C   r   )Nr   r   z!invalid prefix for an %s address!)	r   r   r    r!   r   r|   r   r#   r   r$   r   r   r   _set_prefixlen  r'   zIPNetwork._set_prefixlenc                 C   r(   r)   r   r   r   r   r   r+     r,   zIPNetwork.<lambda>zCsize of the bitmask used to separate the network from the host bitsr-   c                 C   s   t | j| jj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.
        )ri   r   r   rK   r   r   r   r   r     s   zIPNetwork.ipc                 C   s   t | j| j@ | jjS )z/The network address of this `IPNetwork` object.)ri   r   _netmask_intr   rK   r   r   r   r   network     zIPNetwork.networkc                 C   s8   | j jdkr| j j| j dkrdS t| j| jB | j jS )aF  The 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.
        rI   rz   N)r   rK   r|   r   ri   r   _hostmask_intr   r   r   r   	broadcast  s   
zIPNetwork.broadcastc                 C   s   | j | jj| jA @ S )ze
        The integer value of first IP address found within this `IPNetwork`
        object.
        )r   r   r"   r   r   r   r   r   r     s   zIPNetwork.firstc                 C   s    d| j j| j > d }| j|B S )zd
        The integer value of last IP address found within this `IPNetwork`
        object.
        rz   )r   r|   r   r   r   hostmaskr   r   r   r   
  s   
zIPNetwork.lastc                 C   s   | j j| jA }t|| j jS )z+The subnet mask of this `IPNetwork` object.)r   r"   r   ri   rK   )r   r   r   r   r   r     s   zIPNetwork.netmaskc                 C   sJ   t |}|j| jkrtd|| f | stdt| | | _dS )z%Set the prefixlen using a subnet maskzIP version mismatch: %s and %sz!Invalid subnet mask specified: %sN)ri   rK   rm   r{   rw   r   r   )r   r%   r   r   r   r   r     s   c                 C   s   | j j| jA S )z+Same as self.netmask, but in integer format)r   r"   r   r   r   r   r   r   &  r   zIPNetwork._netmask_intc                 C   s$   d| j j| j > d }t|| j jS )z)The host mask of this `IPNetwork` object.rz   )r   r|   r   ri   rK   r   r   r   r   r   +  s   zIPNetwork.hostmaskc                 C   s   d| j j| j > d S )z,Same as self.hostmask, but in integer formatrz   )r   r|   r   r   r   r   r   r   1  r   zIPNetwork._hostmask_intc                 C   s   t | j| j@ | jf| jjdS )z
        The true CIDR address for this `IPNetwork` object which omits any
        host bits to the right of the CIDR subnet prefix.
        rK   )r   r   r   r   r   rK   r   r   r   r   rS   6  s   zIPNetwork.cidrc                 C   sL   t | j| j|  }|| jd  | jjkrtd|dk r!td|| _| 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.
        rz   z#increment exceeds address boundary!r   zincrement is less than zero!)ro   r   r   r   r"   r   r   r   r   r   r   r   @  s   zIPNetwork.__iadd__c                 C   sL   t | j| j|  }|dk rtd|| jd  | jjkr!td|| _| 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.
        r   zdecrement is less than zero!rz   z#decrement exceeds address boundary!)ro   r   r   r   r   r"   r   r   r   r   r   r   U  s   zIPNetwork.__isub__c                 C   s   t |trO| jj|jjkrdS | jj| j }| j|? }t |tr2||> |jjko1|d |> |j	jkS |j|? }t |t
r@||kS t |trO||koN| j|jkS t|| v S )r   Frz   )r   r   r   rK   r|   r   r   IPRange_start_endri   r   )r   r:   
shiftwidthself_net	other_netr   r   r   r   j  s   





zIPNetwork.__contains__c                 C      | j j| j| jfS )zR
        :return: A key tuple used to uniquely identify this `IPNetwork`.
        r   rK   r   r   r   r   r   r   r3        zIPNetwork.keyc                 C   s8   | j d }| j| jj| jA @ }| j| }| jj|||fS )z[
        :return: A key tuple used to compare and sort this `IPNetwork` correctly.
        rz   )r   r   r   r"   r   rK   )r   net_size_bitsr   	host_bitsr   r   r   r4     s   

zIPNetwork.sort_keyc                 C   s   d}| j }| jjdkr|d| j| jf }|S | jjdkrgd| j  kr)tjkr>n nt| j}|d|| jd f }|S tj| j  krJdkran nt| jd }|d|| jd f }|S t	d	|  |S )
z
        :return: A numerically equivalent version 4 `IPNetwork` object.             Raises an `AddrConversionError` if IPv6 address cannot be             converted to IPv4.
        NrI   %s/%drJ   r   `   r   r   r   )
rn   r   rK   r   r   r   rE   r"   r   r   )r   r   r   rq   r   r   r   r     s$   zIPNetwork.ipv4c                 C   s   d}| j }| jjdkr4|r(d| j  krdkr(n n|| jd | jfdd}|S || j| jfdd}|S | jjdkrX|rJ|| j| jd fdd}|S |d| j | jd fdd}|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.
        NrJ   r   r   r  rI   r  )rn   r   rK   r   r   r   r   r   r   r     s*   

zIPNetwork.ipv6rz   c                 C   s(   |  d| j| jf | jj}||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  rn   r   r   r   rK   r   r   ip_copyr   r   r   previous  
   zIPNetwork.previousc                 C   s(   |  d| j| jf | jj}||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  r   r   r   next  r  zIPNetwork.nextc                 C   st   d|  kr| j jksn td|| j jf g }| j}||_|j| jkr8||j | jd7  _|j| jks%|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!rz   )r   r|   rm   rK   rS   r   append)r   r   	supernetssupernetr   r   r   r    s   

zIPNetwork.supernetc           	      c   s    d| j   kr| jjksn td|| jjf | j |ks dS | jj}d|| j   d||   }|du r7|}d|  krD|ksItd td| j| j}d}||k r|| d||f | jj}| j|j	| 7  _||_ |d7 }|V  ||k sVdS dS )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.
        r   r  Nr   rz   z,count outside of current IP subnet boundary!r  )
r   r   r|   rm   rK   r   r   rn   r%   r   )	r   r   countfmtr|   max_subnetsbase_subnetisubnetr   r   r   r    s4   

zIPNetwork.subnetc                 C   s   t g }| jjdkr9| jdkr&tt| jd | jjt| jd | jj}|S tt| j| jjt| j| jj}|S | jdkrQtt| jd | jjt| j| jj}|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.

        .. 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
        rI   rz   r   )r   r   rK   r   r   ri   r   r   )r   it_hostsr   r   r   
iter_hosts&  s&   

zIPNetwork.iter_hostsc                 C   s   | j | j}d|| jf S )z&:return: this IPNetwork in CIDR format%s/%s)r   r   r   r   )r   rq   r   r   r   r   R  s   zIPNetwork.__str__c                 C   r   r   r   r   r   r   r   r   W  r   zIPNetwork.__repr__)FNr   r   rz   r   )NN)%rc   rd   re   rf   rg   r   ru   ry   r   rh   r   r   r   r   r   r   r   setterr   r   r   rS   r   r   r   r3   r4   r   r   r  r  r  r  r   r   r   r   r   r   rt   r   r   I  s\    /D











		

 


),r   c                   @   sv   e Zd ZdZdZdddZdd Zdd	 Zd
d Ze	dd Z
e	dd Zdd Zdd Zdd Zdd Zdd ZdS )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  r   c                 C   sL   t ||d| _| jj| _t || jj|d| _t| jt| jkr$tddS )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.

        r   z(lower bound IP greater than upper bound!N)ri   r  r   rK   r  ro   r   )r   r   endrr   r   r   r   r   g  s   
zIPRange.__init__c                 C   s   | j j| jj| jjfS )z.:return: Pickled state of an `IPRange` object.)r  r%   r  r   rK   r   r   r   r   ru   }  s   zIPRange.__getstate__c                 C   s0   |\}}}t ||| _| jj| _t ||| _dS )zQ
        :param state: data used to unpickle a pickled `IPRange` object.
        N)ri   r  r   r  )r   rx   r   r&  rK   r   r   r   ry     s   

zIPRange.__setstate__c                 C   s   t |tr\| jj|jjkrdS t |tr"| jj|jko!| jj|jkS t |tr7| jj|jjko6| jj|jjkS t |t	r\|jj
|j }|j|? |> }|d|>  }| jj|ko[| jj|kS t|| v S )NFrz   )r   r   r   rK   ri   r  r   r  r  r   r|   r   )r   r:   r  other_startother_next_startr   r   r   r     s&   




zIPRange.__contains__c                 C   r   )z?The integer value of first IP address in this `IPRange` object.)ro   r  r   r   r   r   r     r   zIPRange.firstc                 C   r   )z>The integer value of last IP address in this `IPRange` object.)ro   r  r   r   r   r   r     r   zIPRange.lastc                 C   r  )zP
        :return: A key tuple used to uniquely identify this `IPRange`.
        r	  r   r   r   r   r3     r
  zIPRange.keyc                 C   s$   | j jt| j }| j j| jj|fS )zY
        :return: A key tuple used to compare and sort this `IPRange` correctly.
        )r   r|   r   r   rK   r  r   )r   skeyr   r   r   r4     s   zIPRange.sort_keyc                 C   s   t | j| jS )zx
        The list of CIDR addresses found within the lower and upper bound
        addresses of this `IPRange`.
        )iprange_to_cidrsr  r  r   r   r   r   cidrs  s   zIPRange.cidrsc                 C   s   d| j | jf S )z<:return: this `IPRange` in a common representational format.z%s-%sr%  r   r   r   r   r     r   zIPRange.__str__c                 C   s   d| j j| j| jf S )r   z%s('%s', '%s'))rn   rc   r  r  r   r   r   r   r     s   zIPRange.__repr__Nr#  )rc   rd   re   rf   rg   r   ru   ry   r   rh   r   r   r3   r4   r+  r   r   r   r   r   r   r  \  s     



r  c                  g   s$    t | D ]
}|D ]}|V  q	qdS )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)argsrS   r   r   r   r   iter_unique_ips  s   r.  c                 C   sV  dd }t | rd| v s| dkr| S zt| }d|||f W S  ty   d| v rV| dd\}}zdt|  kr?d	ksGn td
| f W n tyU   |  Y  Y S w | }d}|d}t|dkri|  Y S tdt| D ]}|d qq|du rz||d }W n ty   |  Y  Y S w dd||f  Y S  tt	fy   |  Y S w )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.
    c                 S   s   t | } d|   krdksn td|  d|   kr dkr!dS  d|   kr,dkr-dS  d	|   kr8d
kr9dS  d|   krDdkrGdS  dS dS )Nr      zInvalid octet: %r!   r                           rI   r[   )ro   r   )octetr   r   r   classful_prefix  s    z/cidr_abbrev_to_verbose.<locals>.classful_prefix: z%s.0.0.0/%srk   rz   r   r[   z.prefixlen in address %r out of range for IPv4!N.rI   r   r!  )
r   ro   rm   r   r   ranger  joinr    r   )abbrev_cidrr:  r  	part_addrprefixtokensr   r   r   r     sH   
r   c                 C   s  t | ds	tdg }| D ]}t|ttfr|}nt|}||j|j|j|f q|	  t
|d }|dkr|| d ||d  d krw|| d d ||d  d krw|| d || d t||d  d || d f||d < ||= |d8 }|dks8g }|D ];}t
|dkr|d }t|tr||  q|| q|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!rz   r   r   rI      r  )r   rm   r   r   r  r  rK   r   r   sortr   minextendr+  ri   r*  )ip_addrsrangesr   netr  mergedrange_tupleoriginalrK   range_start
range_stopr   r   r   r,  )  s8   
<<
r,  c                 C   s   t | |\}}}|| 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_rightr   r   r   cidr_exclude\  s   
rV  c                 C   s&  t | } t |}|j| jk rg g | jgfS | j|jk r"| jgg g fS | j|jkr.g | gg fS g }g }| jd }| jj}| j}|j}|}|d||   }	|j|kr|j|	krc|t ||f|d |	}
n|t |	|f|d |}
|d7 }||kryn|
}|
d||   }	|j|ksP||g|ddd fS )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.
    rz   r   r  N)	r   r   r   rS   r   r   r|   rK   r  )rQ  rR  rS  rU  new_prefixlentarget_module_widthtarget_firstrK   i_loweri_uppermatchedr   r   r   rP  j  s:   



rP  c                 C   s   t | }ztt|}tt|}W n ty   tdw ||k r'|}|}n|}|}|D ]}t|}||k r9|}||kr?|}q-|j|jkrJtd|j}|j}	|j	}
|j
j}|	dkrt||
krt|	d8 }	|d||	 >  M }|	dkrt||
ks_t||	f|jd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!r   rz   r  )r   r   r   StopIterationrm   rK   r    r   r   r   r   r|   )rH  ip_addrs_iter	network_a	network_bmin_networkmax_networkr   r   ipnumr   lowest_ipnumr|   r   r   r   spanning_cidr  s<   
rf  rz   c                 c   s    t | } t |}| j|jkrtd| j}t|}|dkr"tdt| } t|}d}|dk r2d}| | }	 ||7 }|rD||ksCdS n||ksJdS t ||V  q7)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!r   zstep argument cannot be zeroFTN)ri   rK   r    ro   rm   )r   r&  r   rK   r   negative_stepr   r   r   r   r     s2   r   c                 C   s   g }t | } t |}| j|jg}t| |g}| jj}|j|d k r9t |d d |f| jd}t||d }| }|j|d krXt |d d |f| jd}|t||d 7 }|S |	| |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.
    r   rz   r  r   )
r   r   r   rf  r   r|   rK   rP  popr  )r   r&  	cidr_listiprange	cidr_spanr|   rR  r   r   r   r*    s    
r*  c                 C   sf   d}t |dstd|f t| } tdd |D D ]}| |v r$|}q|dur0|j|vr0 |S q|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!c                 S      g | ]}t |qS r   r   .0rS   r   r   r   
<listcomp>:      z*smallest_matching_cidr.<locals>.<listcomp>)r   r    ri   sortedr   r   r+  matchrS   r   r   r   smallest_matching_cidr'  s   
 rv  c                 C   sR   d}t |dstd|f t| } tdd |D D ]}| |v r&|} |S q|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   rl  c                 S   rm  r   rn  ro  r   r   r   rq  W  rr  z)largest_matching_cidr.<locals>.<listcomp>)r   r    ri   rs  rt  r   r   r   largest_matching_cidrD  s   
rw  c                 C   sl   g }t |dstd|f t| } tdd |D D ]}| |v r'|| q|r3|j|d vr3 |S q|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   rl  c                 S   rm  r   rn  ro  r   r   r   rq  r  rr  z&all_matching_cidrs.<locals>.<listcomp>rW  )r   r    ri   rs  r  r   )r   r+  matchesrS   r   r   r   all_matching_cidrs_  s   
 ry  z127.0.0.0/8z
10.0.0.0/8z100.64.0.0/10z172.16.0.0/12z192.0.0.0/24z192.168.0.0/16z198.18.0.0/15z	239.0.0.0z239.255.255.255z169.254.0.0/16z224.0.0.0/4z192.88.99.0/24z	0.0.0.0/8z192.0.2.0/24z240.0.0.0/4z198.51.100.0/24z203.0.113.0/24z233.252.0.0/24z	234.0.0.0z238.255.255.255z	225.0.0.0z231.255.255.255z::1zfc00::/7z	fec0::/10z	fe80::/10zff00::/8z	ff00::/12z::/8z0100::/8z0200::/7z0400::/6z0800::/5z1000::/4z4000::/3z6000::/3z8000::/3zA000::/3zC000::/3zE000::/4zF000::/5zF800::/6zFE00::/9)Fr   r"  )7rf   sys_sysnetaddr.corer   r   r   r   r   r   r   r	   r
   r   netaddr.strategyr   rE   r   rG   netaddr.compatr   r   r   r   r   r   objectr   ri   r   r   r   r  r.  r   r,  rV  rP  rf  r   r*  rv  rw  ry  rL   rO   rU   rF   	IPV4_6TO4rW   rM   rP   rV   rH   rX   r   r   r   r   <module>   s   0  U   <
eD    mT3<
./$
