%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/netaddr/ip/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/netaddr/ip/__pycache__/sets.cpython-312.pyc

�

���^�g��f�dZddlZddlmZmZmZmZmZm	Z	ddl
mZmZm
Z
d�Zd�ZGd�de�Zy)	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�,�|jj}||}|j|jkDr+|j||j|jdz
f�|dz
}|}|t	|�krk||}||vrna|j
dz|jk(rn.|j||j
dz|jdz
f�|dz
}|}|t	|�kr�k|j
dz}|j
}	||	kr|j|||	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�subnets�
subnet_idx�rangesr�subnet�prev_subnet�
cur_subnetrrs
          �1/usr/lib/python3/dist-packages/netaddr/ip/sets.py�	_subtractrs�����&�&�G�
�Z�
 �F�
�|�|�h�n�n�$��
�
�w�������q�0@�A�B��!�O�J��K�
�s�7�|�
#��Z�(�
��X�%�����a��:�#3�#3�3���M�M�7�K�$4�$4�q�$8�*�:J�:J�Q�:N�O�P��a��
� ���s�7�|�
#�
���q� �E��=�=�D���}��
�
�w��t�,�-���c#��K�|sy|d\}}}|ddD]6\}}}||dzk(r||k(r|}�t||�t||�f��|}|}|}�8t||�t||�f��y�w)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_ranges�current_version�
current_start�current_stop�next_version�
next_start�	next_stops       r�_iter_merged_rangesr&8s�������3@��3C�0�O�]�L�/<�Q�R�/@�
'�+��j�)����)�)�l�o�.M�$�L�����8����7�9�	9�"�
� ��&��
'��]�O�4��\�?�3�5�5�s�A&A(c��eZdZdZdZd%d�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�ZeZ
d�Zd
�Zd&d�Zd&d�Zd�Zd�Zd�Zd&d�Zd�Zd�Zd�Zd�Zd�ZeZd�Zd�ZeZd�ZeZ d�Z!e!Z"d�Z#e#Z$d�Z%e%Z&d�Z'e(d ��Z)d!�Z*e*Z+d"�Z,d#�Z-d$�Z.y)'�IPSetz[
    Represents an unordered collection (set) of unique IP addresses and
    subnets.

    )�_cidrs�__weakref__Nc��t|t�r|jdi|_yt|t�r,t
j
t|d|d�d�|_yt|t�r*t
j
|j�d�|_yi|_|�Wg}|D]0}t|t�r
t||��}|j|��2t|�D]}d|j|<�yy)aL
        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 netaddr.core namespace documentation
            for supported constant values.

        Tr���N��flags)�
isinstancer�cidrr)r�dict�fromkeysrr(�
iter_cidrsrrrr��self�iterabler.�	mergeable�addrr0s      r�__init__zIPSet.__init__]s����h�	�*�#�=�=�$�/�D�K�
��'�
*��-�-� ��!��h�r�l�;�T�C�D�K�
��%�
(��-�-��(;�(;�(=�t�D�D�K��D�K��#��	�$�+�D�!�$�	�2�(��U�;���$�$�T�*�+�
'�y�1�-�D�(,�D�K�K��%�-�$rc�n�t|jD�cgc]}|j���c}�Scc}w)z.:return: Pickled state of an ``IPSet`` object.)�tupler)�__getstate__�r5r0s  rr<zIPSet.__getstate__|s(���d�k�k�B�d�d�'�'�)�B�C�C��Bs�2c�H�tjd�|D�d�|_y)zR
        :param state: data used to unpickle a pickled ``IPSet`` object.

        c3�BK�|]\}}}t||f|�����y�w))rN)r)�.0�value�	prefixlenrs    r�	<genexpr>z%IPSet.__setstate__.<locals>.<genexpr>�s-����
5�*��	�7���y�)�7�
;�
;�
5�s�TN)r1r2r))r5�states  r�__setstate__zIPSet.__setstate__�s$��
�m�m�
5�.3�
5����rc���|j}|j}|j}|j|jj
k(r3|j
�D]}||jvs�|j|=yn�g}|jD]s}|jj|k7s||k(r�"|j}|j}	||k\r|	|kr|j|��V||ks�\|	|k\s�b|j|=|rJ�y|D]}
|j|
=�|jj
|jz
}|jdk7r�|j|z	dz}|r|j�}
n|j�}
|
|jvry|j|
=|j|=|xjdzc_	|dz
}|j|z	|z|_
d|j|<|jdk7r��yy)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.
        Nrr
T)
rrr�
_prefixlenr�widthrr)rrB�_value�previous�next)r5�
added_network�added_first�
added_last�
added_version�potential_supernet�	to_remover0rr�item�shift_width�the_bit�	candidates              r�_compact_single_networkzIPSet._compact_single_network�s���$�)�)��"�'�'�
�%�-�-�
��#�#�}�'<�'<�'B�'B�B�'4�&<�&<�&>�
�"�%����4����M�2��
��I����
���L�L�(�(�M�9�T�]�=R���
�
���y�y���K�'�D�J�,>��$�$�T�*��k�)�d�j�.@����M�2�!*�*�M��
� "�
&���K�K��%�
&�$�+�+�1�1�M�4K�4K�K���%�%��*�$�+�+�{�:�a�?�G��)�2�2�4�	�)�.�.�0�	�����+�����I�&����M�*��#�#�q�(�#�
�1��K�$1�$8�$8�K�$G�K�#W�M� �)-�D�K�K�
�&�)�%�%��*rc�d�t|j�}tj|d�|_y)zR
        Compact internal list of `IPNetwork` objects using a CIDR merge.
        TN)rr)r1r2�r5�cidrss  r�compactz
IPSet.compact�s$���4�;�;�'���m�m�E�4�0��rc��td��)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!)�	TypeError�r5s r�__hash__zIPSet.__hash__�s���1�2�2rc��t|�}||jvry|jr1|xjdzc_||jvry|jr�1y)z�
        :param ip: An IP address or subnet.

        :return: ``True`` if IP address or subnet is a member of this IP set.
        Tr
F)rr)rG)r5�iprs   r�__contains__zIPSet.__contains__�sU���R�=���t�{�{�"���!�!����1�$���4�;�;�&���!�!�rc�,�t|j�S)z9Return True if IPSet contains at least one IP, else False)�boolr)r]s r�__nonzero__zIPSet.__nonzero__�s���D�K�K� � rc�L�tjt|j��S)zP
        :return: an iterator over the IP addresses within this IP set.
        )�
_itertools�chain�sortedr)r]s r�__iter__zIPSet.__iter__�s���������!4�5�5rc�,�t|j�S)zU
        :return: an iterator over individual IP subnets within this IP set.
        )rhr)r]s rr3zIPSet.iter_cidrss���d�k�k�"�"rc��t|t�rRtjt	|d|d�d�}|j
j
|�|j�yt|t�r
|j}n2t|t�rtt||���}nt|�}d|j
|<|j|�y)a<
        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 netaddr.core namespace documentation
            for supported constant values.

        rr,TNr-)
r/rr1r2rr)�updaterZrr0rrrV)r5r8r.�	new_cidrss    r�addz	IPSet.add	s��� �d�G�$��
�
� ��a��$�r�(�3�T�;�I��K�K���y�)��L�L�N���d�I�&��9�9�D�
��i�
(��Y�t�5�9�:�D��T�?�D� ����D���$�$�T�*rc��t|t�r+t|d|d�}|D]}|j|��yt|t�rt||��}nt
|�}|j|�d}d}|jD]}||vs�t||�}|}n|�$|j|=|D]}d|j|<�yy)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 netaddr.core namespace documentation
            for supported constant values.

        rr,Nr-T)
r/rr�removerrrrnr)r)r5r8r.rYr0�	remainder�
matching_cidrs       rrpzIPSet.remove*s���&�d�G�$�$�T�!�W�d�2�h�7�E��
"�����D�!�
"���d�I�&��T��/�D��T�?�D�	
������	��
��K�K�	�D��t�|�(��t�4�	� $�
��		�� ����M�*�!�
)��$(����D�!�
)�!rc�<�|jj�dS)z�
        Removes and returns an arbitrary IP address or subnet from this IP
        set.

        :return: An IP address or subnet.
        r)r)�popitemr]s r�popz	IPSet.popbs���{�{�"�"�$�Q�'�'rc�*�|j|�}|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)r5�other�results   r�
isdisjointzIPSet.isdisjointks���"�"�5�)���z�rc�p�|j�}|jj|j�|S)z':return: a shallow copy of this IP set.)�	__class__r)rl)r5�obj_copys  r�copyz
IPSet.copyvs)���>�>�#�������t�{�{�+��rc	�D�t|t�rUtjd�t	t|j�t|j�z�D�d�|_yt|ttf�r|j|�yt|d�std��g}|D]0}t|t�r
t||��}|j|��2t	t|j�|z�D]}d|j|<�|j�y)a~
        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 netaddr.core namespace documentation
            for supported constant values.

        c3� K�|]}|���y�w)N�)r@r`s  rrCzIPSet.update.<locals>.<genexpr>�s����I���I�s�TNrizan iterable was expected!r-)r/r(r1r2rr
r)rrrn�hasattrr\rrrrZr4s      rrlzIPSet.update|s���h��&��-�-�I�j��D�K�K�)@�+5�h�o�o�+F�*G�H�I�JN�P�D�K�
�
��9�g�"6�
7��H�H�X����x��,��7�8�8��	��	#�D��$�	�*� ��U�3�����T�"�	#�
�z�$�+�+�6��B�C�	%�D� $�D�K�K���	%�	
���rc��i|_y)z5Remove all IP addresses and subnets from this IP set.N�r)r]s r�clearzIPSet.clear�s	����rc�`�	|j|jk(S#t$r	tcYSwxYw)z�
        :param other: an IP set

        :return: ``True`` if this IP set is equivalent to the ``other`` IP set,
            ``False`` otherwise.
        �r)�AttributeError�NotImplemented�r5rxs  r�__eq__zIPSet.__eq__��/��	"��;�;�%�,�,�.�.���	"�!�!�	"����-�-c�`�	|j|jk7S#t$r	tcYSwxYw)z�
        :param other: an IP set

        :return: ``False`` if this IP set is equivalent to the ``other`` IP set,
            ``True`` otherwise.
        r�r�s  r�__ne__zIPSet.__ne__�r�r�c�~�t|d�stS|j|jkxr|j|�S)z�
        :param other: an IP set

        :return: ``True`` if this IP set is less than the ``other`` IP set,
            ``False`` otherwise.
        r))r�r��size�issubsetr�s  r�__lt__zIPSet.__lt__�s5���u�h�'�!�!��y�y�5�:�:�%�>�$�-�-��*>�>rc�2�|jD]}||vs�yy)z�
        :param other: an IP set.

        :return: ``True`` if every IP address and subnet in this IP set
            is found within ``other``.
        FTr��r5rxr0s   rr�zIPSet.issubset�s'���K�K�	�D��5� ��	�rc�~�t|d�stS|j|jkDxr|j|�S)z�
        :param other: an IP set.

        :return: ``True`` if this IP set is greater than the ``other`` IP set,
            ``False`` otherwise.
        r))r�r�r��
issupersetr�s  r�__gt__zIPSet.__gt__�s5���u�h�'�!�!��y�y�5�:�:�%�@�$�/�/�%�*@�@rc�V�t|d�stS|jD]}||vs�yy)z�
        :param other: an IP set.

        :return: ``True`` if every IP address and subnet in other IP set
            is found within this one.
        r)FT)r�r�r)r�s   rr�zIPSet.issuperset�s7���u�h�'�!�!��L�L�	�D��4���	�rc�H�|j�}|j|�|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).
        )r~rl)r5rx�ip_sets   r�unionzIPSet.union�s ��������
�
�e���
rc�x�i}t|j�}t|j�}d}d}t|�}t|�}||kr]||krX||}	||}
|	|
k(rd||	<|dz
}|dz
}n.|	|
vrd||	<|dz
}n|
|	vrd||
<|dz
}n|	|
kr|dz
}n|dz
}||kr||kr�Xt�}||_|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
)rhr)rr()r5rx�result_cidrs�own_nets�
other_nets�own_idx�	other_idx�own_len�	other_len�own_cur�	other_currys            rrwzIPSet.intersection�s�����$�+�+�&���E�L�L�)�
����	��h�-���
�O�	����I�	�$9��w�'�G�"�9�-�I��)�#�(,��W�%��1����Q��	��I�%�(,��W�%��1����g�%�*.��Y�'��Q��	��Y�&��q�L�G���N�I�'���I�	�$9�.���$��
��
rc�"�g}t|j�}t|j�}d}d}t|�}t|�}||kr�||kr�||}	||}
|	|
k(r|dz
}|dz
}n�|	|
vrt|
|||�}|dz
}n�|
|	vrt|	|||�}|dz
}n�|	|
krB|j	|	j
j|	j|	jf�|dz
}nA|j	|
j
j|
j|
jf�|dz
}||kr||kr��||krL||}	|j	|	j
j|	j|	jf�|dz
}||kr�L||krL||}
|j	|
j
j|
j|
jf�|dz
}||kr�Lt�}t|�D]'\}}
t||
�}|D]}d|j|<��)|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).
        rr
T)rhr)rrrrrrrr(r&r)r5rx�
result_rangesr�r�r�r�r�r�r�r�ry�start�stoprYr0s                r�symmetric_differencezIPSet.symmetric_difference+sG���
��$�+�+�&���E�L�L�)�
����	��h�-���
�O�	����I�	�$9��w�'�G�"�9�-�I��)�#��1����Q��	��I�%�#�I�x��-�P���Q��	��g�%�%�g�z�9�m�T�	��1����Y�&�!�(�(�'�/�/�*A�*A�*1�-�-����*G�H��q�L�G�!�(�(�)�*;�*;�*C�*C�*3�/�/�9�>�>�*K�L���N�I�-���I�	�$9�4����w�'�G�� � �'�/�/�"9�"9�")�-�-����"?�
@��q�L�G�	����)�#�"�9�-�I�� � �)�"3�"3�";�";�"+�/�/�9�>�>�"C�
D���N�I�	�)�#����.�}�=�	+�K�E�4�$�U�D�1�E��
+��&*��
�
�d�#�
+�	+��
rc��g}i}t|j�}t|j�}d}d}t|�}t|�}	||kra||	kr\||}
||}|
|k(r|dz
}|dz
}n7|
|vr|dz
}n-||
vrt|
|||�}|dz
}n|
|krd||
<|dz
}n|dz
}||kr||	kr�\||krd|||<|dz
}||kr�t	|�D]\}}
t||
�D]}d||<�	�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.)
        rr
T)rhr)rrr&rr()r5rxr�r�r�r�r�r�r�r�r�r�r�r�r0rys                r�
differencezIPSet.differenceosj���
����$�+�+�&���E�L�L�)�
����	��h�-���
�O�	����I�	�$9��w�'�G�"�9�-�I��)�#��1����Q��	��I�%��1����g�%�%�g�z�9�&3�5�	��1����Y�&�,0�L��)��q�L�G���N�I�'���I�	�$9�.���.2�L��'�*�+��q�L�G����/�}�=�	*�K�E�4�(���5�
*��%)��T�"�
*�	*����$��
��
rc�T�|j}|tkDrtdtz��|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)r5r�s  r�__len__z
IPSet.__len__�s9���y�y���+���2�4?�@�A�
A��rc�f�t|jD�cgc]}|j��c}�Scc}w)z�
        The cardinality of this IP set (based on the number of individual IP
        addresses including those implicitly defined in subnets).
        )�sumr)r�r=s  rr�z
IPSet.size�s%���$�+�+�6�$�D�I�I�6�7�7��6s�.c�j�dt|j�D�cgc]
}t|���c}zScc}w)z8:return: Python statement to create an equivalent objectz	IPSet(%r))rhr)�str)r5�cs  r�__repr__zIPSet.__repr__�s(���f�T�[�[�.A�B��c�!�f�B�B�B��Bs�0c��|j�}t|�dkDr!|dd}|D]}|d|k7ry|ddz}�y)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.
        r
rFr,T)r3r)r5rYrJr0s    r�iscontiguouszIPSet.iscontiguous�sX�����!���u�:��>��Q�x��{�H��
(����7�h�&� ���8�a�<��
(�rc��|j�r+|j�}|syt|dd|dd�Std��)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.
        Nrr,zIPSet is not contiguous)r�r3r�
ValueErrorrXs  r�iprangez
IPSet.iprange�sK�������O�O�%�E����5��8�A�;��b�	�"�
�6�6��6�7�7rc#��K�|j�D�cgc]/}|jj|j|jf��1}}t|�D]\}}t
||����ycc}w�w)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.
        N)r3rrrrr&r)r5r0rr�r�s     r�
iter_iprangeszIPSet.iter_ipranges�sq����"&���!2�4���,�,�.�.��
�
�D�I�I�F�4�
�4�/�}�=�	'�K�E�4��%��&�&�	'��4�s�A2�4A-�	)A2)Nr)r)/�__name__�
__module__�__qualname__�__doc__�	__slots__r9r<rErVrZr^rard�__bool__rir3rnrprurzr~rlr�r�r�r�r��__le__r�r��__ge__r��__or__rw�__and__r��__xor__r��__sub__r��propertyr�r��__str__r�r�r�r�rrr(r(Us���
*�I�-�>D��H.�T1�3��&!��H�6�#�+�B4)�p(�	��!�F�
"�
"�
?�
��F�
A�
��F�	��F�(�T�G�@�D#�G�2�h�G���8��8�C��G�� 8�"'rr()r��	itertoolsrf�
netaddr.iprrrrrr�netaddr.compatr	r
rrr&�objectr(r�rr�<module>r�s8��9��$�$�>�=�%�P5�:W
'�F�W
'r

Zerion Mini Shell 1.0