
    4)di+             
         U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlZd dlmZmZmZmZmZmZmZmZmZmZmZmZ d dlZd dlZd dlZd dlmZ d dlmZmZ d dl m!Z!m"Z" d dl#m$Z$m%Z% d d	l&m'Z'm(Z(m)Z)m*Z*m+Z+ d d
l,m-Z- ede.ee         e/ee0e1e2ej        f	         Z3 edd          Z4dZ5de6d<    G d d          Z7dS )    )annotationsN)abc)TupleUnionListIterableAnyOptionalBinaryIOTextIOoverloadIteratorTypeTypeVar)BitStore)bitstore_helpersutils)Dtypedtype_register)p4binary_fmtp3binary_fmt)e3m2mxfp_fmte2m3mxfp_fmte2m1mxfp_fmte4m3mxfp_saturate_fmte5m2mxfp_saturate_fmt)ColourBitsTBits)bound   int	MAX_CHARSc                  .    e Zd ZdZdZ	 	 dddZ	 	 dd fdZed fd            ZddZ	ddZ
ddZddZddZddZdd Zdd!Zdd#Zdd$Zedd'            Zedd)            Zd fd,Zdd-Zdd/Zdd0Zdd2Zdd3Zdd4Zdd5Zdd6Zd d8Zd d9Zd d:Zd d;Z dd<Z!dd=Z"dd>Z#dd?Z$dd@Z%ddAZ&d!dBZ'ddCZ(d"dDZ)d#dEZ*d$dGZ+d%dHZ,d&d'dJZ-d(dMZ.d)d*dNZ/d+dQZ0d+dRZ1d+dSZ2d+dTZ3d+dUZ4d+dVZ5d+dWZ6d+dXZ7d+dYZ8d)d,d\Z9d&d-d^Z:dd_Z; e< e=d`da                    Z>e>?                     e=dbdc                     dddZ@d)d.dfZAddgZBd)d/diZCddjZDd)d0dlZEddmZFd)d1doZGddpZHd)d2drZIddsZJd)d3duZKddvZLd4dwZMd4dxZNd4dyZOd4dzZPd4d{ZQd4d|ZRd4d}ZSd4d~ZTd4dZUd5dZVd)d6dZWd4dZXd)d6dZYd4dZZd4dZ[d)d7dZ\d4dZ]d)d7dZ^d8dZ_d9dZ`d:dZad:dZbd:dZcd:dZdd8dZed9dZfd8dZgd9dZhd8dZid9dZjd;dZkd"dZld#dZmd<dZnd)d=dZod)d=dZpddZqd)d>dZrddZsd)d?dZtddZuddZvddZwd@dZxd@dZydAdZzdBdZ{dBdZ|dCdZ}dCdZ~dDdZdDdZdEdZdFdZdGdZd#dZd dZd dZd dZdHdZdIdZdJdńZdKdȄZdLd˄Z	 	 ddMdτZdNdЄZdNdфZ	 	 ddOdԄZdPdՄZdPdքZ	 	 ddMdׄZdNd؄ZdNdلZ	 	 ddQdۄZ	 	 ddRdބZdSdZddZdTdZdUdZd&dVdZd&dWdZd)dXdZd)dXdZdYdZe	 d)dZd            Zed[d            Zed\d            Zd]dZed             Zddddej        fd^dZdd	Zed_ fd
            Z eevd          xZZ xZS (`  r   a  A container holding an immutable sequence of bits.

    For a mutable container use the BitArray class instead.

    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.
    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.

    Special methods:

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

    Properties:

    [GENERATED_PROPERTY_DESCRIPTIONS]

    len -- Length of the bitstring in bits.

    )	_bitstore	_filenameNlengthOptional[int]offsetautoOptional[Union[BitsType, int]]returnNonec                   d| j         _        dS )aA  Either specify an 'auto' initialiser:
        A string of comma separated tokens, an integer, a file object,
        a bytearray, a boolean iterable, an array 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'.

        TN)r%   	immutable)selfr*   r'   r)   kwargss        U/var/www/menimich/repos/protonApp/venv/lib/python3.11/site-packages/bitstring/bits.py__init__zBits.__init__G   s    P $(       posclsType[TBits]r   c                   t                                          |           }|H|sF|/t          |          |_        |j                            d           nt                      |_        |S  |j        |||fi | |S Nr   )super__new__r   r%   setall_initialise)r6   r*   r'   r)   r5   r1   x	__class__s          r2   r;   zBits.__new__q   s    GGOOC  <<!&v..""1%%%%&jjHdFF55f555r4   BitsTypec                   t          ||           r|S t                                          |           }|                    |           |S N)
isinstancer:   r;   _setauto_no_length_or_offset)r6   r*   br?   s      r2   _create_from_bitstypezBits._create_from_bitstype   sH    dC   	KGGOOC  	&&t,,,r4   r	   c               B   |t          |t          j                  r[|dk     rt          j        d| d          t          t          |                    | _        | j                            d           d S | 	                    |||           d S |
                                \  }}|dk    r|                     |||           d S |dk    r|                     |||           d S |dk    r|                     |||           d S |dk    r/t          j        d| j        j         d	| j        j         d
          |t          j        d| d          	 t!          ||                              | |           d S # t$          $ r}t          j        |          d }~ww xY w)Nr   z*Can't create bitstring of negative length .bytesfilenamebitarrayr*   zjThe 'auto' parameter should not be given explicitly - just use the first positional argument. Instead of 'z(auto=x)' use 'z(x)'.z.offset cannot be used when initialising with ''.)rC   numbersIntegral	bitstringCreationErrorr   r"   r%   r<   _setautopopitem_setbytes_with_truncation_setfile_setbitarrayr?   __name__r   set_fn
ValueError)r0   r*   r'   r)   r1   kves           r2   r=   zBits._initialise   s   $ 011 !88#12f_c2f2f2fggg!)#d))!4!4%%a(((MM$///F~~1<<**1ff===F
??MM!VV,,,F
??a000F;;)f#~6f fGK~G^f f fg g g )*`[\*`*`*`aaa	-!V##D!,,,,, 	- 	- 	-)!,,,	-s   $E; ;
FFF	attributestrc           	     >   	 t          |          }n.# t          $ r! t          d| j        j         d| d          w xY w|j        Ct          |           |j        k    r+t          dt          |            d|j         d| d          |                    |           S )N'z' object has no attribute 'rL   zbitstring length z doesn't match length z of property ')r   rX   AttributeErrorr?   rV   	bitlengthlenget_fn)r0   r\   ds      r2   __getattr__zBits.__getattr__   s    	hi  AA 	h 	h 	h !fT^%<!f!fYb!f!f!fggg	h;"s4yyAK'?'?zTzzRSR]zzmvzzz{{{xx~~s    +=Iterable[bool]c                *    t          | j                  S rB   )iterr%   r0   s    r2   __iter__zBits.__iter__   s    DN###r4   r0   c                    | S )z2Return a new copy of the Bits for the copy module. ri   s    r2   __copy__zBits.__copy__   	     r4   otherboolc                    t           S rB   NotImplementedr0   ro   s     r2   __lt__zBits.__lt__   s    r4   c                    t           S rB   rr   rt   s     r2   __gt__zBits.__gt__       r4   c                    t           S rB   rr   rt   s     r2   __le__zBits.__le__   rx   r4   c                    t           S rB   rr   rt   s     r2   __ge__zBits.__ge__   rx   r4   bsc                `   | j                             |          }t          |          t          |           k    r|                                 n|                                }t          |          t          |           k    r|                    |           n|                    |            |S )zbConcatenate bitstrings and return new bitstring.

        bs -- the bitstring to append.

        )r?   rF   rb   _copy	_addright_addleftr0   r}   ss      r2   __add__zBits.__add__   s     ^11"55GGs4yy00DJJLLLbhhjjr77c$iiKKOOOOJJtr4   c                `    | j                             |          }|                    |           S )zAppend current bitstring to bs and return new bitstring.

        bs -- An object that can be 'auto' initialised as a bitstring that will be appended to.

        )r?   rF   r   r0   r}   s     r2   __radd__zBits.__radd__   s+     ^11"55zz$r4   keyslicec                   d S rB   rl   r0   r   s     r2   __getitem__zBits.__getitem__       r4   r"   c                   d S rB   rl   r   s     r2   r   zBits.__getitem__   r   r4   Union[slice, int]Union[TBits, bool]c                  t          |t          j                  r't          | j                            |                    S t                                          | j                  }| j        	                    |          |_        |S )zReturn a new bitstring representing a slice of the current bitstring.

        >>> print(Bits('0b00110')[1:4])
        '0b011'

        )
rC   rM   rN   rp   r%   getindexr:   r;   r?   getslice_withstep)r0   r   r}   r?   s      r2   r   zBits.__getitem__   sk     c7+,, 	6//44555WW__T^,,~77<<	r4   c                *    |                                  S z+Return the length of the bitstring in bits.)
_getlengthri   s    r2   __len__zBits.__len__   s       r4   rI   c                *    |                                  S rB   )tobytesri   s    r2   	__bytes__zBits.__bytes__   s    ||~~r4   c           	        t          |           }|sdS |t          dz  k    r:d                    d| dt          dz                                           df          S |dk     r|dz  dk    r
d| j        z   S |dz  s
d| j        z   S |dz  }d                    d| d||z
                                           dd| ||z
  d	                                         f          S )
a  Return approximate string representation of bitstring for printing.

        Short strings will be given wholly in hexadecimal or binary. Longer
        strings may be part hexadecimal and part binary. Very long strings will
        be truncated with '...'.

            0xr   ...    0b, N)rb   r#   join_gethexbinhex_getbin)r0   r'   bits_at_ends      r2   __str__zBits.__str__   s    T 	2IM!!77D$q1}"5"="="?"?GHHHB;;6A:??$(?"z 	#$(?" qjwwd1Vk%9#9:BBDDdD+)=)>)>$?$G$G$I$IK L L 	Lr4   	classnamec                    |rd| nd}t          | d          r| j        r| d| j        d| | dS |                                 }d}|                    d          rd| }| d	| d
| d| S )Nz, pos=r   r&   z
(filename=z	, length=)r   z  # length=z('r_   )hasattrr&   r   endswith)r0   r   r'   r5   
pos_stringr   lengthstrings          r2   _reprz
Bits._repr  s    '*2^c^^^
4%% 	C$. 	C[[4>[[f[j[[[[ALzz%   65V55BB1BBzBBLBBBr4   c                ^    |                      | j        j        t          |           d          S )zReturn representation that could be used to recreate the bitstring.

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

        r   )r   r?   rV   rb   ri   s    r2   __repr__zBits.__repr__   s%     zz$.13t99a@@@r4   c               v    	 | j         t                              |          j         k    S # t          $ r Y dS w xY w)zReturn True if two bitstrings have the same binary representation.

        >>> BitArray('0b1110') == '0xe'
        True

        F)r%   r   rF   	TypeErrorr   s     r2   __eq__zBits.__eq__(  sG    	>T%?%?%C%C%MMM 	 	 	55	s   '* 
88c               .    |                      |           S )zReturn False if two bitstrings have the same binary representation.

        >>> BitArray('0b111') == '0x7'
        False

        )r   r   s     r2   __ne__zBits.__ne__4  s     ;;r??""r4   c                    t          |           dk    rt          j        d          |                                 }|                                 |S )zdReturn bitstring with every bit inverted.

        Raises Error if the bitstring is empty.

        r   zCannot invert empty bitstring.)rb   rO   Errorr   _invert_allr0   r   s     r2   
__invert__zBits.__invert__=  sC     t99>>/"BCCCJJLL	r4   nc               8   |dk     rt          d          t          |           dk    rt          d          t          |t          |                     }|                     |t          |                     }|                    t          |                     |S )zwReturn bitstring with bits shifted by n to the left.

        n -- the number of bits to shift. Must be >= 0.

        r   "Cannot shift by a negative amount. Cannot shift an empty bitstring.)rX   rb   min_absolute_slicer   r   r0   r   r   s      r2   
__lshift__zBits.__lshift__I  s     q55ABBBt99>>?@@@3t99  CII..	DGGr4   c                  |dk     rt          d          t          |           dk    rt          d          |s|                                 S |                     t	          |t          |                               }t	          |t          |                     }|                    |                     dt          |           |z
                       |S )zxReturn bitstring with bits shifted by n to the right.

        n -- the number of bits to shift. Must be >= 0.

        r   r   r   r'   )rX   rb   r   r?   r   r   r   r   s      r2   
__rshift__zBits.__rshift__X  s     q55ABBBt99>>?@@@ 	 ::<<NN#aT"3"3N443t99	D((CIIM::;;;r4   c                   |dk     rt          d          |s|                                 S |                                 }|                    |           |S )zReturn bitstring consisting of n concatenations of self.

        Called for expression of the form 'a = b*3'.
        n -- The number of concatenations. Must be >= 0.

        r   z&Cannot multiply by a negative integer.)rX   r?   r   _imulr   s      r2   __mul__zBits.__mul__i  sU     q55EFFF 	$>>###JJLL	


r4   c               ,    |                      |          S )zReturn bitstring consisting of n concatenations of self.

        Called for expressions of the form 'a = 3*b'.
        n -- The number of concatenations. Must be >= 0.

        )r   r0   r   s     r2   __rmul__zBits.__rmul__x  s     ||Ar4   c                   || u r|                                  S t                              |          }t                              | j                  }| j        |j        z  |_        |S )zBit-wise 'and' between two bitstrings. Returns new bitstring.

        bs -- The bitstring to '&' with.

        Raises ValueError if the two bitstrings have differing lengths.

        copyr   rF   objectr;   r?   r%   r   s      r2   __and__zBits.__and__  V     ::99;;''++NN4>**nr|3r4   c               ,    |                      |          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   s     r2   __rand__zBits.__rand__       ||Br4   c                   || u r|                                  S t                              |          }t                              | j                  }| j        |j        z  |_        |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   s      r2   __or__zBits.__or__  r   r4   c               ,    |                      |          S r   )r   r   s     r2   __ror__zBits.__ror__  s     {{2r4   c                   t                               |          }t                              | j                  }| j        |j        z  |_        |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   rF   r   r;   r?   r%   r   s      r2   __xor__zBits.__xor__  s?     ''++NN4>**nr|3r4   c               ,    |                      |          S r   )r   r   s     r2   __rxor__zBits.__rxor__  r   r4   c               Z    t                               | |d          }t          |          S )znReturn whether bs is contained in the current bitstring.

        bs -- The bitstring to search for.

        F)bytealigned)r   findrp   )r0   r}   founds      r2   __contains__zBits.__contains__  s'     		$	66E{{r4   c                   t          |           dk    r0t          |                                 t          |           f          S t          | dd         | dd         z                                   t          |           f          S )z%Return an integer hash of the object.i  Ni   i)rb   hashr   ri   s    r2   __hash__zBits.__hash__  sr     t99T3444 $tt*tDEE{2;;==s4yyIJJJr4   c                (    t          |           dk    S )z:Return False if bitstring is empty, otherwise return True.r   )rb   ri   s    r2   __bool__zBits.__bool__  s    4yyA~r4   c                ,    t                      | _        dS )z&Reset the bitstring to an empty state.Nr   r%   ri   s    r2   _clearzBits._clear  s    !r4   r   c                  t          |t                    rt          j        |          | _        d
S t          |t
                    r |j                                        | _        d
S t          |t          t          t          f          r(t          j        t          |                    | _        d
S t          |t          j                  r-t          j        |                                          | _        d
S t          |t          j                  r|                     |j                   d
S t          |t$          j                  rt          |          | _        d
S t          |t&          j                  r-t          j        |                                          | _        d
S t          |t*          j                  r4|                     d                    d |D                                  d
S t          |t2          j                  r3t7          d| j        j         d| d| dt=          |           d	          t7          dt?          |           d	          )FSet bitstring from a bitstring, file, bool, array, iterable or string.r   c              3  h   K   | ]-}t          t          t          |                              V  .d S rB   )r]   r"   rp   .0r>   s     r2   	<genexpr>z4Bits._setauto_no_length_or_offset.<locals>.<genexpr>  s6      'E'EaCQLL(9(9'E'E'E'E'E'Er4   zMIt's no longer possible to auto initialise a bitstring from an integer. Use '(z)' instead of just 'z/' as this makes it clearer that a bitstring of z zero bits will be created.'Cannot initialise bitstring from type 'rL   N) rC   r]   r   str_to_bitstorer%   r   r   rI   	bytearray
memoryviewr   	frombytesioBytesIOgetvalueBufferedReaderrT   namerK   arrayr   r   r   _setbin_unsafer   rM   rN   r   r?   rV   r"   typer   s     r2   rD   z!Bits._setauto_no_length_or_offset  s4   a 	S-=a@@DNNN4   	S[--//DNNNE9j9:: 	S%/	!==DNNN2:&& 	S%/

==DNNN2,-- 	SMM!&!!!!!8,-- 	S%a[[DNNN5;'' 
	S%/		<<DNNN3<(( 	S'E'E1'E'E'E E EFFFFF7+,, 	S _%)^%<_ _?@_ _VW_ _;>q66_ _ _ ` ` ` Qd1ggQQQRRRr4   c                  |||                      |          S |d}t          |t          j                  r||                    dd          dz  |z
  }t          |d          \  }}||dz  z   |z   dz   dz  |z
  }||dz  z   |z   |                    dd          dz  k    rt          j        d          t          j	        |
                                |||z                                          |||z             | _        dS t          |t          j                  r|                     |j        ||           dS t          |t           t"          t$          t&          t(          t          j        t          j        t*          j        t,          j        t.          j        f
          r%t          j        dt3          |           d          t5          dt3          |           d	          )
r   Nr            zBBytesIO object is not long enough for specified length and offset.r   z)' when using explicit lengths or offsets.rL   )rD   rC   r   r   seekdivmodrO   rP   r   r   r   getslicer%   r   rT   r   r]   r   rI   r   r   rK   r   r   r   r  r   )r0   r   r'   r)   
byteoffset
bytelengths         r2   rQ   zBits._setauto  s    >fn44Q777>Fa$$ 		~1)F2!'!2!2J :>1F:Q>1DzQJ
Q&/!&&A,,2BBB-.rsss%/

ZV`I`=`0abbkk) )DNFa*++ 	MM!&&&111Fa#tUIz2:rO`"+U[#,H I I 	H)  +GTXYZT[T[  +G  +G  +G  H  H  HM$q''MMMNNNr4   rJ   c                   t          t          j        |          d          5 }|d}t          j        |                                dt          j                  }|dk    r(|j        | _        t          j	        ||          | _
        nt          j	        |          }|W|t          |          k    r(t          j        d| dt          |           d          |                    |d          | _
        n\|                    |||z             | _
        t          |           |k    r+t          j        d	| d
| dt          |           d          ddd           dS # 1 swxY w Y   dS )zUse file as source of bits.rbNr   )accessr   zThe offset of z' bits is greater than the file length (z bits).zCan't use a length of z bits and an offset of z bits as file length is only  bits.)openpathlibPathmmapfilenoACCESS_READr   r&   r   
frombufferr%   rb   rO   rP   r	  )r0   rJ   r'   r)   sourcemtemps          r2   rT   zBits._setfile   s   ',x(($// 	f6~	&--//1T5EFFFA{{!'!)!4Qv!F!F!F  *1-->D		))'5  7Iv  7I  7Ivyz~vv  7I  7I  7I  J  J  J%)]]64%@%@DNN%)]]66F?%K%KDN4yyF**'5  7ev  7e  7ent  7e  7e  TW  X\  T]  T]  7e  7e  7e  f  f  f#	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	f 	fs   D/EE#&E#babitarray.bitarrayc           
        |d}|t          |          k    r(t          j        d| dt          |           d          |t          ||d                    | _        d S ||z   t          |          k    r+t          j        d| d| dt          |           d          t          ||||z                      | _        d S )Nr   z
Offset of z" too large for bitarray of length rH   z and length of )rb   rO   rP   r   r%   )r0   r  r'   r)   s       r2   rU   zBits._setbitarray5  s    >FCGG)*kv*k*kadegahah*k*k*klll>%bk22DNNNR((-lllllbefhbibillln n n%b&)@&ABBDNNNr4   c                R    t                               |          }|j        | _        d S rB   )r   rF   r%   )r0   r}   r'   s      r2   _setbitszBits._setbitsB  s"    ''++r4   ffloatc                8    t          j        |          | _        d S rB   )r   p3binary2bitstorer%   r0   r  s     r2   _setp3binaryzBits._setp3binaryF      );A>>r4   c                8    t          j        |          | _        d S rB   )r   p4binary2bitstorer%   r#  s     r2   _setp4binaryzBits._setp4binaryI  r%  r4   c                8    t          j        |          | _        d S rB   )r   e4m3mxfp2bitstorer%   r#  s     r2   _sete4m3mxfpzBits._sete4m3mxfpL  r%  r4   c                8    t          j        |          | _        d S rB   )r   e5m2mxfp2bitstorer%   r#  s     r2   _sete5m2mxfpzBits._sete5m2mxfpO  r%  r4   c                8    t          j        |          | _        d S rB   )r   e3m2mxfp2bitstorer%   r#  s     r2   _sete3m2mxfpzBits._sete3m2mxfpR  r%  r4   c                8    t          j        |          | _        d S rB   )r   e2m3mxfp2bitstorer%   r#  s     r2   _sete2m3mxfpzBits._sete2m3mxfpU  r%  r4   c                8    t          j        |          | _        d S rB   )r   e2m1mxfp2bitstorer%   r#  s     r2   _sete2m1mxfpzBits._sete2m1mxfpX  r%  r4   c                8    t          j        |          | _        d S rB   )r   e8m0mxfp2bitstorer%   r#  s     r2   _sete8m0mxfpzBits._sete8m0mxfp[  r%  r4   c                8    t          j        |          | _        d S rB   )r   mxint2bitstorer%   r#  s     r2   	_setmxintzBits._setmxint^  s    )8;;r4   dataUnion[bytearray, bytes, List]c                R    t          j        t          |                    | _        dS )z.Set the data from a bytes or bytearray object.N)r   r   rI   r%   )r0   r>  r'   s      r2   	_setbyteszBits._setbytesa  s    !+E$KK88r4   Union[bytearray, bytes]c                |   |||                      |          S t          |          }|d}|t          |          dz  |z
  }nG||z   t          |          dz  k    r.t          j        d||z    dt          |          dz   d          t          j        |                              |||z             | _        dS )z[Set the data from a bytes or bytearray object, with optional offset and length truncations.Nr   r  zNot enough data present. Need z bits, have rH   )	rA  r   rb   rO   rP   r   r   getslice_msb0r%   )r0   r>  r'   r)   s       r2   rS   zBits._setbytes_with_truncatione  s    >fn>>$'''>F>YY]V+FFTQ..-.|vX^.|.|loptluluxyly.|.|.|}}}!+D11??QWXXr4   c                    t          |           dz  rt          j        d          | j                                        S )z,Return the data as an ordinary bytes object.r  zACannot interpret as bytes unambiguously - not multiple of 8 bits.)rb   rO   InterpretErrorr%   r   ri   s    r2   	_getbyteszBits._getbytest  s;    t99q= 	p*+nooo~%%'''r4   r   r         c                l    |                                  }d                    d |D                       }|S )zHReturn an approximation of the data as a string of printable characters.r   c              3  t   K   | ]3}|t           j        v rt          d |z             nt          |          V  4dS )   N)r   _unprintablechrr   s     r2   r   z+Bits._getbytes_printable.<locals>.<genexpr>  sD      ^^RS10A+A+AUQYs1vv^^^^^^r4   )rG  r   )r0   bytes_strings      r2   _getbytes_printablezBits._getbytes_printable}  s7    !!^^W]^^^^^r4   uintc                    |2t          | d          r"t          |           dk    rt          |           }||dk    rt          j        d          t	          j        ||d          | _        dS )z>Reset the bitstring to have given unsigned int interpretation.Nrb   r   z<A non-zero length must be specified with a uint initialiser.Fr   rb   rO   rP   r   int2bitstorer%   )r0   rR  r'   s      r2   _setuintzBits._setuint  si     >gdE22>s4yyA~~YYF>Vq[[)*hiii)6tVUKKr4   c                    t          |           dk    rt          j        d          | j                                        S )zReturn data as an unsigned int.r   z7Cannot interpret a zero length bitstring as an integer.)rb   rO   rF  r%   slice_to_uintri   s    r2   _getuintzBits._getuint  s7    t99>>*+deee~++---r4   int_c                    |2t          | d          r"t          |           dk    rt          |           }||dk    rt          j        d          t	          j        ||d          | _        dS )z<Reset the bitstring to have given signed int interpretation.Nrb   r   z<A non-zero length must be specified with an int initialiser.TrT  )r0   rZ  r'   s      r2   _setintzBits._setint  si     >gdE22>s4yyA~~YYF>Vq[[)*hiii)6tVTJJr4   c                    t          |           dk    rt          j        d          | j                                        S )z-Return data as a two's complement signed int.r   z:Cannot interpret bitstring without a length as an integer.)rb   rO   rF  r%   slice_to_intri   s    r2   _getintzBits._getint  s7    t99>>*+ghhh~**,,,r4   uintbec                    |2t          | d          r"t          |           dk    rt          |           }||dk    rt          j        d          t	          j        ||d          | _        dS )z>Set the bitstring to a big-endian unsigned int interpretation.Nrb   r   z>A non-zero length must be specified with a uintbe initialiser.FrT  )r0   r`  r'   s      r2   
_setuintbezBits._setuintbe  sg    >gdE22>s4yyA~~YYF>Vq[[)*jkkk)6vvuMMr4   c                    t          |           dz  r%t          j        dt          |            d          |                                 S )z:Return data as a big-endian two's complement unsigned int.r  1Big-endian integers must be whole-byte. Length = r  )rb   rO   rF  rY  ri   s    r2   
_getuintbezBits._getuintbe  sJ    t99q= 	r*+p_bcg_h_h+p+p+pqqq}}r4   intbec                    |2t          | d          r"t          |           dk    rt          |           }||dk    rt          j        d          t	          j        ||d          | _        dS )z8Set bitstring to a big-endian signed int interpretation.Nrb   r   z=A non-zero length must be specified with a intbe initialiser.TrT  )r0   rf  r'   s      r2   	_setintbezBits._setintbe  sg    >gdE22>s4yyA~~YYF>Vq[[)*ijjj)6ufdKKr4   c                    t          |           dz  r%t          j        dt          |            d          |                                 S )z8Return data as a big-endian two's complement signed int.r  rd  r  )rb   rO   rF  r_  ri   s    r2   	_getintbezBits._getintbe  sJ    t99q= 	r*+p_bcg_h_h+p+p+pqqq||~~r4   uintlec                    |2t          | d          r"t          |           dk    rt          |           }||dk    rt          j        d          t	          j        ||d          | _        d S )Nrb   r   z>A non-zero length must be specified with a uintle initialiser.Fr   rb   rO   rP   r   intle2bitstorer%   )r0   rk  r'   s      r2   
_setuintlezBits._setuintle  sg    >gdE22>s4yyA~~YYF>Vq[[)*jkkk)8OOr4   c                    t          |           dz  r%t          j        dt          |            d          t          j        | j                                        ddd                   }|                                S )z*Interpret as a little-endian unsigned int.r  4Little-endian integers must be whole-byte. Length = r  N)rb   rO   rF  r   r   r%   r   rX  r   s     r2   
_getuintlezBits._getuintle  sw    t99q= 	u*+sbefjbkbk+s+s+sttt 6 6 8 82 >??!!!r4   intlec                    |2t          | d          r"t          |           dk    rt          |           }||dk    rt          j        d          t	          j        ||d          | _        d S )Nrb   r   z>A non-zero length must be specified with an intle initialiser.Trm  )r0   rt  r'   s      r2   	_setintlezBits._setintle  sg    >gdE22>s4yyA~~YYF>Vq[[)*jkkk)8MMr4   c                    t          |           dz  r%t          j        dt          |            d          t          j        | j                                        ddd                   }|                                S )z(Interpret as a little-endian signed int.r  rq  r  Nrr  )rb   rO   rF  r   r   r%   r   r^  r   s     r2   	_getintlezBits._getintle  su    t99q= 	u*+sbefjbkbk+s+s+sttt 6 6 8 82 >??   r4   c                N    |                                  }t          j        |         S rB   )rY  r   lut_binary8_to_floatr0   us     r2   _getp4binaryzBits._getp4binary      MMOO033r4   c                N    |                                  }t          j        |         S rB   )rY  r   rz  r{  s     r2   _getp3binaryzBits._getp3binary  r~  r4   c                N    |                                  }t          j        |         S rB   )rY  r   lut_int_to_floatr{  s     r2   _gete4m3mxfpzBits._gete4m3mxfp      MMOO$5a88r4   c                N    |                                  }t          j        |         S rB   )rY  r   r  r{  s     r2   _gete5m2mxfpzBits._gete5m2mxfp  r  r4   c                N    |                                  }t          j        |         S rB   )rY  r   r  r{  s     r2   _gete3m2mxfpzBits._gete3m2mxfp      MMOO,Q//r4   c                N    |                                  }t          j        |         S rB   )rY  r   r  r{  s     r2   _gete2m3mxfpzBits._gete2m3mxfp  r  r4   c                N    |                                  }t          j        |         S rB   )rY  r   r  r{  s     r2   _gete2m1mxfpzBits._gete2m1mxfp  r  r4   c                d    |                                  dz
  }|dk    rt          d          S d|z  S )NrH     nang       @)rY  r   r{  s     r2   _gete8m0mxfpzBits._gete8m0mxfp  s2    MMOOc!88<<axr4   c                N    |                                  }t          |          dz  S )Ng      ?)r_  r   r{  s     r2   	_getmxintzBits._getmxint  s     LLNNQxx'!!r4   
big_endianc                    |2t          | d          r"t          |           dk    rt          |           }||dvrt          j        d          t	          j        |||          | _        d S )Nrb   r      r   @   zEA length of 16, 32, or 64 must be specified with a float initialiser.)r   rb   rO   rP   r   float2bitstorer%   )r0   r  r'   r  s       r2   	_setfloatzBits._setfloat   si    >gdE22>s4yyA~~YYF>V<77)*qrrr)8FJOOr4   c                4    |                      ||d           d S )NTr  r0   r  r'   s      r2   _setfloatbezBits._setfloatbe  s    q&$'''''r4   c                    ddddt          |                    }t          j        || j                                                  d         S )z4Interpret the whole bitstring as a big-endian float.z>ez>fz>dr  r   rb   structunpackr%   r   r0   fmts     r2   _getfloatbezBits._getfloatbe
  A    Tt,,SYY7}S$."8"8":":;;A>>r4   c                4    |                      ||d           d S )NFr  r  s      r2   _setfloatlezBits._setfloatle  s    q&%(((((r4   c                    ddddt          |                    }t          j        || j                                                  d         S )z7Interpret the whole bitstring as a little-endian float.z<ez<fz<dr  r   r  r  s     r2   _getfloatlezBits._getfloatle  r  r4   c                N    | t          d          z   }|                                S Nr  )r   r  r0   zero_paddeds     r2   _getbfloatbezBits._getbfloatbe  s#    T"XXo&&(((r4   Union[float, str]c                z    ||dk    rt          j        d| d          t          j        |d          | _        d S )Nr  0bfloats must be length 16, received a length of r  TrO   rP   r   bfloat2bitstorer%   r  s      r2   _setbfloatbezBits._setbfloatbe  sF    &B,,)*k]c*k*k*klll)9!TBBr4   c                N    t          d          | z   }|                                S r  )r   r  r  s     r2   _getbfloatlezBits._getbfloatle   s#    2hho&&(((r4   c                z    ||dk    rt          j        d| d          t          j        |d          | _        d S )Nr  r  r  Fr  r  s      r2   _setbfloatlezBits._setbfloatle$  sF    &B,,)*k]c*k*k*klll)9!UCCr4   ic                    t           j        j        rt          j        d          t	          j        |          | _        dS )z{Initialise bitstring with unsigned exponential-Golomb code for integer i.

        Raises CreationError if i < 0.

        -Exp-Golomb codes cannot be used in lsb0 mode.N)rO   optionslsb0rP   r   ue2bitstorer%   r0   r  s     r2   _setuezBits._setue)  s;     ! 	[)*YZZZ)5a88r4   Tuple[int, int]c                   t           j        j        rt          j        d          |}	 | |         s|dz  }| |         n"# t          $ r t          j        d          w xY w||z
  }d|z  dz
  }|dk    r^||z   dz   t          |           k    rt          j        d          || |dz   |dz   |z                                            z  }||dz   z  }n|dk    sJ |dz  }||fS )zReturn interpretation of next bits as unsigned exponential-Golomb code.

        Raises ReadError if the end of the bitstring is encountered while
        reading the code.

        -Exp-Golomb codes cannot be read in lsb0 mode.   .Read off end of bitstring trying to read code.r   )rO   r  r  	ReadError
IndexErrorrb   rY  )r0   r5   oldposleadingzeroscodenums        r2   _readuezBits._readue3  s3    ! 	W%&UVVV	X3i q 3i  	X 	X 	X%&VWWW	XV|$)!\!A%D		11)*Z[[[tC!GC!Gl$::;DDFFFG<!##CCa<<<<1HC|s	   ? Ac                l    	 |                      d          S # t          j        $ r t          j        w xY wr9   )r  rO   r  rF  ri   s    r2   _getuezBits._getueN  >    	+<<??"" 	+ 	+ 	+**	+    3c                l    	 |                      d          S # t          j        $ r t          j        w xY wr9   )_readserO   r  rF  ri   s    r2   _getsezBits._getseT  r  r  c                l    	 |                      d          S # t          j        $ r t          j        w xY wr9   )_readuierO   r  rF  ri   s    r2   _getuiezBits._getuieZ  @    	+==###" 	+ 	+ 	+**	+r  c                l    	 |                      d          S # t          j        $ r t          j        w xY wr9   )_readsierO   r  rF  ri   s    r2   _getsiezBits._getsie`  r  r  c                    t           j        j        rt          j        d          t	          j        |          | _        dS )zGInitialise bitstring with signed exponential-Golomb code for integer i.r  N)rO   r  r  rP   r   se2bitstorer%   r  s     r2   _setsezBits._setsef  s9    ! 	[)*YZZZ)5a88r4   c                ^    |                      |          \  }}|dz   dz  }|dz  r||fn| |fS )zReturn interpretation of next bits as a signed exponential-Golomb code.

        Advances position to after the read code.

        Raises ReadError if the end of the bitstring is encountered while
        reading the code.

        r  r  )r  )r0   r5   r  r  s       r2   r  zBits._readsel  sD     ||C((q[Q"Q;53xxaRI5r4   c                    t           j        j        rt          j        d          t	          j        |          | _        dS )zInitialise bitstring with unsigned interleaved exponential-Golomb code for integer i.

        Raises CreationError if i < 0.

        r  N)rO   r  r  rP   r   uie2bitstorer%   r  s     r2   _setuiezBits._setuiey  s;     ! 	[)*YZZZ)6q99r4   c                   t           j        j        rt          j        d          	 d}| |         s"|dz  }|dz  }|| |         z  }|dz  }| |         "|dz  }n"# t          $ r t          j        d          w xY w|dz
  |fS )zReturn interpretation of next bits as unsigned interleaved exponential-Golomb code.

        Raises ReadError if the end of the bitstring is encountered while
        reading the code.

        r  r  r  )rO   r  r  r  r  r0   r5   r  s      r2   r  zBits._readuie  s     ! 	W%&UVVV		XG3i qA49$q	 3i 
 1HCC 	X 	X 	X%&VWWW	X{Cs   1A A8c                    t           j        j        rt          j        d          t	          j        |          | _        dS )zSInitialise bitstring with signed interleaved exponential-Golomb code for integer i.r  N)rO   r  r  rP   r   sie2bitstorer%   r  s     r2   _setsiezBits._setsie  s9    ! 	[)*YZZZ)6q99r4   c                    |                      |          \  }}|sd|fS 	 | |         r| |dz   fn||dz   fS # t          $ r t          j        d          w xY w)zReturn interpretation of next bits as a signed interleaved exponential-Golomb code.

        Advances position to after the read code.

        Raises ReadError if the end of the bitstring is encountered while
        reading the code.

        r   r  r  )r  r  rO   r  r  s      r2   r  zBits._readsie  s     }}S)) 	c6M	X*.s)KWHcAg&&'379KK 	X 	X 	X%&VWWW	Xs	   7 AvalueUnion[bool, str]c                    |dv rt          d          | _        d S |dv rt          d          | _        d S t          j        d| d          )N)r  True1r  )r   False0r  zCannot initialise boolean with rH   )r   r%   rO   rP   )r0   r  s     r2   _setboolzBits._setbool  s[     $$$%c]]DNNN'''%c]]DNNN)*TE*T*T*TUUUr4   c                    | d         S r9   rl   ri   s    r2   _getboolzBits._getbool  s    Awr4   c                    d S rB   rl   ri   s    r2   _getpadzBits._getpad  s    tr4   c                .    t          |          | _        d S rB   r   )r0   r  r'   s      r2   _setpadzBits._setpad  s    !&))r4   	binstringc                8    t          j        |          | _        dS )z4Reset the bitstring to the value given in binstring.N)r   bin2bitstorer%   r0   r  r'   s      r2   _setbin_safezBits._setbin_safe      )6yAAr4   c                8    t          j        |          | _        dS )zXSame as _setbin_safe, but input isn't sanity checked. binstring mustn't start with '0b'.N)r   bin2bitstore_unsafer%   r  s      r2   r  zBits._setbin_unsafe  s    )=iHHr4   c                4    | j                                         S )z)Return interpretation as a binary string.)r%   slice_to_binri   s    r2   r   zBits._getbin      ~**,,,r4   	octstringc                8    t          j        |          | _        dS )z9Reset the bitstring to have the value given in octstring.N)r   oct2bitstorer%   )r0   r  r'   s      r2   _setoctzBits._setoct  r  r4   c                4    | j                                         S )z)Return interpretation as an octal string.)r%   slice_to_octri   s    r2   _getoctzBits._getoct  r   r4   	hexstringc                8    t          j        |          | _        dS )z9Reset the bitstring to have the value given in hexstring.N)r   hex2bitstorer%   )r0   r  r'   s      r2   _sethexzBits._sethex  r  r4   c                4    | j                                         S )zReturn the hexadecimal representation as a string.

        Raises an InterpretError if the bitstring's length is not a multiple of 4.

        )r%   slice_to_hexri   s    r2   r   zBits._gethex  s     ~**,,,r4   c                *    t          | j                  S r   rb   r%   ri   s    r2   r   zBits._getlength  s    4>"""r4   c                j    |                                  }| j                                        |_        |S )z<Create and return a new copy of the Bits (always in memory).)r?   r%   r   )r0   s_copys     r2   r   z
Bits._copy  s.     !!>//11r4   startendc                n    |                                  }| j                            ||          |_        |S )z7Used internally to get a slice, without error checking.)r?   r%   r	  r0   r  r  r}   s       r2   _slicezBits._slice  s/    ^^~..uc::	r4   c                    ||k    r|                                  S ||k     sJ d| d|             |                                  }| j                            ||          |_        |S )zlUsed internally to get a slice, without error checking.
        Uses MSB0 bit numbering even if LSB0 is set.zstart=, end=)r?   r%   rD  r  s       r2   r   zBits._absolute_slice  sn     %<<>>###s{{{7U77#77{{{^^~33E3??	r4   r   .Tuple[Union[float, int, str, None, Bits], int]c                   t          j        ||          }|j        K|j        t          |           |z
  k    r0t	          j        d|j         dt          |           |z
   d          	 |                    | |          }t          |t                    r|S |J |||j        z   fS # t          $ r t          d| d|           w xY w)z8Reads a token from the bitstring and returns the result.Nz/Reading off the end of the data. Tried to read z bits when only z available.zCan't parse token :)r   	get_dtypera   rb   rO   r  read_fnrC   tupleKeyErrorrX   )r0   r   r5   r'   dtypevals         r2   
_readtokenzBits._readtoken  s   (v66?&5?SYY_+L+L% 'k-2_'k 'kNQRViiZ]o'k 'k 'k l l l	C--c**C#u%% 2
)))C%/111 	C 	C 	CA$AAAABBB	Cs   ),B& B& & Cc               0    | xj         |j         z  c_         dS )z4Add a bitstring to the RHS of the current bitstring.N)r%   r   s     r2   r   zBits._addright  s    ",&r4   c                   |j         j        r(|j                                         | j         z   | _         dS |j         | j         z   | _         dS )z-Prepend a bitstring to the current bitstring.N)r%   r/   r   r   s     r2   r   zBits._addleft  sC    <! 	;\//11DNBDNNN\DN:DNNNr4   bitsc               4   d|cxk    rt          |           k    sn J |dk    r|                                 S |                     d|          }|t          |           k    r|                                  |S | j                            |d          | _        |S )zITruncate bits from the start of the bitstring. Return the truncated bits.r   Nrb   r?   r   r   r%   rD  r0   r%  truncated_bitss      r2   _truncateleftzBits._truncateleft  s    D%%%%CII%%%%%%199>>###--a663t99KKMMM!!55dDAAr4   c               p   d|cxk    rt          |           k    sn J |dk    r|                                 S |                     t          |           |z
  t          |                     }|t          |           k    r|                                  |S | j                            d|           | _        |S )zGTruncate bits from the end of the bitstring. Return the truncated bits.r   Nr'  r(  s      r2   _truncaterightzBits._truncateright$  s    D%%%%CII%%%%%%199>>###--c$ii$.>D		JJ3t99KKMMM!!55dTEBBr4   c               d    d|cxk    rt          |           k    sn J |j        | j        ||<   dS )zInsert bs at pos.r   Nr  r0   r}   r5   s      r2   _insertzBits._insert0  sD    C$$$$3t99$$$$$$#%<sCx r4   c                   d|cxk    rt          |           k    sn J || u r
|dk    sJ dS |j        | j        ||t          |          z   <   dS )zOverwrite with bs at pos.r   Nr  r.  s      r2   
_overwritezBits._overwrite6  sk    C$$$$3t99$$$$$$::!8888F-/\sC#b''M)***r4   c          	         d|cxk    rt          |           k    sn J ||z   t          |           k    s J d| d| dt          |                        | j        |||z   = dS )zDelete bits at pos.r   zpos=z, bits=z, len=Nr  )r0   r%  r5   s      r2   _deletezBits._delete?  s    C$$$$3t99$$$$$$TzSYY&&&(Rs(R(R4(R(Rs4yy(R(R&&&N3d
?+r4   c                    ||z
  dz  dk    sJ t          j        | j                            ||                                          ddd                   | j        ||<   dS )zReverse bytes in-place.r  r   Nrr  )r   r   r%   r	  r   r0   r  r  s      r2   _reversebyteszBits._reversebytesF  sk    eq A%%%%$,$6t~7N7NuVY7Z7Z7b7b7d7deieigiei7j$k$kuSy!!!r4   c               v    d|cxk    rt          |           k     sn J | j                            |           dS )zFlip bit at pos 1<->0.r   N)rb   r%   invert)r0   r5   s     r2   _invertzBits._invertK  sI    C#####d))######c"""""r4   c                8    | j                                          dS )zInvert every bit.N)r%   r8  ri   s    r2   r   zBits._invert_allP  s    r4   c                   d|cxk     rt          |           k    sn J |                     t          |                     |                     |           | S )z2Shift bits by n to the left in place. Return self.r   )rb   r   r   r*  r   s     r2   _ilshiftzBits._ilshiftT  s^    1!!!!D		!!!!!!tAww1r4   c                   d|cxk     rt          |           k    sn J |                     t          |                     |                     |           | S )z3Shift bits by n to the right in place. Return self.r   )rb   r   r   r,  r   s     r2   _irshiftzBits._irshift[  s^    1!!!!D		!!!!!!d1ggAr4   c                  |dk    sJ |dk    r|                                   n`d}t          |           }|dz  |k     r#|                     |            |dz  }|dz  |k     #|                     | d||z
  |z                      | S )z3Concatenate n copies of self in place. Return self.r   r  r  )r   rb   r   )r0   r   r  old_lens       r2   r   z
Bits._imulb  s    Avvvv66KKMMMMA$iiGa%!))t$$$Q a%!)) NN41q5G"3 34555r4   c                *    |                                  S rB   )r   ri   s    r2   _getbitszBits._getbitsp  s    zz||r4   c           	     .   |dn|dk     r|t          |           z   n|}|t          |           n|dk     r|t          |           z   n|}d|cxk    r|cxk    rt          |           k    s(n t          dt          |            d| d| d          ||fS )zAValidate start and end and return them as positive bit positions.Nr   z-Invalid slice positions for bitstring length z: start=r  rH   )rb   rX   r5  s      r2   _validate_slicezBits._validate_slices  s    ]eaiiT):):U;c$iiiaS3t99__SE----S----CII----sSQUYYss`essmpssstttczr4   r  !Union[str, List[Union[str, int]]]5List[Union[int, float, str, Bits, bool, bytes, None]]c                ,     | j         |dfi |d         S )a  Interpret the whole bitstring using fmt and return list.

        fmt -- A single string or a list of strings with comma separated tokens
               describing how to interpret the 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.

        Raises ValueError if the format is not understood. If not enough bits
        are available then all bits to the end of the bitstring will be used.

        See the docstring for 'read' for token examples.

        r   )	_readlist)r0   r  r1   s      r2   r  zBits.unpack{  s%     t~c1////22r4   (Union[str, List[Union[str, int, Dtype]]]ATuple[List[Union[int, float, str, Bits, bool, bytes, None]], int]c                b   t          |t                    r|g}g }|D ]}t          |t          j                  r$|                    t          d|                     @t          |t
                    r|                    |           kt          j        |          }|D ]{}	 t          j        |fi |\  }}	|                    t          ||	                     <# t          $ r3 |                    t          dt          |                               Y xw xY w|                     ||          S )Nr%  )rC   r]   rM   rN   appendr   r   preprocess_tokensparse_name_length_tokenrX   r"   _read_dtype_list)
r0   r  r5   r1   
dtype_listf_item
token_listtr   r'   s
             r2   rH  zBits._readlist  sY   c3 	%C
 	? 	?F&'"233 ?!!%"7"78888FE** 
?!!&))))"4V<<
# ? ?A?','DQ'Q'Q&'Q'Qf #))%f*=*=>>>> & A A A"))%A*?*?@@@@@A? $$Z555s   !C:DDdtypesList[Dtype]c           
        d}d}|D ]Y}|j         d u o|j         }|r|rt          j        d          d}.|r)|j        rt          j        d| d          ||j         z  }Zg }|D ]}|j         d u o|j         }|r{t	          |           |z
  }t          ||z
  d          }	t          |	|j                  \  }
}|dk    r#t          d|j	         d|j         d	|	 d
          t          |j	        |
          }|j         !|                    | |          }||j         z  }n|                    | |          \  }}||                    |           ||fS )NFr   z7It's not possible to have more than one 'filler' token.Tz4It's not possible to parse a variable length token 'z' after a 'filler' token.zThe 'z4' type must have a bit length that is a multiple of z so cannot be created from the z1 bits that are available for this stretchy token.)ra   variable_lengthrO   r   rb   maxr  bits_per_itemrX   r   r   r  rL  )r0   rT  r5   has_stretchy_tokenbits_after_stretchy_tokenr   stretchyvalsbits_remainingra   items	remainderr!  s                r2   rO  zBits._read_dtype_list  s   "$%! 		= 		=E$.Lu7L3LH =% e#/*cddd%)""# =( C#/  +Baf  +B  +B  +B  C  C  C)U_<)  	! 	!E$.Lu7L3LH 	1!$TS1J JANN	#))U5H#I#I y>>$w
 w w`e`s w w:Cw w wx x x ej%00*mmD#..u& ==s33SC   Syr4   r   Optional[bool]Union[Tuple[int], Tuple[()]]c               
   t                               |          }t          |          dk    rt          d          |                     ||          \  }}|t
          j        j        n|}|                     ||||          }|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.

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

        r   Cannot find an empty bitstring.)	r   rF   rb   rX   rD  rO   r  r   _findr0   r}   r  r  r   r  ps          r2   r   z	Bits.find  s    , ''++r77a<<>???))%55
s.9.AY**{JJr5#r**r4   c                   ||k    sJ t           j        j        sJ t           j                            t          ||d           t          |                     }|                     |j        |j	                  \  }}| 
                    ||||          }|r)t          |           |d         z
  t          |          z
  fS dS Nr   rl   )rO   r  r  bitstoreoffset_slice_indices_lsb0r   rb   rD  r  stop_rfind_msb0	r0   r}   r  r  r   	new_slice
msb0_startmsb0_endrg  s	            r2   
_find_lsb0zBits._find_lsb0  s    |||| %%%%&@@ucSWAXAXZ]^bZcZcdd	#33IOY^TT
HRX{CC 	II!$s2ww.002r4   c                \    | j                             |j         |||          }|dk    rdn|fS )z)Find first occurrence of a binary string.rr  rl   )r%   r   r0   r}   r  r  r   rg  s         r2   
_find_msb0zBits._find_msb0  s3    NeS+FF"WWrr1$&r4   countIterable[int]c                    ||dk     rt          d          t                              |          }|                     ||          \  }}|t          j        j        n|}|                     |||||          S )as  Find all occurrences of bs. Return generator of bit positions.

        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).
        count -- The maximum number of occurrences to find.
        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.

        Note that all occurrences of bs are found, even if they overlap.

        Nr   zIn findall, count must be >= 0.)rX   r   rF   rD  rO   r  r   _findall)r0   r}   r  r  rv  r   r  s          r2   findallzBits.findall  s|    $ >???''++))%55
s.9.AY**{}}RUB777r4   c              #     K   d}| j                             |j         |||          D ]}|	||k    r d S |dz  }|V  d S )Nr   r  )r%   findall_msb0)r0   r}   r  r  rv  r   cr  s           r2   _findall_msb0zBits._findall_msb0  s`      ,,R\5#{SS 	 	A Q%ZZFAGGGGr4   c           	   #     K   ||k    sJ t           j        j        sJ t           j                            t          ||d           t          |                     }|                     |j        |j	                  \  }}d}	t          dt          |          dz            }
t          |
t          |          z   ||z
            }t          |||z
            }	 t          |                     ||||z   d d                    }|s||k    rd S t          |||
z
            }I|rT||	|k    rd S |	dz  }	t          |           |                                z
  t          |          z
  }|r	|dz  dk    r|V  |Tt          |||
z
            }||k    rd S )	Nr   i    P   TF)r  r  rv  r   r  r  )rO   r  r  rj  rk  r   rb   rD  r  rl  rX  r   listr~  pop)r0   r}   r  r  rv  r   ro  rp  rq  r}  	increment
buffersizer5   r   lsb0_poss                  r2   _findall_lsb0zBits._findall_lsb0  s     |||| %%%%&@@ucSWAXAXZ]^bZcZcdd	#33IOY^TT
H c"ggl++	SWW,h.CDD
*h344	++BcsZ?OW[in+ooppE *$$F*cIo66 #$eFQt99uyy{{2SWW<" #hla&7&7"NNN  # j#	/22Cj  #	r4   c               
   t                               |          }|                     ||          \  }}|t          j        j        n|}t          |          dk    rt          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.

        Nr   rd  )	r   rF   rD  rO   r  r   rb   rX   _rfindrf  s          r2   rfindz
Bits.rfind;  s    & ''++))%55
s.9.AY**{r77a<<>???KKE3++r4   c                \    | j                             |j         |||          }|dk    rdn|fS )z)Find final occurrence of a binary string.rr  rl   )r%   r  rt  s         r2   rm  zBits._rfind_msb0V  s3    N  uc;GG"WWrr1$&r4   c                   ||k    sJ t           j        j        sJ t           j                            t          ||d           t          |                     }|                     |j        |j	                  \  }}| 
                    ||||          }|r)t          |           |d         z
  t          |          z
  fS dS ri  )rO   r  r  rj  rk  r   rb   rD  r  rl  ru  rn  s	            r2   _rfind_lsb0zBits._rfind_lsb0[  s    |||| %%%%&@@ucSWAXAXZ]^bZcZcdd	#33IOY^TT
HOOB
HkBB 	II!$s2ww.002r4   Iterator[Bits]c              #  v  K   |                      ||          \  }}||dk     rt          d          |dk    rt          d          d}|||k     rg|dz  }|                     |t          ||z   |                    }t	          |          dk    rdS |V  t	          |          |k    rdS ||z  }|a||k     gdS )a  Return bitstring generator by cutting into bits sized chunks.

        bits -- The size in bits of the bitstring chunks to generate.
        start -- The bit position to start the first cut. Defaults to 0.
        end -- The bit position one past the last bit to use in the cut.
               Defaults to len(self).
        count -- If specified then at most count items are generated.
                 Default is to cut as many times as possible.

        Nr   z Cannot cut - count must be >= 0.zCannot cut - bits must be >= 0.r  )rD  rX   r  r   rb   )	r0   r%  r  r  rv  start_end_r}  	nextchunks	            r2   cutzBits.cuth  s       ++E377?@@@199>???mq5yyFAFCt,D,DEEI9~~""OOO9~~%%dNF mq5yy 	r4   	delimiterIterable[Bits]c              #    K   t                               |          }t          |          dk    rt          d          |                     ||          \  }}|t
          j        j        n|}||dk     rt          d          |dk    rdS t          j	        | j
        ||          } |||          }|s|                     ||          V  dS |                     ||d                   V  |d         x}	}
d}|||k     rp|
t          |          z  }
 ||
|          }|s|                     |	|          V  dS |dz  }|                     |	|d                   V  |d         x}	}
|j||k     pdS )a  Return bitstring generator by splitting using a delimiter.

        The first item returned is the initial bitstring before the delimiter,
        which may be an empty bitstring.

        delimiter -- The bitstring used as the divider.
        start -- The bit position to start the split. Defaults to 0.
        end -- The bit position one past the last bit to use in the split.
               Defaults to len(self).
        count -- If specified then at most count items are generated.
                 Default is to split as many times as possible.
        bytealigned -- If True splits will only occur on byte boundaries.

        Raises ValueError if the delimiter is empty.

        r   z split delimiter cannot be empty.Nz"Cannot split - count must be >= 0.)r}   r   )r  r  r  )r   rF   rb   rX   rD  rO   r  r   	functoolspartialru  r  )r0   r  r  r  rv  r   bytealigned_r  r   startposr5   r}  s               r2   splitz
Bits.split  s     $ ..y99	y>>Q?@@@))%55
s>I>QY.::WbABBBA::Fdo)VVV3''' 	++eS)))))Fkk%q*****q!3mq5yy3y>>!CACS)))E kk(C00000FA++ha11111"1X%Hs mq5yy 	r4   sequenceIterable[Any]c                   |                                  }t          |           dk    r4|D ]/}|                    t                              |                     0|S t          |          }	 |                    t                              t          |                               n# t          $ r |cY S w xY w|D ]D}|                    |            |                    t                              |                     E|S )zkReturn concatenation of bitstrings joined by self.

        sequence -- A sequence of bitstrings.

        r   )r?   rb   r   r   rF   rh   nextStopIteration)r0   r  r   itemsequence_iters        r2   r   z	Bits.join  s    NNt99>>  > >D66t<<====H NNMD66tM7J7JKKLLLL    % > >D!!!D66t<<====Hs   ,:B' 'B65B6c                4    | j                                         S )zReturn the bitstring as bytes, padding with zero bits if needed.

        Up to seven zero bits will be added at the end to byte align.

        )r%   r   ri   s    r2   r   zBits.tobytes  s     ~%%'''r4   c                    | j         j        -| j                             dt          |                     j        S | j         j        S )z+Convert the bitstring to a bitarray object.Nr   )r%   modified_lengthr	  rb   	_bitarrayri   s    r2   
tobitarrayzBits.tobitarray  s9    >)5>**1c$ii88BB>++r4   r   c                    d}|                      |          D ])}|                    |                                           *dS )zWrite the bitstring to a file object, padding with zero bits if needed.

        Up to seven zero bits will be added at the end to byte align.

        i   2N)r  writer   )r0   r  
chunk_sizechunks       r2   tofilezBits.tofile  sK     +
XXj)) 	% 	%EGGEMMOO$$$$	% 	%r4   prefixc                    |                      |          }|                     ||          \  }}||t          |          z   k    r*|                     ||t          |          z             |k    ndS )zReturn whether the current bitstring starts with prefix.

        prefix -- The bitstring to search for.
        start -- The bit position to start from. Defaults to 0.
        end -- The bit position to end at. Defaults to len(self).

        FrF   rD  rb   r  )r0   r  r  r  s       r2   
startswithzBits.startswith  ss     ++F33))%55
sDG5SVW]S^S^K^D^D^t{{5%#f++"566&@@diir4   suffixc                    |                      |          }|                     ||          \  }}|t          |          z   |k    r*|                     |t          |          z
  |          |k    ndS )zReturn whether the current bitstring ends with suffix.

        suffix -- The bitstring to search for.
        start -- The bit position to start from. Defaults to 0.
        end -- The bit position to end at. Defaults to len(self).

        Fr  )r0   r  r  r  s       r2   r   zBits.endswith  sp     ++F33))%55
s@EF@SWZ@Z@Zt{{3V,c22f<<`eer4   Optional[Iterable[int]]c                    t          |          rdnd}|5|r| j                                        n| j                                         S |D ]#}| j                            |          |k    r dS $dS )aX  Return True if one or many bits are all set to bool(value).

        value -- If value is True then checks for bits set to 1, otherwise
                 checks for bits set to 0.
        pos -- An iterable of bit positions. Negative numbers are treated in
               the same way as slice indices. Defaults to the whole bitstring.

        r  r   NFT)rp   r%   all_setany_setr   r0   r  r5   rg  s       r2   allzBits.all  s     %[['a;/4V4>))+++dn>T>T>V>V:VV 	 	A~&&q))U22uu 3tr4   c                    t          |          rdnd}|5|r| j                                        n| j                                         S |D ]#}| j                            |          |k    r dS $dS )a[  Return True if any of one or many bits are set to bool(value).

        value -- If value is True then checks for bits set to 1, otherwise
                 checks for bits set to 0.
        pos -- An iterable of bit positions. Negative numbers are treated in
               the same way as slice indices. Defaults to the whole bitstring.

        r  r   NTF)rp   r%   r  r  r   r  s       r2   anyzBits.any  s     %[['a;/4V4>))+++dn>T>T>V>V:VV 	 	A~&&q))U22tt 3ur4   c                b    | j                             d          }|r|nt          |           |z
  S )zReturn count of total number of either zero or one bits.

        value -- If bool(value) is True then bits set to 1 are counted, otherwise bits set
                 to 0 are counted.

        >>> Bits('0xef').count(1)
        7

        r  )r%   rv  rb   )r0   r  rv  s      r2   rv  z
Bits.count#  s3     $$Q''4uu3t99u#44r4   bits_per_groupsepr   r   colour_start
colour_endwidthTuple[str, int]c                  
 |j         |j        dk    rt          j        |j        dk    rt	          j        d|          j         |dk    rt           |                     }n|j        dv rt          j        j	        sdnd
dt          |j                 j
        %t          |j                 
                    |          |                    
fd|                     |          D                       }t          |          }|dnt          |t          |          z
  d          }	||z   |z   }t          j        j	        r	d	|	z  |z   }n|d	|	z  z  }||fS )
NrI   rp   rR  r   )r   octr   r%  rI   <>c              3  V   K   | ]#}t           |                    d   V  $dS ) N)r]   )r   rE   alignchars_per_grouprc   s     r2   r   z$Bits._format_bits.<locals>.<genexpr>A  sD      ii1Cq		NNFUFOFFFiiiiiir4   r  )rc   r   r   rQ  r   r  r]   rO   r  r  bitlength2chars_fnr   r  rb   rX  )r%  r  r  r   r  r  r  r>   
chars_usedpadding_spacesr  r  rc   s             @@@r2   _format_bitszBits._format_bits1  sk    :  -F:#-fnEELFQFF4LL!!AA !:)OOOXaXiXnOCCtwEOej)<H"0"<"O"OP^"_"_iiiiiiPTPXPXYgPhPhiiiiiAVV
#mUSVV^Q1G1G1z)! 	&n$q(AA~%%A*}r4   Optional[str]c                n    |t           |         j        dS t           |                             |           S )zQHow many characters are needed to represent a number of bits with a given format.Nr   )r   r  )r  r  s     r2   _chars_per_groupzBits._chars_per_groupM  s4     ;.-@H1c"55nEEEr4   c                ^    | dvrt           dt          |                              d          z  S )zBHow many bits are represented by each character of a given format.)r   r  r   rI      )rX   r   r  )r  s    r2   _bits_per_charzBits._bits_per_charT  s4     444^C(;;B????r4   dtype1dtype2Optional[Dtype]
format_sepshow_offsetstreamr   r  offset_factorc           
        t          t          j        j                   }|j        }||j        nd}|j        rt          d| d          ||j        rt          d| d          d}|	rdnd}|r9t          t          t          |                               t          |          z   }|dk    rt          
                    ||          }t          
                    ||          }||z   t          |          z   t          |          t          |          z  z   }||z
  |z
  |z
  t          |          t          |          z  z
  }t          |d          }d||z  z   }||z  }n|dk    sJ ||z
  t          |          |duz  z
  }t          |d          }||t                              |          z  }nQt          |                             d          t          |                             d          z   }d||z  z  }|dk    rd}|dk    sJ d}dx}}|                     |          D ].}d	}|r}||
z  }|t          |          z  }t          j        j        r+|j        |z   |d
|t          |          z
   z   |j        z   }n*|j        |d|t          |          z
   z   |z   |j        z   }t                              |||||j        |j        |          \  }}||}d	} |6t                              |||||j        |j        |          \  } }||}|| z   } t          j        j        du r|| z   |z   dz   }!n||z   | z   dz   }!|                    |!           0dS )zInternal pretty print method.NzCan't use Dtype 'z&' in pp() as it has a variable length.r   z :z: r  r  r   z <z >T
)r   rO   r  no_colorr   rW  rX   rb   r]   r   r  rp   rX  r  r   r  r  r  greenoffr  purplebluer  )"r0   r  r  r  r  r  r  r  r  r  r  colourname1name2offset_width
offset_sepgroup_chars1group_chars2total_group_chars&width_excluding_offset_and_final_groupgroups_per_linemax_bits_per_linewidth_availablechars_per_24_bitsbitposfirst_fb_widthsecond_fb_widthr%  
offset_strr)   fb1r  fb2line_fmts"                                     r2   _ppzBits._pp[  s    I-6677%1t! 	a____```&"8____```!+TTt
 	As3t99~~..Z@LA00GGL00GGL ,| ;c#hh FSTXYeTfTfIf f5:\5IL5X[g5gjmk k"<00k1 612589_ab5c5c2"HL]"]]O /. @!Q&&&&#l2S__UYHY5ZZO!/155O}$3d6I6I%6P6P$P!!$25$9$L$LR$P$PSabgShS{S{|~SS$!$&/=N*N$O!$))(*% 1$$$$+//HH.// 	# 	#DJ y=0#d))#$) y!'
!:=k,Y\]gYhYhJh=k=k=k!kntnx!xJJ!'60^\CPZOO=[0^0^0^!^ak!kntnx!xJ"//nc6SYS`bhbln|}}OC%!+C!"&"3"3D.#vW]Wbdjdnp  #A  #AZ"*&0O 3& %--9z1D8%+c1D8LL""""r4   c           	     v   t          |           dvr#t          d| dt          |            d          d}t          j        | d                   \  }}t	          ||          }|j        }d }t          |           dk    ryt          j        | d                   \  }}	t	          ||	          }d |j        |j        hvr3|j        |j        k    r#t          d	|j         d
|j         d| d          ||j        }|d}t          |           dk    r5ddddd                    |j                  }|t          d| d          np	 dt          	                    |j                  z  t          	                    |j                  z  }n!# t          $ r t          d| d          w xY w|dk    r|dz  }||||fS )N)r  r  z8Only one or two tokens can be used in an pp() format - 'z' has z tokens.Tr   r  r  zDiffering bit lengths of z and z in format string 'rL   Fr     r   )r   r   r  rI   z7No length or default length available for pp() format 'z7Can't find a default bitlength to use for pp() format 'r  )
rb   rX   r   rN  r   ra   getr   r   r  )
rR  r  has_length_in_fmtr  length1r  r  r  r  length2s
             r2   _process_pp_tokenszBits._process_pp_tokens  s'   z??&((o3ooVYZdVeVeoooq q q 6z!}EEwug&&)z??a"::a=IINE75'**FF,f.>???FDTX^XhDhDh s0@ssvGWsslosssu u u%!'!1! %:!##)*1R"!M!M!Q!QRXR]!^!^!)$%f_b%f%f%fggg *h%&)<)<V[)I)I%IDL_L_`f`kLlLl%lNN! h h h$%f_b%f%f%fgggh!R''"q(Nv~/@@@s   AF	 	F'x   r  Tc                $   t          t          j        j                   }|-t	          |           dz  dk    rt	          |           dk    rdnd}t          j        |          }t                              ||          \  }}	}
}|r|
rt	          |           |
z  nd}|dk    r| n
| d|          }d}|j	        t          |          z   |j        z   }|	%|d|j        z   t          |	          z   |j        z   z  }t          j                    }|j        t          t	          |                     z   |j        z   }|                    d| j        j         d	| d
| d           |                    ||	|
|||||t          j        j        d
  
         |                    d           |dk    r.|                    dt          | | d                   z              |                    d           |                    |                                           dS )a  Pretty print the bitstring's value.

        fmt -- Printed data format. One or two of 'bin', 'oct', 'hex' or 'bytes'.
              The number of bits represented in each printed group defaults to 8 for hex and bin,
              12 for oct and 32 for bytes. This can be overridden with an explicit length, e.g. 'hex:64'.
              Use a length of 0 to not split into groups, e.g. `bin:0`.
        width -- Max width of printed lines. Defaults to 120. A single group will always be printed
                 per line even if it exceeds the max width.
        sep -- A separator string to insert between groups. Defaults to a single space.
        show_offset -- If True (the default) shows the bit offset in the first column of each line.
        stream -- A TextIO object with a write() method. Defaults to sys.stdout.

        >>> s.pp('hex16')
        >>> s.pp('b, h', sep='_', show_offset=False)

        Nr  r   zbin, hexr   z : r   r  z, fmt='z
', length=z	 bits> [
r  ]z + trailing_bits = r  )r   rO   r  r  rb   r   rM  r   r  r  r]   r  r  r   StringIOr  r  r?   rV   r  r  r   )r0   r  r  r  r  r  r  rR  r  r  r  r  trailing_bit_lengthr>  r  tidy_fmtoutput_streamlen_strs                     r2   ppzBits.pp  s   $ I-6677; #D		A 2 2s4yyA~~**5C,S11
<@<S<ST^`c<d<d9(9<MgR`gc$ii.88fg*a//ttT!>Q=Q:Q5R
=3v;;.;v{*S[[86:EEH,SYY/&*<g 7ggggT[ggghhhZ	 1 6	; 	; 	;C   !## 5DBUAUAVAV<W8X8X XYYYD!!!]++--...r4   c                    | S )zReturn a copy of the bitstring.rl   ri   s    r2   r   z	Bits.copy  rn   r4   c               |    t                                          |           }t          j        |          |_        |S )z/Create a new bitstring from a formatted string.)r:   r;   r   r   r%   )r6   r   r>   r?   s      r2   
fromstringzBits.fromstring  s1     GGOOC  &6q99r4   z/The length of the bitstring in bits. Read only.)doc)NNN)r'   r(   r)   r(   r*   r+   r,   r-   )NNNN)r'   r(   r)   r(   r5   r(   r6   r7   r*   r+   r,   r   )r6   r7   r*   r@   r,   r   )r'   r(   r)   r(   r*   r	   r,   r-   )r\   r]   r,   r	   )r,   rf   )r0   r   r,   r   )ro   r	   r,   rp   )r0   r   r}   r@   r,   r   )r0   r   r   r   r,   r   )r   r"   r,   rp   )r0   r   r   r   r,   r   )r,   r"   )r,   rI   )r,   r]   )r   r]   r'   r"   r5   r"   )r}   r	   r,   rp   )r0   r   r   r"   r,   r   )r}   r@   r,   rp   )r,   rp   )r,   r-   )r   r@   r,   r-   )r   r@   r'   r(   r)   r(   r,   r-   )NN)rJ   r]   r'   r(   r)   r(   r,   r-   )r  r  r'   r(   r)   r(   r,   r-   rB   )r}   r@   r'   r-   r,   r-   )r  r   r,   r-   )r>  r?  r'   r-   r,   r-   )r>  rB  r'   r(   r)   r(   r,   r-   )rR  r"   r'   r(   r,   r-   )rZ  r"   r'   r(   r,   r-   )r`  r"   r'   r(   r,   r-   )rf  r"   r'   r(   r,   r-   )rk  r"   r'   r(   r,   r-   )rt  r"   r'   r(   r,   r-   )r,   r   )r  r   r'   r(   r  rp   r,   r-   )r  r   r'   r(   r,   r-   )r  r  r'   r(   r,   r-   )r  r"   r,   r-   )r5   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-   )r0   r   r  r"   r  r"   r,   r   )r   r]   r5   r"   r'   r(   r,   r  )r}   r   r,   r-   )r0   r   r%  r"   r,   r   )r}   r   r5   r"   r,   r-   )r%  r"   r5   r"   r,   r-   )r  r"   r  r"   r,   r-   )r5   r"   r,   r-   )r0   r   )r  r(   r  r(   r,   r  )r  rE  r,   rF  )r  rI  r5   r"   r,   rJ  )rT  rU  r5   r"   r,   rJ  )
r  r(   r  r(   r   ra  r}   r@   r,   rb  )
r}   r   r  r"   r  r"   r   rp   r,   rb  )r}   r@   r  r(   r  r(   rv  r(   r   ra  r,   rw  )r}   r   r  r"   r  r"   rv  r(   r   rp   r,   rw  )
r%  r"   r  r(   r  r(   rv  r(   r,   r  )r  r@   r  r(   r  r(   rv  r(   r   ra  r,   r  )r0   r   r  r  r,   r   )r,   r  )r  r   r,   r-   )r  r@   r  r(   r  r(   r,   rp   )r  r@   r  r(   r  r(   r,   rp   )r  r	   r5   r  r,   rp   )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  r]   r  rp   r  r   r  rp   r  r"   r,   r-   )r  r  r  r"   r  r]   r  rp   r  r   r,   r-   )r6   r   r   r]   r,   r   )rV   
__module____qualname____doc__	__slots__r3   r;   classmethodrF   r=   re   rj   rm   ru   rw   rz   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   rD   rQ   rT   rU   r  r$  r(  r+  r.  r1  r4  r7  r:  r=  rA  rS   rG  r  rangerM  extendrQ  rV  rY  r\  r_  rb  re  rh  rj  ro  rs  rv  rx  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   r  r  r  r   r   r   r  r   r"  r   r   r*  r,  r/  r1  r3  r6  r9  r   r<  r>  r   rB  rD  r  rH  rO  r   rr  ru  rz  r~  r  r  rm  r  r  r  r   r   r  r  r  r   r  r  rv  staticmethodr  r  r  r  r  sysstdoutr  r   r  propertyrb   r'   __classcell__)r?   s   @r2   r   r       s       # #H +I_c)-(( (( (( (( ((T koCG            [- - - -B   $ $ $ $                             X    X     ! ! ! !   L L L L4	C 	C 	C 	CA A A A
 
 
 
# # # #
 
 
 
      "                                   K K K K   $ $ $ $S S S S4O O O O:f f f f f*C C C C& & & & &? ? ? ?? ? ? ?? ? ? ?? ? ? ?? ? ? ?? ? ? ?? ? ? ?? ? ? ?< < < <9 9 9 9 9Y Y Y Y Y( ( ( ( 4dD))**LdD))***   L L L L L. . . .K K K K K- - - -N N N N N   L L L L L   P P P P P" " " "N N N N N! ! ! !4 4 4 44 4 4 49 9 9 99 9 9 90 0 0 00 0 0 00 0 0 0   " " " "P P P P( ( ( ( (? ? ? ?
) ) ) ) )? ? ? ?
) ) ) )C C C C C
) ) ) )D D D D D
9 9 9 9   6+ + + ++ + + ++ + + ++ + + +9 9 9 96 6 6 6: : : :       *: : : :X X X X"V V V V      * * * *B B B B BI I I I I- - - -B B B B B- - - -B B B B B- - - -# # # #         C C C C ' ' ' '; ; ; ;
 
 
 

 
 
 
   : : : :   l l l l
# # # #
                      3 3 3 3"6 6 6 6,# # # #J W[+/    <   ' ' ' '
 tx.28 8 8 8 82      @ X\,0    6' ' ' '
    PT#'    : \`IM0 0 0 0 0d   .( ( ( (, , , ,	% 	% 	% 	%
j 
j 
j 
j 
j
f 
f 
f 
f 
f    "    "5 5 5 5 NR    \6 F F F \F @ @ @ \@B B B BH  A  A \ AD '+#cj' ' ' ' 'R         [ 8J,]^^^^C&&&&&r4   )8
__future__r   rM   r  r  r  r  r   r   collectionsr   r  typingr   r   r   r   r	   r
   r   r   r   r   r   r   rK   bitarray.utilrO   bitstring.bitstorer   r   r   bitstring.dtypesr   r   bitstring.fp8r   r   bitstring.mxfpr   r   r   r   r   bitstring.bitstring_optionsr   r]   rp   r   rI   r   r@   r   r#   __annotations__r   rl   r4   r2   <module>r      s   " " " " " " "   



    				           s s s s s s s s s s s s s s s s s s s s s s s s s s s s          ' ' ' ' ' ' - - - - - - - - 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 q q q q q q q q q q q q q q . . . . . . hsmT8Yz[c[llmv&&& 	    X_ X_ X_ X_ X_ X_ X_ X_ X_ X_r4   