HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //proc/thread-self/root/usr/lib/python3.9/site-packages/netaddr/ip/__pycache__/sets.cpython-39.pyc
a

��g�g�@sddZddlZddlmZmZmZmZmZm	Z	ddl
mZmZm
Z
dd�Zdd�ZGd	d
�d
e�ZdS)z2Set based operations for IP addresses and subnets.�N)�	IPNetwork�	IPAddress�IPRange�
cidr_merge�cidr_exclude�iprange_to_cidrs)�_sys_maxint�
_dict_keys�	_int_typec
Cs�|jj}||}|j|jkr4|�||j|jdf�|d7}|}|t|�kr�||}||vr^q�|jd|jkrpn|�||jd|jdf�|d7}|}q@|jd}|j}	||	kr�|�|||	f�|S)a�Calculate IPSet([supernet]) - IPSet(subnets).

    Assumptions: subnets is sorted, subnet_idx points to the first
    element in subnets that is a subnet of supernet.

    Results are appended to the ranges parameter as tuples of in format
    (version, first, last). Return value is the first subnet_idx that
    does not point to a subnet of supernet (or len(subnets) if all
    subsequents items are a subnet of supernet).
    �)�_module�version�first�append�len�last)
�supernet�subnetsZ
subnet_idxZrangesr
ZsubnetZprev_subnetZ
cur_subnetrr�r�3/usr/lib/python3.9/site-packages/netaddr/ip/sets.py�	_subtracts(
rccs�|sdS|d\}}}|dd�D]F\}}}||dkrF||krF|}q"t||�t||�fV|}|}|}q"t||�t||�fVdS)aqIterate over sorted_ranges, merging where possible

    Sorted ranges must be a sorted iterable of (version, first, last) tuples.
    Merging occurs for pairs like [(4, 10, 42), (4, 43, 100)] which is merged
    into (4, 10, 100), and leads to return value
    ( IPAddress(10, 4), IPAddress(100, 4) ), which is suitable input for the
    iprange_to_cidrs function.
    Nrr)r)�
sorted_rangesZcurrent_versionZ
current_startZcurrent_stopZnext_versionZ
next_startZ	next_stoprrr�_iter_merged_ranges8s 	��rc@sHeZdZdZdZdGdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZeZ
dd�Zdd�ZdHdd�ZdIdd�Zdd�Zdd �Zd!d"�ZdJd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�ZeZd/d0�Zd1d2�ZeZd3d4�ZeZ d5d6�Z!e!Z"d7d8�Z#e#Z$d9d:�Z%e%Z&d;d<�Z'e(d=d>��Z)d?d@�Z*e*Z+dAdB�Z,dCdD�Z-dEdF�Z.dS)K�IPSetz[
    Represents an unordered collection (set) of unique IP addresses and
    subnets.

    )�_cidrs�__weakref__NrcCs�t|t�r|jdi|_n�t|t�r@t�t|d|d�d�|_nrt|t�r^t�|�	�d�|_nTi|_|dur�g}|D]$}t|t
�r�t||d�}|�|�qtt
|�D]}d|j|<q�dS)aH
        Constructor.

        :param iterable: (optional) an iterable containing IP addresses,
            subnets or ranges.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the :class:`IPAddress` documentation
            for supported constant values.

        Tr���N��flags)�
isinstancer�cidrrr�dict�fromkeysrr�
iter_cidrsr
rrr��self�iterablerZ	mergeable�addrr rrr�__init__]s"

�

zIPSet.__init__cCstdd�|jD��S)z.:return: Pickled state of an ``IPSet`` object.cSsg|]}|���qSr)�__getstate__��.0r rrr�
<listcomp>~�z&IPSet.__getstate__.<locals>.<listcomp>)�tupler�r%rrrr)|szIPSet.__getstate__cCst�dd�|D�d�|_dS)zR
        :param state: data used to unpickle a pickled ``IPSet`` object.

        css$|]\}}}t||f|d�VqdS))r
N)r)r+�value�	prefixlenr
rrr�	<genexpr>�s�z%IPSet.__setstate__.<locals>.<genexpr>TN)r!r"r)r%�staterrr�__setstate__�s��zIPSet.__setstate__cCsd|j}|j}|j}|j|jjkrH|��D]}||jvr(|j|=dSq(n�g}|jD]h}|jj|ksR||krlqR|j}|j}	||kr�|	|kr�|�|�qR||krR|	|krR|j|=|r�J�dSqR|D]}
|j|
=q�|jj|j	}|j	dk�r`|j
|?d@}|�r|��}
n|��}
|
|jv�rdS|j|
=|j|=|j	d8_	|d7}|j
|?|>|_
d|j|<q�dS)a
        Same as compact(), but assume that added_network is the only change and
        that this IPSet was properly compacted before added_network was added.
        This allows to perform compaction much faster. added_network must
        already be present in self._cidrs.
        NrrT)
rrr
�
_prefixlenr�widthrrrr1�_value�previous�next)r%Z
added_networkZadded_firstZ
added_lastZ
added_versionZpotential_supernet�	to_remover rr�itemZshift_widthZthe_bit�	candidaterrr�_compact_single_network�sH




zIPSet._compact_single_networkcCst|j�}t�|d�|_dS)zR
        Compact internal list of `IPNetwork` objects using a CIDR merge.
        TN)rrr!r"�r%�cidrsrrr�compact�s
z
IPSet.compactcCstd��dS)z�
        Raises ``TypeError`` if this method is called.

        .. note:: IPSet objects are not hashable and cannot be used as             dictionary keys or as members of other sets.         zIP sets are unhashable!N)�	TypeErrorr/rrr�__hash__�szIPSet.__hash__cCs>t|�}||jvrdS|jr:|jd8_||jvrdSqdS)z�
        :param ip: An IP address or subnet.

        :return: ``True`` if IP address or subnet is a member of this IP set.
        TrF)rrr5)r%�iprrrr�__contains__�s


zIPSet.__contains__cCs
t|j�S)z9Return True if IPSet contains at least one IP, else False)�boolrr/rrr�__nonzero__�szIPSet.__nonzero__cCstjt|j��S)zP
        :return: an iterator over the IP addresses within this IP set.
        )�
_itertools�chain�sortedrr/rrr�__iter__�szIPSet.__iter__cCs
t|j�S)zU
        :return: an iterator over individual IP subnets within this IP set.
        �rIrr/rrrr#szIPSet.iter_cidrscCs�t|t�r<t�t|d|d�d�}|j�|�|��dSt|t�rN|j	}n$t|t
�rjtt||d��}nt|�}d|j|<|�|�dS)a8
        Adds an IP address or subnet or IPRange to this IP set. Has no effect if
        it is already present.

        Note that where possible the IP address or subnet is merged with other
        members of the set to form more concise CIDR blocks.

        :param addr: An IP address or subnet in either string or object form, or
            an IPRange object.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the :class:`IPAddress` documentation
            for supported constant values.

        rrTNr)
rrr!r"rr�updater@rr r
rr=)r%r'rZ	new_cidrsrrr�add	s
�


z	IPSet.addcCs�t|t�r4t|d|d�}|D]}|�|�q dSt|t�rLt||d�}nt|�}|�|�d}d}|jD]}||vrlt	||�}|}q�ql|dur�|j|=|D]}d|j|<q�dS)a	
        Removes an IP address or subnet or IPRange from this IP set. Does
        nothing if it is not already a member.

        Note that this method behaves more like discard() found in regular
        Python sets because it doesn't raise KeyError exceptions if the
        IP address or subnet is question does not exist. It doesn't make sense
        to fully emulate that behaviour here as IP sets contain groups of
        individual IP addresses as individual set members using IPNetwork
        objects.

        :param addr: An IP address or subnet, or an IPRange.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the :class:`IPAddress` documentation
            for supported constant values.

        rrNrT)
rrr�remover
rrrMrr)r%r'rr?r Z	remainderZ
matching_cidrrrrrN*s(




zIPSet.removecCs|j��dS)z�
        Removes and returns an arbitrary IP address or subnet from this IP
        set.

        :return: An IP address or subnet.
        r)r�popitemr/rrr�popbsz	IPSet.popcCs|�|�}|S)z�
        :param other: an IP set.

        :return: ``True`` if this IP set has no elements (IP addresses
            or subnets) in common with other. Intersection *must* be an
            empty set.
        )�intersection)r%�other�resultrrr�
isdisjointks
zIPSet.isdisjointcCs|��}|j�|j�|S)z':return: a shallow copy of this IP set.)�	__class__rrL)r%Zobj_copyrrr�copyvsz
IPSet.copycCs�t|t�r:t�dd�tt|j�t|j��D�d�|_dSt|ttf�rV|�	|�dSt
|d�shtd��g}|D]$}t|t�r�t
||d�}|�|�qptt|j�|�D]}d|j|<q�|��dS)az
        Update the contents of this IP set with the union of itself and
        other IP set.

        :param iterable: an iterable containing IP addresses, subnets or ranges.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the :class:`IPAddress` documentation
            for supported constant values.

        css|]
}|VqdS)Nr)r+rCrrrr2�r-zIPSet.update.<locals>.<genexpr>TNrJzan iterable was expected!r)rrr!r"rr	rrrrM�hasattrrAr
rrr@r$rrrrL|s*
��


zIPSet.updatecCs
i|_dS)z5Remove all IP addresses and subnets from this IP set.N�rr/rrr�clear�szIPSet.clearcCs*z|j|jkWSty$tYS0dS)z�
        :param other: an IP set

        :return: ``True`` if this IP set is equivalent to the ``other`` IP set,
            ``False`` otherwise.
        N�r�AttributeError�NotImplemented�r%rRrrr�__eq__�szIPSet.__eq__cCs*z|j|jkWSty$tYS0dS)z�
        :param other: an IP set

        :return: ``False`` if this IP set is equivalent to the ``other`` IP set,
            ``True`` otherwise.
        NrZr]rrr�__ne__�szIPSet.__ne__cCs$t|d�stS|j|jko"|�|�S)z�
        :param other: an IP set

        :return: ``True`` if this IP set is less than the ``other`` IP set,
            ``False`` otherwise.
        r)rWr\�size�issubsetr]rrr�__lt__�s
zIPSet.__lt__cCs|jD]}||vrdSqdS)z�
        :param other: an IP set.

        :return: ``True`` if every IP address and subnet in this IP set
            is found within ``other``.
        FTrX�r%rRr rrrra�s
zIPSet.issubsetcCs$t|d�stS|j|jko"|�|�S)z�
        :param other: an IP set.

        :return: ``True`` if this IP set is greater than the ``other`` IP set,
            ``False`` otherwise.
        r)rWr\r`�
issupersetr]rrr�__gt__�s
zIPSet.__gt__cCs,t|d�stS|jD]}||vrdSqdS)z�
        :param other: an IP set.

        :return: ``True`` if every IP address and subnet in other IP set
            is found within this one.
        rFT)rWr\rrcrrrrd�s

zIPSet.issupersetcCs|��}|�|�|S)z�
        :param other: an IP set.

        :return: the union of this IP set and another as a new IP set
            (combines IP addresses and subnets from both sets).
        )rVrL)r%rRZip_setrrr�union�s
zIPSet.unioncCs�i}t|j�}t|j�}d}d}t|�}t|�}||kr�||kr�||}	||}
|	|
krrd||	<|d7}|d7}q0|	|
vr�d||	<|d7}q0|
|	vr�d||
<|d7}q0|	|
kr�|d7}q0|d7}q0t�}||_|S)z�
        :param other: an IP set.

        :return: the intersection of this IP set and another as a new IP set.
            (IP addresses and subnets common to both sets).
        rTr)rIrrr)r%rR�result_cidrs�own_nets�
other_nets�own_idx�	other_idx�own_len�	other_len�own_cur�	other_currSrrrrQ�s4






zIPSet.intersectioncCs�g}t|j�}t|j�}d}d}t|�}t|�}||kr�||kr�||}	||}
|	|
krj|d7}|d7}q0|	|
vr�t|
|||�}|d7}q0|
|	vr�t|	|||�}|d7}q0|	|
kr�|�|	jj|	j|	jf�|d7}q0|�|
jj|
j|
jf�|d7}q0||k�r*||}	|�|	jj|	j|	jf�|d7}q�||k�r`||}
|�|
jj|
j|
jf�|d7}�q*t	�}t
|�D]*\}}
t||
�}|D]}d|j|<�q��qn|S)z�
        :param other: an IP set.

        :return: the symmetric difference of this IP set and another as a new
            IP set (all IP addresses and subnets that are in exactly one
            of the sets).
        rrT)rIrrrrrr
rrrrr)r%rR�
result_rangesrhrirjrkrlrmrnrorS�start�stopr?r rrr�symmetric_difference+s\





�

�


�


�
zIPSet.symmetric_differencecCsg}i}t|j�}t|j�}d}d}t|�}t|�}	||kr�||	kr�||}
||}|
|krn|d7}|d7}q4|
|vr�|d7}q4||
vr�t|
|||�}|d7}q4|
|kr�d||
<|d7}q4|d7}q4||kr�d|||<|d7}q�t|�D] \}}
t||
�D]}d||<q�q�t�}||_|S)z�
        :param other: an IP set.

        :return: the difference between this IP set and another as a new IP
            set (all IP addresses and subnets that are in this IP set but
            not found in the other.)
        rrT)rIrrrrrr)r%rRrprgrhrirjrkrlrmrnrorqrrr rSrrr�
differenceosD



�



zIPSet.differencecCs|j}|tkrtdt��|S)z�
        :return: the cardinality of this IP set (i.e. sum of individual IP             addresses). Raises ``IndexError`` if size > maxint (a Python             limitation). Use the .size property for subnets of any size.
        zUrange contains more than %d (sys.maxint) IP addresses!Use the .size property instead.)r`r�
IndexError)r%r`rrr�__len__�s��z
IPSet.__len__cCstdd�|jD��S)z�
        The cardinality of this IP set (based on the number of individual IP
        addresses including those implicitly defined in subnets).
        cSsg|]
}|j�qSr)r`r*rrrr,�r-zIPSet.size.<locals>.<listcomp>)�sumrr/rrrr`�sz
IPSet.sizecCsddd�t|j�D�S)z8:return: Python statement to create an equivalent objectz	IPSet(%r)cSsg|]}t|��qSr)�str)r+�crrrr,�r-z"IPSet.__repr__.<locals>.<listcomp>rKr/rrr�__repr__�szIPSet.__repr__cCsL|��}t|�dkrH|dd}|D]"}|d|kr:dS|dd}q$dS)z�
        Returns True if the members of the set form a contiguous IP
        address range (with no gaps), False otherwise.

        :return: ``True`` if the ``IPSet`` object is contiguous.
        rrFrT)r#r)r%r?r8r rrr�iscontiguous�szIPSet.iscontiguouscCs>|��r2|��}|sdSt|dd|dd�Std��dS)z�
        Generates an IPRange for this IPSet, if all its members
        form a single contiguous sequence.

        Raises ``ValueError`` if the set is not contiguous.

        :return: An ``IPRange`` for all IPs in the IPSet.
        NrrzIPSet is not contiguous)r{r#r�
ValueErrorr>rrr�iprange�s	z
IPSet.iprangeccs4dd�|��D�}t|�D]\}}t||�VqdS)z�Generate the merged IPRanges for this IPSet.

        In contrast to self.iprange(), this will work even when the IPSet is
        not contiguous. Adjacent IPRanges will be merged together, so you
        get the minimal number of IPRanges.
        cSsg|]}|jj|j|jf�qSr)rr
rrr*rrrr,�s�z'IPSet.iter_ipranges.<locals>.<listcomp>N)r#rr)r%rrqrrrrr�
iter_ipranges�s
�zIPSet.iter_ipranges)Nr)r)r)r)/�__name__�
__module__�__qualname__�__doc__�	__slots__r(r)r4r=r@rBrDrF�__bool__rJr#rMrNrPrTrVrLrYr^r_rbra�__le__rerd�__ge__rf�__or__rQ�__and__rs�__xor__rt�__sub__rv�propertyr`rz�__str__r{r}r~rrrrrUsX

J	
!
8	
#*B4

r)r��	itertoolsrGZ
netaddr.iprrrrrrZnetaddr.compatrr	r
rr�objectrrrrr�<module>s (