
    4)diYq                        d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZ d dlZd dlZ edd          Z G d	 de          Z G d
 deej                  ZdS )    )annotationsN)BitsBitsType)Dtype)UnionListAnyOptionaloverloadTypeVarTupleTConstBitStreamConstBitStream)boundc                      e Zd ZdZdZ	 	 dMdNdZdOdZdPdZdQdZdPdZ	dRdZ
dSdZdTdZdTdZdTdZdTdZdUdZdVd ZdWdXd!Z	 	 dYdZ fd'Z	 	 dYdZ fd(Zed[d+            Zed\d-            Zd]d0Zd^d3ZdWd_d4Zed`d5            Zedad7            Zdbd9Zdcd<ZdPd=Zedd fdA            ZededD            ZedfdF            Zdg fdIZ ee	edJK          Z  ee	edJK          Z! eeedLK          Z" xZ#S )hr   a  A container or stream holding an immutable sequence of bits.

    For a mutable container use the BitStream class instead.

    Methods inherited from Bits:

    all() -- Check if all specified bits are set to 1 or 0.
    any() -- Check if any of specified bits are set to 1 or 0.
    copy() -- Return a copy of the bitstring.
    count() -- Count the number of bits set to 1 or 0.
    cut() -- Create generator of constant sized chunks.
    endswith() -- Return whether the bitstring ends with a sub-string.
    find() -- Find a sub-bitstring in the current bitstring.
    findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
    fromstring() -- Create a bitstring from a formatted string.
    join() -- Join bitstrings together using current bitstring.
    pp() -- Pretty print the bitstring.
    rfind() -- Seek backwards to find a sub-bitstring.
    split() -- Create generator of chunks split by a delimiter.
    startswith() -- Return whether the bitstring starts with a sub-bitstring.
    tobitarray() -- Return bitstring as a bitarray from the bitarray package.
    tobytes() -- Return bitstring as bytes, padding if needed.
    tofile() -- Write bitstring to file, padding if needed.
    unpack() -- Interpret bits using format string.

    Other methods:

    bytealign() -- Align to next byte boundary.
    peek() -- Peek at and interpret next bits as a single item.
    peeklist() -- Peek at and interpret next bits as a list of items.
    read() -- Read and interpret next bits as a single item.
    readlist() -- Read and interpret next bits as a list of items.
    readto() -- Read up to and including next occurrence of a bitstring.

    Special methods:

    Also available are the operators [], ==, !=, +, *, ~, <<, >>, &, |, ^.

    Properties:

    [GENERATED_PROPERTY_DESCRIPTIONS]

    len -- Length of the bitstring in bits.
    pos -- The current bit position in the bitstring.
    _posNr   lengthOptional[int]offsetposintautoOptional[Union[BitsType, int]]returnNonec                   |dk     r|t          | j                  z  }|dk     s|t          | j                  k    r-t          j        d| dt          | j                   d          || _        d| j        _        dS )ak  Either specify an 'auto' initialiser:
        A string of comma separated tokens, an integer, a file object,
        a bytearray, a boolean iterable or another bitstring.

        Or initialise via **kwargs with one (and only one) of:
        bin -- binary string representation, e.g. '0b001010'.
        hex -- hexadecimal string representation, e.g. '0x2ef'
        oct -- octal string representation, e.g. '0o777'.
        bytes -- raw data as a bytes object, for example read from a binary file.
        int -- a signed integer.
        uint -- an unsigned integer.
        float / floatbe -- a big-endian floating point number.
        bool -- a boolean (True or False).
        se -- a signed exponential-Golomb code.
        ue -- an unsigned exponential-Golomb code.
        sie -- a signed interleaved exponential-Golomb code.
        uie -- an unsigned interleaved exponential-Golomb code.
        floatle -- a little-endian floating point number.
        floatne -- a native-endian floating point number.
        bfloat / bfloatbe - a big-endian bfloat format 16-bit floating point number.
        bfloatle -- a little-endian bfloat format 16-bit floating point number.
        bfloatne -- a native-endian bfloat format 16-bit floating point number.
        intbe -- a signed big-endian whole byte integer.
        intle -- a signed little-endian whole byte integer.
        intne -- a signed native-endian whole byte integer.
        uintbe -- an unsigned big-endian whole byte integer.
        uintle -- an unsigned little-endian whole byte integer.
        uintne -- an unsigned native-endian whole byte integer.
        filename -- the path of a file which will be opened in binary read-only mode.

        Other keyword arguments:
        length -- length of the bitstring in bits, if needed and appropriate.
                  It must be supplied for all integer and float initialisers.
        offset -- bit offset to the data. These offset bits are
                  ignored and this is mainly intended for use when
                  initialising using 'bytes' or 'filename'.
        pos -- Initial bit position, defaults to 0.

        r   zCannot set pos to z when length is .TN)len	_bitstore	bitstringCreationErrorr   	immutableselfr   r   r   r   kwargss         Z/var/www/menimich/repos/protonApp/venv/lib/python3.11/site-packages/bitstring/bitstream.py__init__zConstBitStream.__init__>   s    R 773t~&&&C77cC////)*js*j*jTWX\XfTgTg*j*j*jkkk	#'       byteposc                6    |                      |dz             dS )z1Move to absolute byte-aligned position in stream.   N)
_setbitpos)r%   r*   s     r'   _setbyteposzConstBitStream._setbyteposn   s    !$$$$$r)   c                R    | j         dz  rt          j        d          | j         dz  S )zIReturn the current position in the stream in bytes. Must be byte aligned.r,   z-Not byte aligned when using bytepos property.)r   r!   ByteAlignErrorr%   s    r'   _getbyteposzConstBitStream._getbyteposr   s/    9q= 	\*+Z[[[yA~r)   c                    |dk     rt          d          |t          |           k    rt          d          || _        dS )z+Move to absolute position bit in bitstream.r   z Bit position cannot be negative.z%Cannot seek past the end of the data.N)
ValueErrorr   r   )r%   r   s     r'   r-   zConstBitStream._setbitposx   sC    77?@@@T??DEEE			r)   c                    | j         S )z2Return the current position in the stream in bits.r   r1   s    r'   
_getbitposzConstBitStream._getbitpos   s
    yr)   c                <    t          j        |            d| _        d S Nr   )r   _clearr   r1   s    r'   r9   zConstBitStream._clear   s    D			r)   r%   r   c                T    |                                  }| j        |_        d|_        |S )z<Return a new copy of the ConstBitStream for the copy module.r   )	__class__r    r   )r%   ss     r'   __copy__zConstBitStream.__copy__   s(     NNnr)   bsr   c               >    t          j        | |          }d|_        |S )zBit-wise 'and' between two bitstrings. Returns new bitstring.

        bs -- The bitstring to '&' with.

        Raises ValueError if the two bitstrings have differing lengths.

        r   )r   __and__r   r%   r>   r<   s      r'   r@   zConstBitStream.__and__   !     Lr""r)   c               >    t          j        | |          }d|_        |S )zBit-wise 'or' between two bitstrings. Returns new bitstring.

        bs -- The bitstring to '|' with.

        Raises ValueError if the two bitstrings have differing lengths.

        r   )r   __or__r   rA   s      r'   rD   zConstBitStream.__or__   s!     Kb!!r)   c               >    t          j        | |          }d|_        |S )zBit-wise 'xor' between two bitstrings. Returns new bitstring.

        bs -- The bitstring to '^' with.

        Raises ValueError if the two bitstrings have differing lengths.

        r   )r   __xor__r   rA   s      r'   rF   zConstBitStream.__xor__   rB   r)   c               >    t          j        | |          }d|_        |S )zbConcatenate bitstrings and return new bitstring.

        bs -- the bitstring to append.

        r   )r   __add__r   rA   s      r'   rH   zConstBitStream.__add__   s!     Lr""r)   c               X    |                      |           t          |           | _        dS )zAppend a bitstring to the current bitstring.

        bs -- The bitstring to append.

        The current bit position will be moved to the end of the BitStream.

        N_appendr   r   r%   r>   s     r'   appendzConstBitStream.append   s'     	RII			r)   strc                h    |                      | j        j        t          |           | j                  S )zReturn representation that could be used to recreate the bitstring.

        If the returned string is too long it will be truncated. See __str__().

        )_reprr;   __name__r   r   r1   s    r'   __repr__zConstBitStream.__repr__   s'     zz$.13t99diHHHr)   c               D   t          j        |          }t          |          dk    rdS || j        }|dk     r|t          |           z  }|dk     s|t          |           k    rt	          d          |                     ||           |t          |          z   | _        dS )a2  Overwrite with bitstring at bit position pos.

        bs -- The bitstring to overwrite with.
        pos -- The bit position to begin overwriting from.

        The current bit position will be moved to the end of the overwritten section.
        Raises ValueError if pos < 0 or pos > len(self).

        r   Nz/Overwrite starts outside boundary of bitstring.)r   _create_from_bitstyper   r   r4   
_overwriter%   r>   r   s      r'   	overwritezConstBitStream.overwrite   s     '++r77a<<F;)C773t99C77cCIIooNOOOC   #b''M			r)   startendbytealignedOptional[bool]Union[Tuple[int], Tuple[()]]c               n    t                                          ||||          }|r|d         | _        |S )a  Find first occurrence of substring bs.

        Returns a single item tuple with the bit position if found, or an
        empty tuple if not found. The bit position (pos property) will
        also be set to the start of the substring if it is found.

        bs -- The bitstring to find.
        start -- The bit position to start the search. Defaults to 0.
        end -- The bit position one past the last bit to search.
               Defaults to len(self).
        bytealigned -- If True the bitstring will only be
                       found on byte boundaries.

        Raises ValueError if bs is empty, if start < 0, if end > len(self) or
        if end < start.

        >>> BitStream('0xc3e').find('0b1111')
        (6,)

        r   )superfindr   r%   r>   rX   rY   rZ   pr;   s         r'   r_   zConstBitStream.find   s8    . GGLLUC55 	!DIr)   c               n    t                                          ||||          }|r|d         | _        |S )a  Find final occurrence of substring bs.

        Returns a single item tuple with the bit position if found, or an
        empty tuple if not found. The bit position (pos property) will
        also be set to the start of the substring if it is found.

        bs -- The bitstring to find.
        start -- The bit position to end the reverse search. Defaults to 0.
        end -- The bit position one past the first bit to reverse search.
               Defaults to len(self).
        bytealigned -- If True the bitstring will only be found on byte
                       boundaries.

        Raises ValueError if bs is empty, if start < 0, if end > len(self) or
        if end < start.

        r   )r^   rfindr   r`   s         r'   rc   zConstBitStream.rfind  s8    & GGMM"eS+66 	!DIr)   fmtr   c                    d S N r%   rd   s     r'   readzConstBitStream.read      r)   r	   c                    d S rf   rg   rh   s     r'   ri   zConstBitStream.read!  rj   r)   Union[int, str, Dtype]/Union[int, float, str, Bits, bool, bytes, None]c           	        | j         }t          |t          j                  r|dk     rt	          d          |t          |           | j         z
  k    r0t          j        d| dt          |           | j         z
   d          |                     | j         | j         |z             }| xj         |z  c_         |S t          j	        
                    |          }|j        |j        sxt          |           | j         z
  }t          ||j                  \  }}|dk    r#t	          d|j         d|j         d	| d
          t          j	        
                    ||          }|j        1|                    | | j                   }| xj         |j        z  c_         n#|                    | | j                   \  }| _         | j         t          |           k    r2|| _         t          j        d| dt          |           |z
   d          |S )a  Interpret next bits according to the format string and return result.

        fmt -- Token string describing how to interpret the next bits.

        Token examples: 'int:12'    : 12 bits as a signed integer
                        'uint:8'    : 8 bits as an unsigned integer
                        'float:64'  : 8 bytes as a big-endian float
                        'intbe:16'  : 2 bytes as a big-endian signed integer
                        'uintbe:16' : 2 bytes as a big-endian unsigned integer
                        'intle:32'  : 4 bytes as a little-endian signed integer
                        'uintle:32' : 4 bytes as a little-endian unsigned integer
                        'floatle:64': 8 bytes as a little-endian float
                        'intne:24'  : 3 bytes as a native-endian signed integer
                        'uintne:24' : 3 bytes as a native-endian unsigned integer
                        'floatne:32': 4 bytes as a native-endian float
                        'hex:80'    : 80 bits as a hex string
                        'oct:9'     : 9 bits as an octal string
                        'bin:1'     : single bit binary string
                        'ue'        : next bits as unsigned exp-Golomb code
                        'se'        : next bits as signed exp-Golomb code
                        'uie'       : next bits as unsigned interleaved exp-Golomb code
                        'sie'       : next bits as signed interleaved exp-Golomb code
                        'bits:5'    : 5 bits as a bitstring
                        'bytes:10'  : 10 bytes as a bytes object
                        'bool'      : 1 bit as a bool
                        'pad:3'     : 3 bits of padding to ignore - returns None

        fmt may also be an integer, which will be treated like the 'bits' token.

        The position in the bitstring is advanced to after the read items.

        Raises ReadError if not enough bits are available.
        Raises ValueError if the format is not understood.

        r   zCannot read negative amount.zCannot read z bits, only z available.NzThe 'z4' type must have a bit length that is a multiple of z so cannot be read from the z bits that are available.z'Reading off end of bitstring with fmt 'z'. Only z bits available.)r   
isinstancenumbersIntegralr4   r   r!   	ReadError_slicedtypesr   	bitlengthvariable_lengthdivmodbits_per_itemnameread_fn)	r%   rd   ra   r>   dtyperu   items	remaindervals	            r'   ri   zConstBitStream.read%  s   H Ic7+,, 	Qww !?@@@SYY***)*l*l*l#d))VZV_J_*l*l*lmmmTY	C88BIIIII &&s++?"5+@"D		DI-I%i1DEEE9A~~ XEJ X X\a\o X X3<X X XY Y Y $**366E?&--di00CII(III"]]4;;NC9s4yy  DI%&|PS&|&|]`ae]f]fij]j&|&|&|}}}
r)   (Union[str, List[Union[int, str, Dtype]]]5List[Union[int, float, str, Bits, bool, bytes, None]]c                >     | j         || j        fi |\  }| _        |S )a  Interpret next bits according to format string(s) and return list.

        fmt -- A single string or list of strings with comma separated tokens
               describing how to interpret the next bits in the bitstring. Items
               can also be integers, for reading new bitstring of the given length.
        kwargs -- A dictionary or keyword-value pairs - the keywords used in the
                  format string will be replaced with their given value.

        The position in the bitstring is advanced to after the read items.

        Raises ReadError is not enough bits are available.
        Raises ValueError if the format is not understood.

        See the docstring for 'read' for token examples. 'pad' tokens are skipped
        and not added to the returned list.

        >>> h, b1, b2 = s.readlist('hex:20, bin:5, bin:3')
        >>> i, bs1, bs2 = s.readlist(['uint:12', 10, 10])

        )	_readlistr   )r%   rd   r&   values       r'   readlistzConstBitStream.readlistg  s-    , *4>#tyCCFCCtyr)   c               `   t          |t          j                  rt          d          t	          j        |          }| j        }|                     || j        |          }|st          j	        d          | xj        t          |          z  c_        |                     || j                  S )a4  Read up to and including next occurrence of bs and return result.

        bs -- The bitstring to find.
        bytealigned -- If True the bitstring will only be
                       found on byte boundaries.

        Raises ValueError if bs is empty.
        Raises ReadError if bs is not found.

        zIntegers cannot be searched for)rZ   zSubstring not found)ro   rp   rq   r4   r   rT   r   r_   r!   rr   r   rs   )r%   r>   rZ   oldposra   s        r'   readtozConstBitStream.readto  s     b'*++ 	@>???'++IIb$)I== 	=%&;<<<		SWW		{{649---r)   c                    d S rf   rg   rh   s     r'   peekzConstBitStream.peek  rj   r)   :Union[int, float, str, TConstBitStream, bool, bytes, None]c                    d S rf   rg   rh   s     r'   r   zConstBitStream.peek  rj   r)   Union[int, str]c                L    | j         }|                     |          }|| _         |S )a  Interpret next bits according to format string and return result.

        fmt -- Token string describing how to interpret the next bits.

        The position in the bitstring is not changed. If not enough bits are
        available then all bits to the end of the bitstring will be used.

        Raises ReadError if not enough bits are available.
        Raises ValueError if the format is not understood.

        See the docstring for 'read' for token examples.

        )r   ri   )r%   rd   
pos_beforer   s       r'   r   zConstBitStream.peek  s&     Y
		#	r)   !Union[str, List[Union[int, str]]](List[Union[int, float, str, Bits, None]]c                >    | j         } | j        |fi |}|| _         |S )a  Interpret next bits according to format string(s) and return list.

        fmt -- One or more integers or strings with comma separated tokens describing
               how to interpret the next bits in the bitstring.
        kwargs -- A dictionary or keyword-value pairs - the keywords used in the
                  format string will be replaced with their given value.

        The position in the bitstring is not changed. If not enough bits are
        available then all bits to the end of the bitstring will be used.

        Raises ReadError if not enough bits are available.
        Raises ValueError if the format is not understood.

        See the docstring for 'read' for token examples.

        )r   r   )r%   rd   r&   r   return_valuess        r'   peeklistzConstBitStream.peeklist  s1    $ i%c44V44	r)   c                F    d| j         dz  z
  dz  }| xj        |z  c_        |S )zAlign to next byte and return number of skipped bits.

        Raises ValueError if the end of the bitstring is reached before
        aligning to the next byte.

        r,   )r   r   )r%   skippeds     r'   	bytealignzConstBitStream.bytealign  s.     	A&!+Gr)   clsTBitsr<   c               p    t                                          |          }d|_        d|j        _        |S )Nr   T)r^   
fromstringr   r    r#   )r   r<   xr;   s      r'   r   zConstBitStream.fromstring  s0    GGq!! $r)   keyslicec                   d S rf   rg   r%   r   s     r'   __getitem__zConstBitStream.__getitem__  rj   r)   boolc                   d S rf   rg   r   s     r'   r   zConstBitStream.__getitem__  rj   r)   Union[slice, int]Union[TBits, bool]c               "   t          |t          j                  r't          | j                            |                    S t                                          | j                  }| j        	                    |          |_        d|_
        |S )zEReturn a new bitstring representing a slice of the current bitstring.r   )ro   rp   rq   r   r    getindexr^   __new__r;   getslice_withstepr   )r%   r   r>   r;   s      r'   r   zConstBitStream.__getitem__  sp    c7+,, 	6//44555WW__T^,,~77<<	r)   zMThe position in the bitstring in bits. Read and write.
                      )doczNThe position in the bitstring in bytes. Read and write.
                      NNNr   
r   r   r   r   r   r   r   r   r   r   )r*   r   r   r   )r   r   )r   r   r   r   )r   r   )r%   r   r   r   )r%   r   r>   r   r   r   r>   r   r   r   )r   rN   rf   r   r   r>   r   r   r   )NNN)
rX   r   rY   r   rZ   r[   r>   r   r   r\   )rd   r   r   r   )rd   rN   r   r	   )rd   rl   r   rm   )rd   r   r   r   )rZ   r[   r%   r   r>   r   r   r   )r%   r   rd   r   r   r   )rd   rN   r   r   )r%   r   rd   r   r   r   )rd   r   r   r   )r   r   r<   rN   r   r   )r%   r   r   r   r   r   )r%   r   r   r   r   r   )r%   r   r   r   r   r   )$rQ   
__module____qualname____doc__	__slots__r(   r.   r2   r-   r6   r9   r=   r@   rD   rF   rH   rM   rR   rW   r_   rc   r   ri   r   r   r   r   r   classmethodr   r   propertyr   bitposr*   __classcell__r;   s   @r'   r   r      s       , ,\ I_c:;.( .( .( .( .(`% % % %               
 
 
 

 
 
 

 
 
 
   	 	 	 	I I I I" " " " ", W[+/      8 X\,0      0    X    X@ @ @ @D   2. . . . .*    X    X   &   .	 	 	 	      [    X    X      (:z  C Xj*  F h{K  GGGGGr)   c                  r     e Zd ZdZdZ	 	 d"d#dZd$dZd%dZd& fdZd' fdZ	d(dZ
d)d*dZ	 	 d+d,d!Z xZS )-	BitStreama	  A container or stream holding a mutable sequence of bits

    Subclass of the ConstBitStream and BitArray classes. Inherits all of
    their methods.

    Methods:

    all() -- Check if all specified bits are set to 1 or 0.
    any() -- Check if any of specified bits are set to 1 or 0.
    append() -- Append a bitstring.
    bytealign() -- Align to next byte boundary.
    byteswap() -- Change byte endianness in-place.
    clear() -- Remove all bits from the bitstring.
    copy() -- Return a copy of the bitstring.
    count() -- Count the number of bits set to 1 or 0.
    cut() -- Create generator of constant sized chunks.
    endswith() -- Return whether the bitstring ends with a sub-string.
    find() -- Find a sub-bitstring in the current bitstring.
    findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
    fromstring() -- Create a bitstring from a formatted string.
    insert() -- Insert a bitstring.
    invert() -- Flip bit(s) between one and zero.
    join() -- Join bitstrings together using current bitstring.
    overwrite() -- Overwrite a section with a new bitstring.
    peek() -- Peek at and interpret next bits as a single item.
    peeklist() -- Peek at and interpret next bits as a list of items.
    pp() -- Pretty print the bitstring.
    prepend() -- Prepend a bitstring.
    read() -- Read and interpret next bits as a single item.
    readlist() -- Read and interpret next bits as a list of items.
    readto() -- Read up to and including next occurrence of a bitstring.
    replace() -- Replace occurrences of one bitstring with another.
    reverse() -- Reverse bits in-place.
    rfind() -- Seek backwards to find a sub-bitstring.
    rol() -- Rotate bits to the left.
    ror() -- Rotate bits to the right.
    set() -- Set bit(s) to 1 or 0.
    split() -- Create generator of chunks split by a delimiter.
    startswith() -- Return whether the bitstring starts with a sub-bitstring.
    tobitarray() -- Return bitstring as a bitarray from the bitarray package.
    tobytes() -- Return bitstring as bytes, padding if needed.
    tofile() -- Write bitstring to file, padding if needed.
    unpack() -- Interpret bits using format string.

    Special methods:

    Mutating operators are available: [], <<=, >>=, +=, *=, &=, |= and ^=
    in addition to [], ==, !=, +, *, ~, <<, >>, &, | and ^.

    Properties:

    [GENERATED_PROPERTY_DESCRIPTIONS]

    len -- Length of the bitstring in bits.
    pos -- The current bit position in the bitstring.
    rg   Nr   r   r   r   r   r   r   r   r   r   c                   t          j        | ||||fi | | j        j        r,| j                                        | _        d| j        _        dS dS )ad  Either specify an 'auto' initialiser:
        A string of comma separated tokens, an integer, a file object,
        a bytearray, a boolean iterable or another bitstring.

        Or initialise via **kwargs with one (and only one) of:
        bin -- binary string representation, e.g. '0b001010'.
        hex -- hexadecimal string representation, e.g. '0x2ef'
        oct -- octal string representation, e.g. '0o777'.
        bytes -- raw data as a bytes object, for example read from a binary file.
        int -- a signed integer.
        uint -- an unsigned integer.
        float / floatbe -- a big-endian floating point number.
        bool -- a boolean (True or False).
        se -- a signed exponential-Golomb code.
        ue -- an unsigned exponential-Golomb code.
        sie -- a signed interleaved exponential-Golomb code.
        uie -- an unsigned interleaved exponential-Golomb code.
        floatle -- a little-endian floating point number.
        floatne -- a native-endian floating point number.
        bfloat / bfloatbe - a big-endian bfloat format 16-bit floating point number.
        bfloatle -- a little-endian bfloat format 16-bit floating point number.
        bfloatne -- a native-endian bfloat format 16-bit floating point number.
        intbe -- a signed big-endian whole byte integer.
        intle -- a signed little-endian whole byte integer.
        intne -- a signed native-endian whole byte integer.
        uintbe -- an unsigned big-endian whole byte integer.
        uintle -- an unsigned little-endian whole byte integer.
        uintne -- an unsigned native-endian whole byte integer.
        filename -- the path of a file which will be opened in binary read-only mode.

        Other keyword arguments:
        length -- length of the bitstring in bits, if needed and appropriate.
                  It must be supplied for all integer and float initialisers.
        offset -- bit offset to the data. These offset bits are
                  ignored and this is intended for use when
                  initialising using 'bytes' or 'filename'.
        pos -- Initial bit position, defaults to 0.

        FN)r   r(   r    r#   _copyr$   s         r'   r(   zBitStream.__init__1  sb    R 	dFFCJJ6JJJ># 	-!^1133DN',DN$$$	- 	-r)   c                    t                               t                    }d|_        | j                                        |_        |S )z#Return a new copy of the BitStream.r   )objectr   r   r   r    copy)r%   s_copys     r'   r=   zBitStream.__copy___  s5    	**>..00r)   r>   r   c               X    |                      |           t          |           | _        | S )zAppend to current bitstring. Return self.

        bs -- the bitstring to append.

        The current bit position will be moved to the end of the BitStream.
        rJ   rL   s     r'   __iadd__zBitStream.__iadd__f  s(     	RII	r)   c                   t          j        |          }t                                          |           d| _        dS )z`Prepend a bitstring to the current bitstring.

        bs -- The bitstring to prepend.

        r   N)r   rT   r^   prependr   )r%   r>   r;   s     r'   r   zBitStream.prependq  s6     '++			r)   r   r   r   c                   t          |           }t                                          ||           t          |           |k    rd| _        d S r8   )r   r^   __setitem__r   )r%   r   r   length_beforer;   s       r'   r   zBitStream.__setitem__{  sE    D		C'''t99%%DIr)   c                   t          |           }| j                            |           t          |           |k    r	d| _        dS dS )zDelete item or range.

        >>> a = BitStream('0x001122')
        >>> del a[8:16]
        >>> print a
        0x0022

        r   N)r   r    __delitem__r   )r%   r   r   s      r'   r   zBitStream.__delitem__  sI     D		""3'''t99%%DIII &%r)   c               z   t          j        |          }t          |          dk    rdS || u r|                                 }|| j        }|dk     r|t          |           z  }d|cxk    rt          |           k    sn t          d          |                     ||           |t          |          z   | _        dS )a  Insert bitstring at bit position pos.

        bs -- The bitstring to insert.
        pos -- The bit position to insert at.

        The current bit position will be moved to the end of the inserted section.
        Raises ValueError if pos < 0 or pos > len(self).

        r   NzInvalid insert position.)r   rT   r   r   r   r4   _insertrV   s      r'   insertzBitStream.insert  s     '++r77a<<F::B;)C773t99CC$$$$3t99$$$$7888R#b''M			r)   oldnewrX   rY   countrZ   r[   c                   |dk    rdS t          t          j        |          x}          dk    rt          d          |                     ||          \  }}t          j        |          }|| u rt          j        |           }t          |           }|                     |||||dn||          }t          |           |k    rd| _        |S )a  Replace all occurrences of old with new in place.

        Returns number of replacements made.

        old -- The bitstring to replace.
        new -- The replacement bitstring.
        start -- Any occurrences that start before this will not be replaced.
                 Defaults to 0.
        end -- Any occurrences that finish after this will not be replaced.
               Defaults to len(self).
        count -- The maximum number of replacements to make. Defaults to
                 replace all occurrences.
        bytealigned -- If True replacements will only be made on byte
                       boundaries.

        Raises ValueError if old is empty or if start or end are
        out of range.

        r   z#Empty bitstring cannot be replaced.)r   r   rT   r4   _validate_slicer   _replacer   )	r%   r   r   rX   rY   r   rZ   r   replacement_counts	            r'   replacezBitStream.replace  s    * A::1d0555s66!;;BCCC))%55
s(--$;;)D//CD		 MM#sE3U]X]_jkkt99%%DI  r)   r   r   )r   r   )r>   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   rf   r   )NNNN)r   r   r   r   rX   r   rY   r   r   r   rZ   r[   r   r   )rQ   r   r   r   r   r(   r=   r   r   r   r   r   r   r   r   s   @r'   r   r     s       7 7r I_c:;,- ,- ,- ,- ,-\   	 	 	 	             " " " " "0 gkKO"! "! "! "! "! "! "! "! "!r)   r   )
__future__r   r!   bitstring.bitsr   r   bitstring.dtypesr   typingr   r   r	   r
   r   r   r   r   rp   r   r   BitArrayr   rg   r)   r'   <module>r      s!   " " " " " "     ) ) ) ) ) ) ) ) " " " " " " G G G G G G G G G G G G G G G G G G  '+3CDDDe e e e eT e e ePU! U! U! U! U!	 2 U! U! U! U! U!r)   