HEX
Server: LiteSpeed
System: Linux premium71.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: consovgw (933)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3.6/site-packages/netaddr/strategy/__pycache__/__init__.cpython-36.pyc
3

��],�@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_strcCsfg}tddd	�}xPtd�D]D}ddg}x$|D]}d|d@||<|dL}q.W|jdj|��qW|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	)r�range�append�join)�lookupZ
bits_per_byte�num�bits�i�r�/usr/lib/python3.6/__init__.py�
bytes_to_bitss

rcCsXt|d�sdSt|�|krdSd|d}x(|D] }d|koF|kns0dSq0WdS)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|ko"|kns8tdt|���d|d}g}x.t|�D]"}||@}|jt|��||L}qRWtt|��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&cCsRt|||�std|��d}x0tt|��D] \}}|}|||>}||B}q*W|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)rcCs|t|�sdS|dkr |j|d�}t|�|kr0dSd|d}y&dt|d�koV|knr`dSWntk
rvYnXdS)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.
    FrrrrT)r�replacerrr')r�width�word_sepr#rrr�
valid_bitsmsr-cCs6t|||�std|��|dkr,|j|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!rr)r-r'r*r)rr+r,rrr�bits_to_int�s

r.cCs�g}xvt|||�D]f}g}x"|r<|jt|d@�|dL}qW|j�dj|�pVd|}d|||d�}|j|�qW|dk	r�t|�s�td|��|j|�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|jd�sdS|jdd�}t|�|kr6dSd|d}y&dt|d�ko\|knrfdSWntk
r|YnXdS)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�0brrrrT)r�
startswithr*rrr')�bin_valr+r#rrr�	valid_bin�s

r7cCs�g}yt|�}Wndtk
rt|}x*|dkrN|d@}|jt|�|dL}q&W|j�dtjdddj|��}YnXt|dd	��|kr�t	d
|��|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\1rrNz 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|��t|jdd�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!r4rr)r7r'rr*)r6r+rrr�
bin_to_ints

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

"