
    M@ct                     f    d dl Z dZedz
   ZddZd Zd ZddZddZdd	Zd
 Z	de
fdZdefdZy)    Ni      c                    |dk  s|dkD  rt        d|       g }| D cg c]  }t        |g       c}D ]  }g }t        |      }|dkD  r|j                  |dz         |dz  }|dkD  rt	        |      |k  r"|j                  dg|t	        |      z
  z         nt	        |      |kD  r|d| }|j                          |j                  |        |S c c}w )zAccepts a string of ``bytes`` (chars) and returns an array of bits
    representing the bytes in big endian byte order. An optional max ``sz`` for
    each byte (default 8 bits/byte) which can  be used to mask out higher
    bits.r      zInvalid sz value: r   N)
ValueErrorbytesordappendlenextendreverse)bitesszretvalbbitss        6/usr/lib/python3/dist-packages/eyed3/utils/binfuncs.py	bytes2binr      s    
 
Ava-bT233F"'(QeQCj( F!eKKA!GA !e t9r>KKrCI~./Y^9D 	d  M! )s   Cc                 8   g }|j                  |        |j                          d}d}d}d}|D ]/  }|dz  }|||z  z  }|dz  }|dk(  sd}|t        |g      z  }d}d}1 |dkD  r|t        |g      z  }t        |      }|j                          t        |      }|S )zAConvert an array of bits (MSB first) into a string of characters.r       r      r   )r   r   r   	bytearray)xr   ioutmultittlr   s          r   	bin2bytesr   5   s    DKKNLLN	A
CE
C 	Qq5y
6A5#<CEC qyucU|
C.CKKM
*CJr   c                 |    g }|j                  |        |j                          d}d}|D ]  }|||z  z  }|dz  } |S )zEConvert ``x``, an array of "bits" (MSB first), to it's decimal value.r   r   r   )r   r   )r   r   r   valuer   s        r   bin2decr    R   sR    DKKNLLNEE U
 Lr   c                 ,    t        t        | |            S N)r    r   )r   r   s     r   	bytes2decr#   `   s    9UB'((r   c                    | dk\  sJ t        |       t        urt        |       } g }| dkD  r|j                  | dz         | dz  } | dkD  r|dkD  r!|j                  dg|t	        |      z
  z         |j                          |S )zrConvert a decimal value ``n`` to an array of bits (MSB first).
    Optionally, pad the overall size to ``p`` bits.r   r   )typeintr	   r   r
   r   )npr   s      r   dec2binr)   d   s     6M6AwcFF
a%a!e	a a% 	1uqcQV_-.
NNMr   c                 ,    t        t        | |            S r"   )r   r)   )r'   r(   s     r   	dec2bytesr+   v   s    WQ]##r   c                    t        |       }t        |       dkD  s|dkD  rt        dt        |       z        t        |       dk  r| S t	        |dz	  dz  |dz	  dz  |dz	  dz  |d	z	  dz  g      }t        |      }t        |      dk(  sJ |S )
zoConvert ``x``, a list of bits (MSB first), to a synch safe list of bits.
    (section 6.2 of the ID3 2.4 spec).    i   zInvalid value: %sr               r   )r    r
   r   strr   r   )r   r'   r   r   s       r   bin2synchsafer3   z   s     	
A
1v{a)m,s1v566	Q!AGt#Gt#Fd?Fd? E
 UDt9??Kr   r   c                 j    t        |       dk7  rt        d      t        j                  d|       }|d   S )Nr   z&Signed 16 bit integer MUST be 2 bytes.>hr   )r
   r   structunpack)r   r   s     r   bytes2signedInt16r8      s2    
5zQABBdE"AQ4Kr   r'   c                     t        |       } t        | cxk  r	t        k  rn nt        j                  d|       S t        d|        )Nr5   zSigned int16 out of range: )r&   	MIN_INT16	MAX_INT16r6   packr   )r'   s    r   signedInt162bytesr=      s<    AAA""{{4##
21#6
77r   )r   )r   )r6   r;   r:   r   r   r    r#   r)   r+   r3   r   r8   r&   r=    r   r   <module>r?      sV   & 	!m	8:)$$(U 8 8r   