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__/__init__.cpython-39.pyc
a

��g7�@s|dZddlZddlmZmZdd�Ze�Zdd�Zdd	�Z	d
d�Z
dd
d�Zddd�Zddd�Z
dd�Zdd�Zdd�ZdS)z)
Shared logic for various address types.
�N)�_range�_is_strcCs^g}tddd�}td�D]@}ddg}|D]}d|d@||<|dL}q*|�d�|��q|S)	z�
    :return: A 256 element list containing 8-bit binary digit strings. The
        list index value is equivalent to its bit string value.
    ������NZ01��)r�range�append�join)�lookupZ
bits_per_byte�num�bits�i�r�=/usr/lib/python3.9/site-packages/netaddr/strategy/__init__.py�
bytes_to_bitss

rcCsTt|d�sdSt|�|krdSd|d}|D] }d|krF|ks.ndSq.dS)a6
    :param words: A sequence of unsigned integer word values.

    :param word_size: Width (in bits) of each unsigned integer word value.

    :param num_words: Number of unsigned integer words expected.

    :return: ``True`` if word sequence is valid for this address type,
        ``False`` otherwise.
    �__iter__F�rrT)�hasattr�len)�words�	word_size�	num_words�max_wordrrrr�valid_words!s
rcCs~d||d}d|kr$|ks6ntdt|���d|d}g}t|�D]"}||@}|�t|��||L}qNtt|��S)aJ
    :param int_val: Unsigned integer to be divided into words of equal size.

    :param word_size: Width (in bits) of each unsigned integer word value.

    :param num_words: Number of unsigned integer words expected.

    :return: A tuple contain unsigned integer word values split according
        to provided arguments.
    rrrzinteger out of bounds: %r!)�
IndexError�hexr
r�int�tuple�reversed)�int_valrr�max_intrr�_�wordrrr�int_to_words;s
r&cCsPt|||�std|f��d}tt|��D] \}}|}|||>}||B}q*|S)a5
    :param words: A sequence of unsigned integer word values.

    :param word_size: Width (in bits) of each unsigned integer word value.

    :param num_words: Number of unsigned integer words expected.

    :return: An unsigned integer that is equivalent to value represented
        by word sequence.
    z"invalid integer word sequence: %r!r)r�
ValueError�	enumerater!)rrrr"rrr%rrr�words_to_intVs
r)r	cCs|t|�sdS|dkr |�|d�}t|�|kr0dSd|d}z(dt|d�krX|krbnnWdSWntyvYn0dS)al
    :param bits: A network address in a delimited binary string format.

    :param width: Maximum width (in bits) of a network address (excluding
        delimiters).

    :param word_sep: (optional) character or string used to delimit word
        groups (default: '', no separator).

    :return: ``True`` if network address is valid, ``False`` otherwise.
    Fr	rrrT)r�replacerrr')r�width�word_sepr#rrr�
valid_bitsms
r-cCs8t|||�std|f��|dkr.|�|d�}t|d�S)a�
    :param bits: A network address in a delimited binary string format.

    :param width: Maximum width (in bits) of a network address (excluding
        delimiters).

    :param word_sep: (optional) character or string used to delimit word
        groups (default: '', no separator).

    :return: An unsigned integer that is equivalent to value represented
        by network address in readable binary form.
    z#invalid readable binary string: %r!r	r)r-r'r*r)rr+r,rrr�bits_to_int�s

r.cCs�g}t|||�D]b}g}|r8|�t|d@�|dL}q|��d�|�pPd|}d|||d�}|�|�q|dkr�t|�s�td|f��|�|�S)a�
    :param int_val: An unsigned integer.

    :param word_size: Width (in bits) of each unsigned integer word value.

    :param num_words: Number of unsigned integer words expected.

    :param word_sep: (optional) character or string used to delimit word
        groups (default: '', no separator).

    :return: A network address in a delimited binary string format that is
        equivalent in value to unsigned integer.
    �rr	�0Nz#word separator is not a string: %r!)r&r�
BYTES_TO_BITS�reverserrr')r"rrr,Z	bit_wordsr%rZbit_strrrr�int_to_bits�s
r3cCs�t|�sdS|�d�sdS|�dd�}t|�|kr6dSd|d}z(dt|d�kr^|krhnnWdSWnty|Yn0dS)a
    :param bin_val: A network address in Python's binary representation format
        ('0bxxx').

    :param width: Maximum width (in bits) of a network address (excluding
        delimiters).

    :return: ``True`` if network address is valid, ``False`` otherwise.
    F�0br	rrrT)r�
startswithr*rrr')�bin_valr+r#rrr�	valid_bin�s


r7cCs�g}zt|�}Wn^tyn|}|dkrJ|d@}|�t|�|dL}q"|��dt�ddd�|��}Yn0t|dd	��|kr�t	d
|f��|S)z�
    :param int_val: An unsigned integer.

    :param width: Maximum allowed width (in bits) of a unsigned integer.

    :return: Equivalent string value in Python's binary representation format
        ('0bxxx').
    rr/rr4z
^[0]+([01]+)$z\1r	rNz binary string out of bounds: %s!)
�bin�	NameErrorrr1r2�_re�subrrr)r"r+Z
bin_tokensr6rr%rrr�
int_to_bin�s	
r<cCs*t||�std|f��t|�dd�d�S)a9
    :param bin_val: A string containing an unsigned integer in Python's binary
        representation format ('0bxxx').

    :param width: Maximum allowed width (in bits) of a unsigned integer.

    :return: An unsigned integer that is equivalent to value represented
        by Python binary string format.
    z%not a valid Python binary string: %r!r4r	r)r7r'rr*)r6r+rrr�
bin_to_ints

r=)r	)r	)r	)�__doc__�rer:Znetaddr.compatrrrr1rr&r)r-r.r3r7r<r=rrrr�<module>s
 

"