HEX
Server: Apache
System: Linux a16-asgard6.hospedagemuolhost.com.br 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: maoristu4c3dbd03 (1436)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/rhsm/__pycache__/bitstream.cpython-39.pyc
a

X�Zh��@s.ddlmZddlmZmZGdd�d�ZdS)�)�deque)�List�Unionc@s�eZdZdZeeefdd�dd�Zdd�dd�Zed�d	d
�Z	e
d�dd�Zee
ed
�dd��Z
ee
ed�dd��Zeee
e
d�dd��ZdS)�GhettoBitStreama�
    Accepts binary data and makes it available as a stream of bits or one byte
    at a time. Python does not provide a built-in way to read a stream of bits,
    or a way to represent a single bit. Thus, this class uses character '0'
    or '1' to represent the status of each bit.

    Data is converted into the '0' and '1' characters one byte at a time, since
    that operation multiplies the size of the data by a factor of 8, and it may
    not be desirable to inflate all the data at once.
    N)�data�returncCstt|��|_t�|_dS)z9
        :param data:    binary data in a string
        N)r�	bytearray�bytes�_bit_buffer)�selfr�r�4/usr/lib64/python3.9/site-packages/rhsm/bitstream.py�__init__szGhettoBitStream.__init__)rcCs|S)Nr�rrrr
�__iter__$szGhettoBitStream.__iter__cCsJ|js@z|��}Wnty(t�Yn0|�|�}|j�|�|j��S)z�
        converts one byte at a time into a bit representation, waiting until
        those bits have been consumed before converting another byte

        :return:    next bit in the stream, either '0' or '1'
        :rtype:     string
        )r
�pop_byte�
IndexError�
StopIteration�
_byte_to_bits�extend�popleft)r�byte�bitsrrr
�__next__'s

zGhettoBitStream.__next__cCs
|j��S)zG
        :return:    next entire byte in the stream, as an int
        )r	rrrrr
r8szGhettoBitStream.pop_byte)rrcCs.zd�|�WSty(|�|�YS0dS)a|
        Produces a string representation of a byte as a base-2 number.
        Python versions < 2.6 lack the "bin()" builtin as well as the
        below "format()" method of strings, so this method falls back
        to using a home-brew implementation.

        :param byte:    positive int < 256
        :return:        binary representation of byte as 8-char string
        z{0:08b}N)�format�AttributeError�
_bin_backport)�clsrrrr
r>szGhettoBitStream._byte_to_bits)�xrcCsNg}tddd�D]2}|d|}|dkr8|�d�|}q|�d�qd�|�S)a
        In python versions < 2.6, there is no built-in way to produce a string
        representation of base-2 data. Thus, we have to do it manually.

        :param byte:    positive int < 256
        :return:        binary representation of byte as 8-char string
        �����r�1�0�)�range�append�join)r�chars�n�yrrr
rOs	
zGhettoBitStream._bin_backportcCs*|dd�}|��tdd�t|�D��S)a�
        combine unsigned ints read from a bit stream into one unsigned number,
        reading data as big-endian

        :param data:    iterable of positive ints, each representing a byte of
                        uint binary data that should be combined
                        such that the right-most byte stays as-is, and then
                        each byte to the left gets left-shifted by 8 * n bits.
                        For example, [1, 2] would give you 258 ((1 << 8) + 2)
        :type  data:    iterable of positive ints
        :return:        positive int, composed from input bytes combined as
                        one int
        Ncss|]\}}||d>VqdS)�Nr)�.0r)rrrr
�	<genexpr>s�z0GhettoBitStream.combine_bytes.<locals>.<genexpr>)�reverse�sum�	enumerate)r�copyrrr
�
combine_bytesbszGhettoBitStream.combine_bytes)�__name__�
__module__�__qualname__�__doc__rr	�strrrr�intr�classmethodr�staticmethodrrr3rrrr
rsrN)�collectionsr�typingrrrrrrr
�<module>
s