
    4)di                       d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlZd dlZd dl Z d dl!Z!d dl"Z"e	e#e$e%e&e'ef         Z( e            Z) G d d          Z*dS )    )annotationsN)Sized)CreationError)UnionListIterableAnyOptionalBinaryIOoverloadTextIO)BitsBitsType)BitArray)Dtypedtype_register)utils)OptionsColourc                  >   e Zd ZdZ	 	 dddZdZedd            Zedd            Z	edd            Z
edd            Zej        dd            ZddZddZddZedd"            Zedd#            Zdd&Zedd(            Zedd)            Zdd+Zdd,Zdd-Zdd.Zdd0Zdd2Zdd5Zdd7Zddd9Zdd:Zdd;Zdd=Zdd@ZdddBZddCZ ddDdEe!j"        fddMZ#ddPZ$ddQZ%ddRZ&dddVZ'ddXZ(ddZZ)dd[Z*ddd\Z+e,dd_            Z-ddaZ.ddbZ/ddcZ0dddZ1ddeZ2ddfZ3ddgZ4ddhZ5ddiZ6ddjZ7ddlZ8ddmZ9ddnZ:ddoZ;ddpZ<ddqZ=ddrZ>ddsZ?ddtZ@dduZAddvZBddwZCddxZDddyZEddzZFdd{ZGdd|ZHdd}ZIdd~ZJddZKddZLddZMddZNddZOddZPd ZQd ZRdS )Arrayaz  Return an Array whose elements are initialised according to the fmt string.
    The dtype string can be typecode as used in the struct module or any fixed-length bitstring
    format.

    a = Array('>H', [1, 15, 105])
    b = Array('int5', [-9, 0, 4])

    The Array data is stored compactly as a BitArray object and the Array behaves very like
    a list of items of the given format. Both the Array data and fmt properties can be freely
    modified after creation. If the data length is not a multiple of the fmt length then the
    Array will have 'trailing_bits' which will prevent some methods from appending to the
    Array.

    Methods:

    append() -- Append a single item to the end of the Array.
    byteswap() -- Change byte endianness of all items.
    count() -- Count the number of occurences of a value.
    extend() -- Append new items to the end of the Array from an iterable.
    fromfile() -- Append items read from a file object.
    insert() -- Insert an item at a given position.
    pop() -- Remove and return an item.
    pp() -- Pretty print the Array.
    reverse() -- Reverse the order of all items.
    tobytes() -- Return Array data as bytes object, padding with zero bits at the end if needed.
    tofile() -- Write Array data to a file, padding with zero bits at the end if needed.
    tolist() -- Return Array items as a list.

    Special methods:

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

    Properties:

    data -- The BitArray binary data of the Array. Can be freely modified.
    dtype -- The format string or typecode. Can be freely modified.
    itemsize -- The length *in bits* of a single item. Read only.
    trailing_bits -- If the data length is not a multiple of the fmt length, this BitArray
                     gives the leftovers at the end of the data.


    NdtypeUnion[str, Dtype]initializer`Optional[Union[int, Array, array.array, Iterable, Bits, bytes, bytearray, memoryview, BinaryIO]]trailing_bitsOptional[BitsType]returnNonec           	        t                      | _        t          |t                    r|j        dk    rt          |t
          t          t          t          t          t          f          rt          d          |                     ||j        |j                  }t          |j        |j        |          }	 |                     |           n!# t           $ r}t#          |          d }~ww xY wt          |t$          j                  r"t          || j        j        z            | _        nt          |t          t          t          t          f          r| xj        |z  c_        nGt          |t,          j                  r|                     |           n||                     |           |$| xj        t          j        |          z  c_        d S d S )NautozTAn Array with an 'auto' scale factor can only be created from an iterable of values.)scale)r   data
isinstancer   r"   intr   bytes	bytearray
memoryviewr   	TypeError_calculate_auto_scalenamelength
_set_dtype
ValueErrorr   numbersIntegral_dtype	bitlengthioBufferedReaderfromfileextend_create_from_bitstype)selfr   r   r   
auto_scalees         W/var/www/menimich/repos/protonApp/venv/lib/python3.11/site-packages/bitstring/array_.py__init__zArray.__init__F   s   JJ	eU## 	Fv(=(=+T5)ZQY'Z[[ x vwww33KU\ZZJ%*el*EEEE	#OOE"""" 	# 	# 	#"""	# k7#344 	% t{/D!DEEDIIdE9j%IJJ 	%II$IIIR%677 	%MM+&&&&$KK$$$$II7FFFIIII %$s   5C 
C)C$$C)r+   strr,   Optional[int]floatc                   t           j        t          d          j        t          d          j        t          d          j        t          d          j        t          d          j        t          d          j        t          d          j	        t          d          j
        t          d          j        d	t           _        | | t           j                                        v rt          d|                                           }|st          d	          t          d
 |D                       }|dk    rdS t!          j        t!          j        |                    }t!          j        t!          j        t           j        | |                              }||z
  }|dk    rd}n|dk     rd}d|z  S t          d| | dt'          t           j                                                   d          )N
0b011111110b01110b011111
0b01111110
0b011110110x7bff)	mxint8	e2m1mxfp4	e2m3mxfp6	e3m2mxfp6	e4m3mxfp8	e5m2mxfp8	p4binary8	p3binary8float16float64z@Can't calculate an 'auto' scale with an empty Array initializer.c              3  4   K   | ]}t          |          V  d S N)abs).0xs     r;   	<genexpr>z.Array._calculate_auto_scale.<locals>.<genexpr>v   s(      !?!?Q#a&&!?!?!?!?!?!?    r   g      ?   i   z'Can't calculate auto scale for format 'z5'. This feature is only available for these formats: .)r   _largest_valuesr   rG   rH   rI   rJ   rK   rL   rM   rN   rO   keystolistr.   maxmathfloorlog2list)r   r+   r,   float_valuesmax_float_valuera   lp2lg_scales           r;   r*   zArray._calculate_auto_scalea   s     (|,,3!(^^5!*--7!*--7!,//9!,//9!,//9!,//9>>1% %E! F 5 : : < <<< K88??AAL e !cddd!!?!?,!?!?!???O!##s:di8899D*TYu'<=Nf=N=N'OPPQQCczH#~~D=  xt xV x xRVW\WlWqWqWsWsRtRtx x x y y yrW   r%   c                    | j         j        S rR   )r1   r,   r8   s    r;   itemsizezArray.itemsize   s    {!!rW   r   c                    t          | j                  | j        j        z  }|dk    rt	                      n| j        | d          S )Nr   )lenr#   r1   r2   r   )r8   trailing_bit_lengths     r;   r   zArray.trailing_bits   sC    !$)nnt{/DD0A55xzzz49FYEYEZEZ;[[rW   r   c                    | j         S rR   )r1   rh   s    r;   r   zArray.dtype   s
    {rW   	new_dtypec                0    |                      |           d S rR   )r-   )r8   rn   s     r;   r   zArray.dtype   s    	"""""rW   c                   t          |t                    r|| _        n	 t          |          }nV# t          $ rI t	          j        |          }|t          |d         |d                   }nt          d| d          Y nw xY w|j        t          d| d          || _        | j        j        dk    rt          d          d S )Nr      z Inappropriate Dtype for Array: ''.z8A fixed length format is needed for an Array, received 'r!   zOA Dtype with an 'auto' scale factor can only be used when creating a new Array.)r$   r   r1   r.   r   parse_single_struct_tokenr,   r"   )r8   rn   r   name_lengths       r;   r-   zArray._set_dtype   s    i'' 	 #DKKWi(( W W W#=iHH*!+a.+a.AAEE$%U	%U%U%UVVV EW |# !i\e!i!i!ijjjDK;&&nooo '&s   / ABBvalueElementTyper   c                    | j                             |          }t          |          | j         j        k    rt	          d|d| j          d          |S )zCCreate Bits from value according to the token_name and token_lengthz
The value z& has the wrong length for the format 'rr   )r1   buildrk   r,   r.   )r8   ru   bs      r;   _create_elementzArray._create_element   sX    Ke$$q66T['''h%hhY]YdhhhiiirW   c                D    t          | j                  | j        j        z  S rR   )rk   r#   r1   r,   rh   s    r;   __len__zArray.__len__   s    49~~!333rW   keyslicec                    d S rR    r8   r}   s     r;   __getitem__zArray.__getitem__       rW   c                    d S rR   r   r   s     r;   r   zArray.__getitem__   r   rW   Union[slice, int]Union[Array, ElementType]c                T   t          |t                    r|                    t          |                     \  }}}|dk    rt	                      }t          || j        j        z  || j        j        z  || j        j        z            D ]1}|                    | j	        ||| j        j        z                       2| 
                    | j                  }||_	        |S | 
                    | j                  }| j	        || j        j        z  || j        j        z           |_	        |S |dk     r|t          |           z  }|dk     s|t          |           k    r#t          d| dt          |            d          | j                            | j	        | j        j        |z            S )Nrq   r   Index " out of range for Array of length rZ   start)r$   r~   indicesrk   r   ranger1   r,   appendr#   	__class__
IndexErrorread_fn)r8   r}   r   stopstepdsas           r;   r   zArray.__getitem__   s   c5!! 	R #CII 6 6E4qyyJJut{'994$+BT;TVZ]a]h]oVopp C CAHHTYq!dk.@*@'@ABBBBNN4;//NN4;//54;+=#=tdkFX?X#XYQwws4yy Qww#T** !]#!]!]QTUYQZQZ!]!]!]^^^;&&ty8JS8P&QQQrW   Iterable[ElementType]c                    d S rR   r   r8   r}   ru   s      r;   __setitem__zArray.__setitem__   r   rW   c                    d S rR   r   r   s      r;   r   zArray.__setitem__   r   rW   )Union[Iterable[ElementType], ElementType]c                N   t          |t                    r}|                    t          |                     \  }}}t          |t                    st          d          |dk    rSt                      }|D ]}||                     |          z  }|| j        || j	        j
        z  || j	        j
        z  <   d S t          t          |||                    }t          |t                    st          |          }t          |          |k    rbt          t          |||          |          D ]@\  }	}
| j                            |                     |
          |	| j	        j
        z             Ad S t!          dt          |           d| d          |dk     r|t          |           z  }|dk     s|t          |           k    r#t#          d| dt          |            d          | j	        j
        |z  }| j                            |                     |          |           d S )	Nz'Can only assign an iterable to a slice.rq   zCan't assign z' values to an extended slice of length rZ   r   r   r   )r$   r~   r   rk   r   r)   r   rz   r#   r1   r,   r   r   rb   zip	overwriter.   r   )r8   r}   ru   r   r   r   new_datarU   items_in_slicer   vs              r;   r   zArray.__setitem__   s-   c5!! 	 #CII 6 6E4eX.. K IJJJqyy#:: 8 8A 4 4Q 7 77HHS[	%$+"44dT[=O6OOP udD!9!9::NeU++ $U5zz^++eT4 8 8%@@ Y YDAqI''(<(<Q(?(?T[EWAWXXXXY Y !!uU!u!udr!u!u!uvvvQwws4yy Qww#T** !]#!]!]QTUYQZQZ!]!]!]^^^K&,EI 4 4U ; ;UCCCFrW   c                   t          |t                    r|                    t          |                     \  }}}|dk    rD| j                            t          || j        j        z  || j        j        z                       d S |dk    rt          t          |||                    nt          |||          }|D ]G}| j                            t          || j        j        z  |dz   | j        j        z                       Hd S |dk     r|t          |           z  }|dk     s|t          |           k    rt          | j        j        |z  }| j        ||| j        j        z   = d S )Nrq   r   )r$   r~   r   rk   r#   __delitem__r1   r,   reversedr   r   )r8   r}   r   r   r   rr   s          r;   r   zArray.__delitem__   sh   c5!! 	= #CII 6 6E4qyy	%%eEDK4F,Ft{OaHa&b&bccc6:QhhudD11222E%QUW[D\D\A c c	%%eA0B,BQUdkN`D`&a&abbbbc c Qwws4yy Qww#T**  K&,E	%);!;;<<<rW   c                    |                                   }t          | j                  | j        j        z  }|dk    rdndt          | j        | d                    z   }d| j         d| | dS )Nr    z, trailing_bits=zArray('z', ))r]   rk   r#   r1   r,   repr)r8   list_strrl   	final_strs       r;   __repr__zArray.__repr__  s    kkmm%!$)nnt{/AA-22BB8JTI**++,N. N. 9.	????9????rW   c                V    |                      ||                                           }|S )zHReturn Array with elements of new dtype, initialised from current Array.)r   r]   )r8   r   	new_arrays      r;   astypezArray.astype  s#    NN5$++--88	rW   List[ElementType]c                      fdt          dt           j                   j        j        z
  dz    j        j                  D             S )Nc                R    g | ]#}j                             j        |           $S )r   )r1   r   r#   )rT   r   r8   s     r;   
<listcomp>z Array.tolist.<locals>.<listcomp>  sF     d d d ##DIU#;; d d drW   r   rq   )r   rk   r#   r1   r,   rh   s   `r;   r]   zArray.tolist  s^    d d d d"1c$)nnt{7I&IA&Mt{Oabbd d d 	drW   rU   c                    t          | j                  | j        j        z  dk    rt	          d          | xj        |                     |          z  c_        d S )Nr   zLCannot append to Array as its length is not a multiple of the format length.)rk   r#   r1   r,   r.   rz   )r8   rU   s     r;   r   zArray.append  sP    ty>>DK..!33klll		T))!,,,				rW   iterable(Union[Array, array.array, Iterable[Any]]c                   t          | j                  | j        j        z  dk    r2t	          dt          | j                   d| j        j         d          t          |t                    ru| j        j        |j        j        k    s| j        j        |j        j        k    r t          d| j         d|j         d          | j        	                    |j                   d S t          |t          j
                  rt          j        d|j        z             }|t	          d	|j         d
          t          j        |dd i}| j        j        |j        k    s| j        j        |j        k    r t	          d| j         d|j         d          | xj        |                                z  c_        d S t          |t"                    rt          d          |D ]%}| xj        |                     |          z  c_        &d S )Nr   (Cannot extend Array as its data length (/ bits) is not a multiple of the format length ( bits).z$Cannot extend an Array with format 'z' from an Array of format 'rr   =z'Cannot extend from array with typecode rZ   r"   z' from an array with typecode 'z!Can't extend an Array with a str.)rk   r#   r1   r,   r.   r$   r   r+   r)   r   arrayr   rs   typecoder   	get_dtypetobytesr=   rz   )r8   r   
name_valueother_dtypeitems        r;   r6   zArray.extend  s:   ty>>DK..!33  cDI  c  c  HL  HS  HZ  c  c  c  d  d  dh&& 	8{8?#7774;;MQYQ`Qg;g;gv4;vvckcrvvvx x x IX]+++++%+.. 	88x?P9PQQJ! !_8K\!_!_!_```(2JKdKKK{;#333t{7I[M_7_7_ |4;||gogx|||~ ~ ~II))+++IIII(C(( E CDDD  8 8		T11$777			8 8rW   ic                    t          |t          |                     }| j                            |                     |          || j        j        z             dS )z<Insert a new element into the Array at position i.

        N)minrk   r#   insertrz   r1   r,   r8   r   rU   s      r;   r   zArray.insert6  sO     3t99	--a00!dk6H2HIIIIIrW   c                `    t          |           dk    rt          d          | |         }| |= |S )zpReturn and remove an element of the Array.

        Default is to return and remove the final element.

        r   zCan't pop from an empty Array.)rk   r   r   s      r;   popz	Array.pop=  s7     t99>>=>>>GGrW   c                    | j         j        dz  dk    r%t          d| j          d| j         j         d          | j                            | j        dz             dS )zChange the endianness in-place of all items in the Array.

        If the Array format is not a whole number of bytes a ValueError will be raised.

           r   z8byteswap can only be used for whole-byte elements. The 'z' format is z bits long.N)r1   r,   r.   r#   byteswapri   rh   s    r;   r   zArray.byteswapI  s     ;!Q&& D4;  D  Ddhdodv  D  D  DE E E	4=A-.....rW   c                    t          j                  rt          d | D                       S t          fd| D                       S )a  Return count of Array items that equal value.

        value -- The quantity to compare each Array element to. Type should be appropriate for the Array format.

        For floating point types using a value of float('nan') will count the number of elements that are NaN.

        c              3  >   K   | ]}t          j        |          V  d S rR   )r_   isnan)rT   r   s     r;   rV   zArray.count.<locals>.<genexpr>]  s*      33tz!}}333333rW   c              3  $   K   | ]
}|k    V  d S rR   r   )rT   r   ru   s     r;   rV   zArray.count.<locals>.<genexpr>_  s'      00aqEz000000rW   )r_   r   sum)r8   ru   s    `r;   countzArray.countT  sW     :e 	133d33333300004000000rW   r&   c                4    | j                                         S )zReturn the Array data as a bytes object, padding with zero bits if needed.

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

        )r#   r   rh   s    r;   r   zArray.tobytesa  s     y  """rW   fr   c                :    | j                             |           dS )zWrite the Array data to a file object, padding with zero bits if needed.

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

        N)r#   tofile)r8   r   s     r;   r   zArray.tofilei  s      		rW   nc                   t          | j                  | j        j        z  }|dk    r2t	          dt          | j                   d| j        j         d          t          |          }t          |          | j        j        z  }||nt          ||          }| xj        |d|| j        j        z           z  c_        |||k     rt          d| d| d          d S d S )Nr   r   r   r   zOnly z were appended, not the z items requested.)	rk   r#   r1   r2   r.   r   r,   r   EOFError)r8   r   r   rl   r   	max_itemsitems_to_appends          r;   r5   zArray.fromfileq  s   !$)nnt{/DD!##  fDI  f  f  HL  HS  H]  f  f  f  g  g  g77MMT[%77	'(y))c!Y6G6G		Xa4;3H!HHII		=_q00`?``A```aaa =00rW   c                6   t          | j                  | j        j        z  }|dk    r2t	          dt          | j                   d| j        j         d          t          dt          | j                  dz  | j        j                  D ]}t          | j                  |z
  | j        j        z
  }| j        ||| j        j        z            }| j        ||| j        j        z            | j        ||| j        j        z   <   || j        ||| j        j        z   <   d S )Nr   z:Cannot reverse the items in the Array as its data length (r   r   rY   )rk   r#   r1   r,   r.   r   )r8   rl   	start_bitstart_swap_bittemps        r;   reversezArray.reverse}  sJ   !$)nnt{/AA!##  uZ]^b^gZhZh  u  u  Z^  Ze  Zl  u  u  u  v  v  vq#di..A"5t{7IJJ 	R 	RI ^^i7$+:LLN9Y	DK4F(FFGDCG9?M~`d`k`rOr?rDtDIiT[-?!??@MQDInnt{7I&IIJJ	R 	RrW   x   TfmtOptional[str]widthshow_offsetboolstreamr   c                   t          t          j                   }d}d}d}|9| j        }| j        }	d|j        z   t          | j                  z   dz   |j        z   }nt          j        |          }
t          |
          dvr#t          d| dt          |
           d          t          j        |
d	                   \  }}t          ||          }	t          |
          d
k    r-t          j        |
d                   \  }}t          ||          }|	j        }|:|	j        *|j        #|	j        |j        k    rt          d| d          ||j        }|| j        }t          | j                  |z  }d}|N|j        t          |	          z   |j        z   }|%|d|j        z   t          |          z   |j        z   z  }d|z   dz   }|d	k    r| j        n| j        d	|          }t          | j                  |z  }|j        t          |          z   |j        z   }|                    d| j        j         d| d| d| dt          | j                  dz   dz   d           |                    |	|||||||d|
  
         |                    d           |d	k    r3|                    dt          | j        | d                   z              |                    d           dS )a  Pretty-print the Array contents.

        fmt -- Data format string. Defaults to current Array dtype.
        width -- Max width of printed lines in characters. Defaults to 120. A single group will always
                 be printed per line even if it exceeds the max width.
        show_offset -- If True shows the element offset in the first column of each line.
        stream -- A TextIO object with a write() method. Defaults to sys.stdout.

         Nzdtype='')rq   rY   z>Only one or two tokens can be used in an Array.pp() format - 'z' has z tokens.r   rY   rq   z)Two different format lengths specified ('z4'). Either specify just one, or two the same length.z : z, zfmt='<z	, length=z, itemsize=z bits, total data size=   r   z
 bytes> [
F]z + trailing_bits = 
)r   optionsno_colorr   purpler=   offr   preprocess_tokensrk   r.   parse_name_length_tokenr   r2   ri   r#   bluegreenwriter   __name___pp)r8   r   r   r   r   coloursepdtype2tidy_fmtdtype1
token_listname1length1name2length2token_lengthrl   
format_sepr#   r,   len_strs                        r;   ppzArray.pp  s    G,,--;*CZF 6=03tz??BSH6:UHH055J:f,,   "Gbe  "G  "Gmpq{m|m|  "G  "G  "G  H  H  H"::a=IINE75'**F:!##!&!>z!}!M!Mwug..'+0@0LQWQaekeuQuQu   "GS  "G  "G  "G  H  H  H#%/=L!$)nn|;
}s6{{2VZ?H!D6;.V<vzII)C/H/144tyy$)AH[G[D[:\TY</,V,vz9  f0  f  f8  f  fg  f  fZf  f  f  AD  EI  EN  AO  AO  RS  AS  XY  @Y  f  f  f  	g  	g  	guc:{TZ\acopppS!##LL.TY@S?S?T?T5U1V1VVWWWTrW   otherr	   c                   t          |t                    rL| j        j        |j        j        k    rdS | j        j        |j        j        k    rdS | j        |j        k    rdS dS t          |t          j                  rn| j        rdS | j        |j        dz  k    rdS t          |           t          |          k    rdS | 
                                |
                                k    rdS dS dS )z4Return True if format and all Array items are equal.FTr   )r$   r   r1   r,   r+   r#   r   r   ri   rk   r]   r8   r
  s     r;   equalszArray.equals  s    eU## 	{!U\%888u{5<#444uyEJ&&u4u{++ 	! u} 222u4yyCJJ&&u{{}}..u4urW   c              #     K   d}t          t          |                     D ]4}| j                            | j        |          V  || j        j        z  }5d S )Nr   r   )r   rk   r1   r   r#   r,   )r8   r   _s      r;   __iter__zArray.__iter__  sf      s4yy!! 	( 	(A+%%diu%=====T[''EE	( 	(rW   c                v    |                      | j                  }t          j        | j                  |_        |S rR   )r   r1   copyr#   )r8   a_copys     r;   __copy__zArray.__copy__  s-    ,,i	**rW   FUnion[int, float, None]is_comparisonc                d   |                      |rdn| j                  }t                      }dx}}d}fd}	nfd}	t          t	          |                     D ]}
| j                            | j        | j        j        |
z            }	 |                    |	                     |	|                               c# t          t          t          f$ r&}|dk    rt          |          }|
}|dz  }Y d}~d}~ww xY w|dk    r!t          d	j         d
| d| d| d	          ||_        |S )zGApply op with value to each element of the Array and return a new Arrayr   r   r   Nc                     |           S rR   r   )r   opru   s    r;   
partial_opz3Array._apply_op_to_all_elements.<locals>.partial_op  s    r!U||#rW   c                     |           S rR   r   )r   r  s    r;   r  z3Array._apply_op_to_all_elements.<locals>.partial_op  s    r!uurW   r   rq   Applying operator '' to Array caused  errors. First error at index  was: "")r   r1   r   r   rk   r   r#   r,   r   rz   r   ZeroDivisionErrorr.   r=   r   )r8   r  ru   r  r   r   failuresindexmsgr  r   r   r:   s    ``          r;   _apply_op_to_all_elementszArray._apply_op_to_all_elements  s   NN]#K66LL	::5$ $ $ $ $ $ $    s4yy!! 	 	A##DIT[5G!5K#LLA	 9 9**Q-- H HIIII!#4jA   q==a&&CEA	
 q== J2; J JRZ J J5:J JCFJ J J K K K!	s   1CC?C::C?Union[int, float]c                
   t                      }dx}}d}t          t          |                     D ]}| j                            | j        | j        j        |z            }	 |                    |                      |||                               d# t          t          t          f$ r&}	|dk    rt          |	          }|}|dz  }Y d}	~	d}	~	ww xY w|dk    r!t          d|j         d| d| d	| d
	          || _        | S )z:Apply op with value to each element of the Array in place.r   r   r   rq   Nr  r  r  r  r   )r   r   rk   r1   r   r#   r,   r   rz   r   r!  r.   r=   r   )
r8   r  ru   r   r"  r#  r$  r   r   r:   s
             r;   !_apply_op_to_all_elements_inplacez'Array._apply_op_to_all_elements_inplace  sY    ::5s4yy!! 	 	A##DIT[5G!5K#LLA 4 4RR5\\ B BCCCC!#4jA   q==a&&CEA	
 q== J2; J JRZ J J5:J JCFJ J J K K K	s   "2BC,CCr   c                F    | dd         }|                     ||           |S )z^Apply op with value to each element of the Array as an unsigned integer and return a new ArrayN))_apply_bitwise_op_to_all_elements_inplace)r8   r  ru   r  s       r;   !_apply_bitwise_op_to_all_elementsz'Array._apply_bitwise_op_to_all_elements  s*    aaa88UCCCrW   c                   t          j        |          }t          |          | j        j        k    r%t          d| j        j         d| j         d          t          dt          |           | j        j        z  | j        j                  D ]?} || j        ||| j        j        z            |          | j        ||| j        j        z   <   @| S )zQApply op with value to each element of the Array as an unsigned integer in place.z'Bitwise op needs a bitstring of length z to match format rZ   r   )r   r7   rk   r1   r,   r.   r   r#   )r8   r  ru   r   s       r;   r*  z/Array._apply_bitwise_op_to_all_elements_inplace  s    .u55u::+++zt{GYzzlplwzzz{{{1c$ii$+*<<dk>PQQ 	s 	sE;=2diuW[WbWiOiHi>jlq;r;rDIeUT[%77788rW   c                    t          |           t          |          k    rpdt          |            dt          |           d}|t          j        t          j        fv r|dz  }|t          j        t          j        fv r|dz  }t          |          |rt          j        dd          }n | 	                    | j
        |j
                  }|                     |          }t                      }dx}}	d	}t          t          |                     D ]}
| j
                            | j        | j
        j        |
z  
          }|j
                            |j        |j
        j        |
z  
          }	 |                    |                     |||                               # t&          t          t(          f$ r&}|dk    rt+          |          }|
}	|dz  }Y d }~d }~ww xY w|dk    r!t          d|j         d| d|	 d| d	          ||_        |S )Nz>Cannot operate element-wise on Arrays with different lengths (z and z).z+ Use extend() method to concatenate Arrays.zC Use equals() method to compare Arrays for a single boolean result.r   rq   r   r   r   r  z' between Arrays caused r  r  r   )rk   operatoraddiaddeqner.   r   r   _promotetyper1   r   r   r   r   r#   r,   r   rz   r   r!  r=   r   )r8   r  r
  r  r$  new_typer   r   r"  r#  r   r   ry   r:   s                 r;   _apply_op_between_arrayszArray._apply_op_between_arrays"  sR   t99E

""qSVW[S\S\qqcfglcmcmqqqChlHM222DDhk8;///\\S//! 	D%/::HH((elCCHNN8,,	::5s4yy!! 		 		A##DIT[5G!5K#LLA$$UZu|7JQ7N$OOA	 9 9""Q(( C CDDDD!:/@A   q==a&&CEA	
 q== J2; J JX` J J5:J JCFJ J J K K K!	s   -2F  G7GGtype1type2c                4   d }d } ||           ||          z    ||          z    ||          z   dk    rt          d| d| d          |j        |j        k    r|j        |j        k    r|n|S  ||          r ||          r|S  ||          r ||          r|S  ||          r ||          r|j        |j        k    r|n|S  ||          r ||          sJ |j        r	|j        s|S |j        r	|j        s|S |j        |j        k    r|n|S )a  When combining types which one wins?

        1. We only deal with types representing floats or integers.
        2. One of the two types gets returned. We never create a new one.
        3. Floating point types always win against integer types.
        4. Signed integer types always win against unsigned integer types.
        5. Longer types win against shorter types.
        6. In a tie the first type wins against the second type.

        c                    | j         t          u S rR   )return_typer?   rU   s    r;   is_floatz$Array._promotetype.<locals>.is_floatN  s     66rW   c                :    | j         t          u p| j         t          u S rR   )r:  r%   r   r;  s    r;   is_intz"Array._promotetype.<locals>.is_intO  s    ams2Kamt6KKrW   rY   z=Only integer and floating point types can be combined - not 'z' and 'rr   )r.   r+   r,   	is_signed)clsr6  r7  r<  r>  s        r;   r3  zArray._promotetypeB  s    	766KKK8E??VVE]]*XXe__<vve}}LPQQQt]bttkptttuuu:##!L5<7755UB8E?? 	vve}} 	L6%== 	XXe__ 	L8E?? 	Cxx 	C!L5<7755UBve}}....? 	5? 	L? 	5? 	Lu|33uu>rW   Union[int, float, Array]c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S )z!Add int or float to all elements.)r$   r   r5  r.  r/  r%  r  s     r;   __add__zArray.__add__e  sE    eU## 	F00uEEE--hlEBBBrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  r/  r(  r  s     r;   __iadd__zArray.__iadd__k  E    eU## 	F00uEEE55hlEJJJrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  subr(  r  s     r;   __isub__zArray.__isub__p  rF  rW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rH  r%  r  s     r;   __sub__zArray.__sub__u  E    eU## 	F00uEEE--hlEBBBrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  mulr%  r  s     r;   __mul__zArray.__mul__z  rL  rW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rN  r(  r  s     r;   __imul__zArray.__imul__  rF  rW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  floordivr%  r  s     r;   __floordiv__zArray.__floordiv__  sG    eU## 	K001BEJJJ--h.?GGGrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rS  r(  r  s     r;   __ifloordiv__zArray.__ifloordiv__  sG    eU## 	K001BEJJJ55h6GOOOrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  truedivr%  r  s     r;   __truediv__zArray.__truediv__  sG    eU## 	J001A5III--h.>FFFrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rX  r(  r  s     r;   __itruediv__zArray.__itruediv__  sG    eU## 	J001A5III55h6FNNNrW   Union[int, Array]c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rshiftr%  r  s     r;   
__rshift__zArray.__rshift__  E    eU## 	I00%HHH--houEEErW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  lshiftr%  r  s     r;   
__lshift__zArray.__lshift__  r`  rW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  r^  r(  r  s     r;   __irshift__zArray.__irshift__  E    eU## 	I00%HHH55houMMMrW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rb  r(  r  s     r;   __ilshift__zArray.__ilshift__  rf  rW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  modr%  r  s     r;   __mod__zArray.__mod__  rL  rW   c                    t          |t                    r |                     t          j        |          S |                     t          j        |          S rR   )r$   r   r5  r.  rj  r(  r  s     r;   __imod__zArray.__imod__  rF  rW   c                B    |                      t          j        |          S rR   r+  r.  iandr  s     r;   __and__zArray.__and__      55hmUKKKrW   c                B    |                      t          j        |          S rR   )r*  r.  rp  r  s     r;   __iand__zArray.__iand__      ==hmUSSSrW   c                B    |                      t          j        |          S rR   r+  r.  iorr  s     r;   __or__zArray.__or__      55hlEJJJrW   c                B    |                      t          j        |          S rR   )r*  r.  rx  r  s     r;   __ior__zArray.__ior__  s    ==hlERRRrW   c                B    |                      t          j        |          S rR   r+  r.  ixorr  s     r;   __xor__zArray.__xor__  rr  rW   c                B    |                      t          j        |          S rR   )r*  r.  r  r  s     r;   __ixor__zArray.__ixor__  ru  rW   c                B    |                      t          j        |          S rR   )r%  r.  rN  r  s     r;   __rmul__zArray.__rmul__      --hlEBBBrW   c                B    |                      t          j        |          S rR   )r%  r.  r/  r  s     r;   __radd__zArray.__radd__  r  rW   c                    |                      t          j        d           }|                     t          j        |          S rR   )r%  r.  negr/  )r8   r
  r  s      r;   __rsub__zArray.__rsub__  s1    ,,X\4@@,,X\5AAArW   c                B    |                      t          j        |          S rR   ro  r  s     r;   __rand__zArray.__rand__  rr  rW   c                B    |                      t          j        |          S rR   rw  r  s     r;   __ror__zArray.__ror__  rz  rW   c                B    |                      t          j        |          S rR   r~  r  s     r;   __rxor__zArray.__rxor__  rr  rW   c                    t          |t                    r"|                     t          j        |d          S |                     t          j        |d          S NT)r  )r$   r   r5  r.  ltr%  r  s     r;   __lt__zArray.__lt__  Q    eU## 	Y00eSW0XXX--hk5PT-UUUrW   c                    t          |t                    r"|                     t          j        |d          S |                     t          j        |d          S r  )r$   r   r5  r.  gtr%  r  s     r;   __gt__zArray.__gt__  r  rW   c                    t          |t                    r"|                     t          j        |d          S |                     t          j        |d          S r  )r$   r   r5  r.  ger%  r  s     r;   __ge__zArray.__ge__  r  rW   c                    t          |t                    r"|                     t          j        |d          S |                     t          j        |d          S r  )r$   r   r5  r.  ler%  r  s     r;   __le__zArray.__le__  r  rW   c                    t          |t          t          t          t          f          r|                     ||d          S |                     | j        |          }|                     ||d          S r  )	r$   r%   r?   r=   r   r%  r   r   r5  )r8   r  r
  s      r;   _eq_nezArray._eq_ne  si    ec5#t455 	Q11"e41PPPtz511,,Rd,KKKrW   c                B    |                      t          j        |          S rR   )r  r.  r1  r  s     r;   __eq__zArray.__eq__      {{8;...rW   c                B    |                      t          j        |          S rR   )r  r.  r2  r  s     r;   __ne__zArray.__ne__  r  rW   c                B    |                      t          j        d           S rR   )r%  r.  r  rh   s    r;   __neg__zArray.__neg__      --hlDAAArW   c                B    |                      t          j        d           S rR   )r%  r.  rS   rh   s    r;   __abs__zArray.__abs__	  r  rW   )NN)r   r   r   r   r   r   r   r   )r+   r=   r,   r>   r   r?   )r   r%   )r   r   )r   r   )rn   r   r   r   )ru   rv   r   r   )r}   r~   r   r   )r}   r%   r   rv   )r}   r   r   r   )r}   r~   ru   r   r   r   )r}   r%   ru   rv   r   r   )r}   r   ru   r   r   r   )r}   r   r   r   )r   r=   )r   r   r   r   )r   r   )rU   rv   r   r   )r   r   r   r   )r   r%   rU   rv   r   r   )r   )r   r%   r   rv   )r   r   )ru   rv   r   r%   )r   r&   )r   r   r   r   rR   )r   r   r   r>   r   r   )
r   r   r   r%   r   r   r   r   r   r   )r
  r	   r   r   )r   r   )r   r   )F)ru   r  r  r   r   r   )ru   r&  r   r   )ru   r   r   r   )r
  r   r  r   r   r   )r6  r   r7  r   r   r   )r
  rA  r   r   )r
  r\  r   r   )r
  r   r   r   )r
  r&  r   r   )r
  r	   r   r   )Sr   
__module____qualname____doc__r<   r[   staticmethodr*   propertyri   r   r   setterr-   rz   r|   r   r   r   r   r   r   r]   r   r6   r   r   r   r   r   r   r5   r   sysstdoutr	  r  r  r  r%  r(  r+  r*  r5  classmethodr3  rC  rE  rI  rK  rO  rQ  rT  rV  rY  r[  r_  rc  re  rh  rk  rm  rq  rt  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rW   r;   r   r      st       * *X bf59G G G G G2 O$y $y $y \$yL " " " X" \ \ \ X\    X \# # # \#p p p p$   4 4 4 4    X    XR R R R*    X    X   8= = = =$@ @ @ @   
d d d d- - - -
8 8 8 82J J J J
 
 
 
 
	/ 	/ 	/ 	/1 1 1 1# # # #   
b 
b 
b 
b 
b	R 	R 	R 	R '+#cj6 6 6 6 6p   0( ( ( (   
    6   *          @ ? ? ? [?DC C C CK K K K
K K K K
C C C C
C C C C
K K K K
H H H H
P P P P
G G G G
O O O O
F F F F
F F F F
N N N N
N N N N
C C C C
K K K KL L L LT T T TK K K KS S S SL L L LT T T T
C C C CC C C CB B B BL L L LK K K KL L L L
V V V V
V V V V
V V V V
V V V V
L L L L/ / / // / / /
B B BB B B B BrW   r   )+
__future__r   r_   r/   collections.abcr   bitstring.exceptionsr   typingr   r   r   r	   r
   r   r   r   bitstring.bitsr   r   bitstring.bitarray_r   bitstring.dtypesr   r   	bitstringr   bitstring.bitstring_optionsr   r   r  r   r.  r3   r  r?   r=   r%   r&   r   rv   r   r   r   rW   r;   <module>r     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       7 7 7 7 7 7 7 7    				 



 E3UD$67
'))qB qB qB qB qB qB qB qB qB qBrW   