
    (i                         d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlZe j                  dk\  rd dlmZ nd dlmZ  G d d	ej                         Zy)
    N)AnyDictUnioncast)keccak)pipe)HexBytes)      )Selfc                        e Zd ZdZedeeef   defd       Z	ede
eef   defd       ZdefdZdef fdZdeeef   f fd	Z xZS )
HashableRLPa  
    An extension of :class:`rlp.Serializable`. In addition to the below
    functions, the class is iterable.

    Use like:

    ::

        class MyRLP(HashableRLP):
            fields = (
                ('name1', rlp.sedes.big_endian_int),
                ('name2', rlp.sedes.binary),
                etc...
            )

        my_obj = MyRLP(name2=b'\xff', name1=1)
        list(my_obj) == [1, b'\xff']
        # note that the iteration order is always in RLP-defined order
    
field_dictreturnc                      | di |S )a  
        In addition to the standard initialization of.

        ::

            my_obj = MyRLP(name1=1, name2=b'\xff')

        This method enables initialization with.

        ::

            my_obj = MyRLP.from_dict({'name1': 1, 'name2': b'\xff'})

        In general, the standard initialization is preferred, but
        some approaches might favor this API, like when using
        :meth:`toolz.functoolz.pipe`.

        ::

            return eth_utils.toolz.pipe(
                my_dict,
                normalize,
                validate,
                MyRLP.from_dict,
            )

        :param dict field_dict: the dictionary of values to initialize with
        :returns: the new rlp object
        :rtype: HashableRLP
         r   )clsr   s     =/var/www/br/venv/lib/python3.12/site-packages/eth_rlp/main.py	from_dictzHashableRLP.from_dict3   s    @  Z      serialized_bytesc                 N    t        j                  ||       }t        t        |      S )z
        Shorthand invocation for :meth:`rlp.decode` using this class.

        :param bytes serialized_bytes: the byte string to decode
        :return: the decoded object
        :rtype: HashableRLP
        )rlpdecoder   r   )r   r   decodeds      r   
from_byteszHashableRLP.from_bytesU   s"     **-s3D'""r   c                 R    t        t        | t        j                  t                    S )zf
        :returns: the hash of the encoded bytestring
        :rtype: ~hexbytes.main.HexBytes
        )r	   r   r   encoder   )selfs    r   hashzHashableRLP.hasha   s&    
 


 	
r   c                 v     t         d      rt         fd j                  D              S t                  S )Nfieldsc              3   <   K   | ]  \  }}t        |        y w)N)getattr).0field_r   s      r   	<genexpr>z'HashableRLP.__iter__.<locals>.<genexpr>p   s     Ie,Is   )hasattriterr"   super__iter__)r   	__class__s   `r   r,   zHashableRLP.__iter__n   s0    4"IT[[III7#%%r   c                     	 t         |          }t        t        t        t
        f   |      S # t        $ r+ t        |       }t        t        t        t
        f   |      cY S w xY w)z
        Convert rlp object to a dict

        :returns: mapping of RLP field names to field values
        :rtype: dict
        )r+   as_dictr   r   strr   AttributeErrorvars)r   _as_dictr-   s     r   r/   zHashableRLP.as_dictt   sV    	2w(HS#X11 	2DzHS#X11	2s   *. 1A"!A")__name__
__module____qualname____doc__classmethodr   r0   r   r   r   r   bytes	bytearrayr   r	   r    r,   r/   __classcell__)r-   s   @r   r   r      s    ( !4S> !d ! !B 	#%y0@*A 	#d 	# 	#
h 
&# &2c3h 2 2r   r   )systypingr   r   r   r   	eth_utilsr   eth_utils.toolzr   hexbytesr	   r   version_infor   typing_extensionsSerializabler   r   r   r   <module>rD      sR    
  w
b2#"" b2r   