
    &i                     p    d dl mZmZmZmZmZmZmZ ddlm	Z	 erd dl m
Z
 eeeeeeef   Z G d de      Zy)    )TYPE_CHECKINGCallableTupleTypeUnioncastoverload   )to_bytes)SupportsIndexc                        e Zd ZdZdee   dedd f fdZeddde	fd       Z
ededd fd	       Z
dedef   dee	ed f   f fd
Z
defdZdefdZdeedef   eed    ef   f   fdZ xZS )HexBytesaW  
    Thin wrapper around the python built-in :class:`bytes` class.

    It has these changes:
        1. Accepts more initializing values: bool, bytearray, bytes, (non-negative) int,
           str, and memoryview
        2. The representation at console (__repr__) is 0x-prefixed
        3. ``to_0x_hex`` returns a 0x-prefixed hex string
    clsvalreturnc                 V    t        |      }t        t        t        |   | |            S N)r   r   r   super__new__)r   r   bytesval	__class__s      >/var/www/br/venv/lib/python3.12/site-packages/hexbytes/main.pyr   zHexBytes.__new__"   s$    C=Hegoc8<==    keyr   c                      y r    selfr   s     r   __getitem__zHexBytes.__getitem__&       r   c                      y r   r   r   s     r   r   zHexBytes.__getitem__*   r    r   c                 `    t         |   |      }t        |d      r t        |       |      S |S )Nhex)r   r   hasattrtype)r   r   resultr   s      r   r   zHexBytes.__getitem__.   s4     $S)65!4:f%%Mr   c                 0    dd| j                         z   dS )Nz	HexBytes(0x)r#   r   s    r   __repr__zHexBytes.__repr__7   s    4$((*,/q11r   c                 (    d| j                         z   S )z?
        Convert the bytes to a 0x-prefixed hex string
        r(   r*   r+   s    r   	to_0x_hexzHexBytes.to_0x_hex:   s     dhhj  r   .c                 N    t         j                  t        |       t        |       ffS )z
        An optimized ``__reduce__`` that bypasses the input validation in
        ``HexBytes.__new__`` since an existing HexBytes instance has already been
        validated when created.
        )bytesr   r%   r+   s    r   
__reduce__zHexBytes.__reduce__@   s      }}tDz5;777r   )__name__
__module____qualname____doc__r   r0   	BytesLiker   r	   intr   slicer   strr,   r.   r   r   r1   __classcell__)r   s   @r   r   r      s    >T%[ >y >Z >  3   u   %/0	sE:%	&2# 2!3 !8	xU
#U4
+;U+B%CC	D8r   r   N)typingr   r   r   r   r   r   r	   _utilsr   r   bool	bytearrayr0   r7   r9   
memoryviewr6   r   r   r   r   <module>r@      sH       $	5#sJ>?	18u 18r   