
    &i                     J    d dl Z d dlmZ deeeeeeef   defdZ	dedefdZ
y)    N)Unionvalreturnc                    t        | t              r| S t        | t              rt        |       S t        | t              rt        |       S t        | t
              r| rdS dS t        | t              r(| dk  rt        d|  d      t        t        |             S t        | t              rt        |       S t        d| dt        |        d      )z
    Equivalent to: `eth_utils.hexstr_if_str(eth_utils.to_bytes, val)` .

    Convert a hex string, integer, or bool, to a bytes representation.
    Alternatively, pass through bytes or bytearray as a bytes value.
           r   z Cannot convert negative integer z	 to byteszCannot convert z	 of type )
isinstancebytesstrhexstr_to_bytes	bytearrayboolint
ValueErrorto_byteshex
memoryview	TypeErrortype)r   s    @/var/www/br/venv/lib/python3.12/site-packages/hexbytes/_utils.pyr   r      s     #u
	C	s##	C	#Sz	C	w*7*	C	 7?uINOOCH%%	C	$Sz/#	$s)INOO    hexstrc                     | j                  d      r| dd  }n| }t        |       dz  rd|z   }n|}	 |j                  d      }t        j                  |      S # t
        $ r t        d| d      w xY w)N)0x0X   0asciizhex string z( may only contain [0-9a-fA-F] characters)
startswithlenencodebinascii	unhexlifyUnicodeDecodeErrorr   )r   non_prefixed_hex
padded_hex	ascii_hexs       r   r   r   #   s    &!!":! 6{Q++
%
-%%g.	 !!),,  
*%MN
 	

s   A A0)r"   typingr   r   r   r
   r   r   r   r   r    r   r   <module>r*      sH    
P%iS*DE P% P8-C -E -r   