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: //lib/python3.9/site-packages/netaddr/strategy/__pycache__/ipv4.cpython-39.opt-1.pyc
a

��gP �@s�dZddlZddlZddlmZejdvr<ddl	m
ZmZnddlm
ZmZddl
mZmZmZddlmZmZmZmZmZmZmZddl m!Z!d	Z"d
Z#dZ$dZ%eZ&d
Z'dZ(dZ)de"dZ*e"e#Z+de#dZ,e-dd�e.de"d�D��Z/e-dd�e.de"d�D��Z0e-dd�e.de"d�D��Z1e-dd�e.de"d�D��Z2d7dd�Z3d8dd�Z4d9dd�Z5dd�Z6dd �Z7d!d"�Z8d#d$�Zd%d&�Z9d'd(�Z:d)d*�Zd+d,�Zd:d-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z;dS);zIPv4 address logic.�N)�	inet_aton)�win32�cygwin)�	inet_pton�AF_INET)�AddrFormatError�ZEROFILL�	INET_PTON)�valid_words�
valid_bits�bits_to_int�int_to_bits�	valid_bin�
int_to_bin�
bin_to_int)�	_str_type� ��%d�.ZIPv4��
��cCs$g|]}|tdt|dAf�qS�rr��max_int�width��.0�i�r!�9/usr/lib/python3.9/site-packages/netaddr/strategy/ipv4.py�
<listcomp>B�r#cCs$g|]}tdt|dA|f�qSrrrr!r!r"r#Fr$cCs g|]}|dt|df�qSr�rrr!r!r"r#Jr$cCs g|]}dt|d|f�qSrr%rr!r!r"r#Nr$cCsr|dkrtd��d}|t@r6d�dd�|�d�D��}z |t@rLtt|�nt|�Wntyld}Yn0|S)a�
    :param addr: An IPv4 address in presentation (string) format.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Supported constants are INET_PTON and ZEROFILL. See the
        :class:`IPAddress` documentation for details.

    .. versionchanged:: 0.10.1
        ``flags`` is scheduled to default to :data:`INET_PTON` instead of :data:`INET_ATON`
        in the future.

    :return: ``True`` if IPv4 address is valid, ``False`` otherwise.
    �z Empty strings are not supported!TrcSsg|]}dt|��qS�r��intrr!r!r"r#er$zvalid_str.<locals>.<listcomp>F)	rr�join�splitr	�
_inet_ptonr�
_inet_aton�	Exception)�addr�flagsZvalidityr!r!r"�	valid_strQs
r1cCs�|t@r"d�dd�|�d�D��}z:|t@rDt�dtt|��dWSt�dt|��dWSWn t	y|t
d|f��Yn0dS)a_
    :param addr: An IPv4 dotted decimal address in string form.

    :param flags: decides which rules are applied to the interpretation of the
        addr value. Supported constants are INET_PTON and ZEROFILL. See the
        :class:`IPAddress` documentation for details.

    :return: The equivalent unsigned integer for a given IPv4 address.
    rcSsg|]}dt|��qSr'r(rr!r!r"r#}r$zstr_to_int.<locals>.<listcomp>�>Irz&%r is not a valid IPv4 address string!N)rr*r+r	�_struct�unpackr,rr-r.r)r/r0r!r!r"�
str_to_intrs
r5cCsRd|krtkr@nn(d|d?|d?d@|d?d@|d@fStd|f��dS)	z�
    :param int_val: An unsigned integer.

    :param dialect: (unused) Any value passed in is ignored.

    :return: The IPv4 presentation (string) format address equivalent to the
        unsigned integer provided.
    rz%d.%d.%d.%d���rz*%r is not a valid 32-bit unsigned integer!N�r�
ValueError)�int_valZdialectr!r!r"�
int_to_str�s	

�r<cCs2dd�t|�D�}|��|�gd��d�|�S)z�
    :param int_val: An unsigned integer.

    :return: The reverse DNS lookup for an IPv4 address in network byte
        order integer form.
    cSsg|]}d|�qSr'r!rr!r!r"r#�r$zint_to_arpa.<locals>.<listcomp>)zin-addrZarpar&r)�int_to_words�reverse�extendr*)r;�wordsr!r!r"�int_to_arpa�srAcCst�d|�S)z�
    :param int_val: the integer to be packed.

    :return: a packed string that is equivalent to value represented by an
    unsigned integer.
    r2)r3�pack�r;r!r!r"�
int_to_packed�srDcCst�d|�dS)a
    :param packed_int: a packed string containing an unsigned integer.
        It is assumed that string is packed in network byte order.

    :return: An unsigned integer equivalent to value of network address
        represented by packed binary string.
    r2r)r3r4)Z
packed_intr!r!r"�
packed_to_int�srEcCst|tt�S�N)�_valid_words�	word_size�	num_words�r@r!r!r"r
�sr
cCsHd|krtks$ntd|f��|d?|d?d@|d?d@|d@fS)z�
    :param int_val: An unsigned integer.

    :return: An integer word (octet) sequence that is equivalent to value
        represented by an unsigned integer.
    rz>%r is not a valid integer value supported bythis address type!r6r7r8rr9rCr!r!r"r=�s�

�r=cCs4t|�std|f��t�dtjdg|�R��dS)z�
    :param words: A list or tuple containing integer octets.

    :return: An unsigned integer that is equivalent to value represented
        by word (octet) sequence.
    z1%r is not a valid octet list for an IPv4 address!r2Z4Br)r
r:r3r4rBrJr!r!r"�words_to_int�srKcCst|tt�SrF)�_valid_bitsr�word_sep��bitsr!r!r"r�srcCst|tt�SrF)�_bits_to_intrrMrNr!r!r"r�srcCs |durt�d}t|tt|�S)NrM)�globals�_int_to_bitsrHrI)r;rMr!r!r"r
�s
r
cCs
t|t�SrF)�
_valid_binr�Zbin_valr!r!r"r�srcCs
t|t�SrF)�_int_to_binrrCr!r!r"r�srcCs
t|t�SrF)�_bin_to_intrrTr!r!r"r�srcCs�g}td|�}t|t�r�d|vr&|�z0d|vrFdd�|�d�D�}ndt|�g}Wntyl|�Yn0dt|�kr�dkr�nn"tdt|��D]}|�d	�q�n|�|s�|�d
t	|�S)z�
    Expands a partial IPv4 address into a full 4-octet version.

    :param addr: an partial or abbreviated IPv4 address

    :return: an expanded IP address in presentation format (x.x.x.x)

    z!invalid partial IPv4 address: %r!�:rcSsg|]}dt|��qSr'r()r�or!r!r"r#r$z*expand_partial_address.<locals>.<listcomp>rrr�0z%s.%s.%s.%s)
r�
isinstancerr+r)r:�len�range�append�tuple)r/�tokens�errorr r!r!r"�expand_partial_address�s$	

ra)r)r)N)N)<�__doc__�sys�_sys�structr3Zsocketrr-�platformZnetaddr.fbsocketrr,rZnetaddr.corerrr	Znetaddr.strategyr
rGrrLrrPr
rRrrSrrUrrVZnetaddr.compatrrrHZword_fmtrMZfamilyZfamily_name�versionZ	word_baserrIZmax_word�dictr\Zprefix_to_netmaskZnetmask_to_prefixZprefix_to_hostmaskZhostmask_to_prefixr1r5r<rArDrEr=rKrar!r!r!r"�<module>s`
$����
!