� c��j> � �H � d Z dZddlZdZdZ G d� de� Z G d� d e� Zd � Zd2d�Z d� Z d � Zd� Zd� Z d� Zd� Zd� Zd� Zd� Zd� Z G d� d� Zdaej, G d� de� � Zej, G d� de� � Z G d� d� Zee_ G d� d� Z G d � d!ee� Z G d"� d#e� Z G d$� d%ee� Z G d&� d'� Zee_ ee_ G d(� d)� Z G d*� d+e e� Z! G d,� d-e!� Z" G d.� d/e e� Z# G d0� d1� Z$e$e!_ e$e#_ y)3z�A fast, lightweight IPv4/IPv6 manipulation library in Python. This library is used to create/poke/manipulate IPv4 and IPv6 addresses and networks. z1.0� N� � c � � e Zd ZdZy)�AddressValueErrorz%A Value Error related to the address.N��__name__� __module__�__qualname__�__doc__� � �"/usr/lib64/python3.12/ipaddress.pyr r � � �/r r c � � e Zd ZdZy)�NetmaskValueErrorz%A Value Error related to the netmask.Nr r r r r r r r r c � � t | � S # t t f$ r Y nw xY w t | � S # t t f$ r Y nw xY wt | �d�� �)a� Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Address or IPv6Address object. Raises: ValueError: if the *address* passed isn't either a v4 or a v6 address z. does not appear to be an IPv4 or IPv6 address)�IPv4Addressr r �IPv6Address� ValueError��addresss r � ip_addressr sg � � ��7�#�#���0�1� �� �� ��7�#�#���0�1� �� �� ��{�"P�Q� R�R� � ��� . �A �A c � � t | |� S # t t f$ r Y nw xY w t | |� S # t t f$ r Y nw xY wt | �d�� �)a� Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP network. Either IPv4 or IPv6 networks may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Network or IPv6Network object. Raises: ValueError: if the string passed isn't either a v4 or a v6 address. Or if the network has host bits set. z. does not appear to be an IPv4 or IPv6 network)�IPv4Networkr r �IPv6Networkr )r �stricts r � ip_networkr 9 sk � � ��7�F�+�+���0�1� �� �� ��7�F�+�+���0�1� �� �� ��{�"P�Q� R�Rs � � � �0 �A�Ac � � t | � S # t t f$ r Y nw xY w t | � S # t t f$ r Y nw xY wt | �d�� �)ag Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Interface or IPv6Interface object. Raises: ValueError: if the string passed isn't either a v4 or a v6 address. Notes: The IPv?Interface classes describe an Address on a particular Network, so they're basically a combination of both the Address and Network classes. z0 does not appear to be an IPv4 or IPv6 interface)� IPv4Interfacer r � IPv6Interfacer r s r �ip_interfacer" V sg � �* ��W�%�%���0�1� �� �� ��W�%�%���0�1� �� �� ��{�"R�S� T�Tr c �V � | j d� S # t $ r t d� �w xY w)a` Represent an address as 4 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv4 IP address. Returns: The integer address packed as 4 bytes in network (big-endian) order. Raises: ValueError: If the integer is negative or too large to be an IPv4 IP address. � z&Address negative or too large for IPv4��to_bytes� OverflowErrorr r s r �v4_int_to_packedr( x s6 � �C�����"�"��� C��A�B�B�C�� � �(c �V � | j d� S # t $ r t d� �w xY w)z�Represent an address as 16 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv6 IP address. Returns: The integer address packed as 16 bytes in network (big-endian) order. � z&Address negative or too large for IPv6r% r s r �v6_int_to_packedr, � s6 � �C�����#�#��� C��A�B�B�C�r) c �r � t | � j d� }t |� dkD rt d| ��� �|S )zAHelper to split the netmask and raise AddressValueError if needed�/� zOnly one '/' permitted in )�str�split�lenr )r �addrs r �_split_optional_netmaskr4 � s9 � ��w�<���c�"�D� �4�y�1�}��"<�W�K� H�I�I��Kr c # � K � t | � }t |� x}}|D ]( }|j |j dz k7 r||f�� |}|}�* ||f�� y�w)z�Find a sequence of sorted deduplicated IPv#Address. Args: addresses: a list of IPv#Address objects. Yields: A tuple containing the first and last IP addresses in the sequence. � N)�iter�next�_ip)� addresses�it�first�last�ips r �_find_address_ranger? � s] � �� � �i��B���8��E�D��� �6�6�T�X�X��\�!���+���E��� � ��+��s �A Ac �R � | dk( r|S t || | dz z j � � S )z�Count the number of zero bits on the right hand side. Args: number: an integer. bits: maximum number of bits to count. Returns: The number of zero bits on the right hand side of the number. r r6 )�min� bit_length)�number�bitss r �_count_righthand_zero_bitsrE � s1 � � ��{����t�v�g����*�6�6�8�9�9r c # �V K � t | t � rt |t � st d� �| j |j k7 rt | �d|�d�� �| |kD rt d� �| j dk( rt }n!| j dk( rt }nt d� �| j }| j }|j }||k r`t t ||� ||z dz j � dz � } ||||z f� }|�� |d|z z }|dz |j k( ry ||k r�_y y �w) a� Summarize a network range given the first and last IP addresses. Example: >>> list(summarize_address_range(IPv4Address('192.0.2.0'), ... IPv4Address('192.0.2.130'))) ... #doctest: +NORMALIZE_WHITESPACE [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), IPv4Network('192.0.2.130/32')] Args: first: the first IPv4Address or IPv6Address in the range. last: the last IPv4Address or IPv6Address in the range. Returns: An iterator of the summarized IPv(4|6) network objects. Raise: TypeError: If the first and last objects are not IP addresses. If the first and last objects are not the same version. ValueError: If the last object is not greater than the first. If the version of the first address is not 4 or 6. z1first and last must be IP addresses, not networks� and � are not of the same versionz*last IP address must be greater than firstr$ � zunknown IP versionr6 N) � isinstance�_BaseAddress� TypeError�versionr r r �_max_prefixlenr9 rA rE rB � _ALL_ONES)r<