
    (i                         d dl mZmZmZmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZ  G d d	      Z G d
 de      Z G d de      Z G d dee      Zy)    )AnyIterableTuplecast)	DecodableTypeStr)ContextFramesBytesIOTupleDecoder)TupleEncoder)EncodingError)ABIRegistry)validate_bytes_paramvalidate_list_like_paramc                       e Zd ZdZdefdZy)BaseABICoderz
    Base class for porcelain coding APIs.  These are classes which wrap
    instances of :class:`~eth_abi.registry.ABIRegistry` to provide last-mile
    coding functionality.
    registryc                     || _         y)z
        Constructor.

        :param registry: The registry providing the encoders to be used when
            encoding values.
        N)	_registry)selfr   s     >/var/www/br/venv/lib/python3.12/site-packages/eth_abi/codec.py__init__zBaseABICoder.__init__'   s     "    N)__name__
__module____qualname____doc__r   r    r   r   r   r       s    " "r   r   c                   T    e Zd ZdZdee   dee   defdZdedede	fdZ
dede	fd	Zy
)
ABIEncoderzG
    Wraps a registry to provide last-mile encoding functionality.
    typesargsreturnc                     t        |d       t        |d       |D cg c]  }| j                  j                  |       }}t        |      } ||      S c c}w )a*  
        Encodes the python values in ``args`` as a sequence of binary values of
        the ABI types in ``types`` via the head-tail mechanism.

        :param types: A list or tuple of string representations of the ABI types
            that will be used for encoding e.g.  ``('uint256', 'bytes[]',
            '(int,int)')``
        :param args: A list or tuple of python values to be encoded.

        :returns: The head-tail encoded binary representation of the python
            values in ``args`` as values of the ABI types in ``types``.
        r    r!   )encoders)r   r   get_encoderr   )r   r    r!   type_strr$   encoders         r   encodezABIEncoder.encode6   sT     	!0 v.INOXDNN..x8OO1t}	 Ps   "Atypargc                     | j                  |      sy| j                  j                  |      }	 |j                  |       y# t        $ r Y yt
        $ r 	  ||       Y y# t        $ r Y Y yw xY ww xY w)a  
        Determines if the python value ``arg`` is encodable as a value of the
        ABI type ``typ``.

        :param typ: A string representation for the ABI type against which the
            python value ``arg`` will be checked e.g. ``'uint256'``,
            ``'bytes[]'``, ``'(int,int)'``, etc.
        :param arg: The python value whose encodability should be checked.

        :returns: ``True`` if ``arg`` is encodable as a value of the ABI type
            ``typ``.  Otherwise, ``False``.
        FT)is_encodable_typer   r%   validate_valuer   AttributeError)r   r)   r*   r'   s       r   is_encodablezABIEncoder.is_encodableM   s     %%c*..,,S1	""3'   	 	  ! 	s/   A 	A0A0A	A,(A0+A,,A0c                 8    | j                   j                  |      S )a  
        Returns ``True`` if values for the ABI type ``typ`` can be encoded by
        this codec.

        :param typ: A string representation for the ABI type that will be
            checked for encodability e.g. ``'uint256'``, ``'bytes[]'``,
            ``'(int,int)'``, etc.

        :returns: ``True`` if values for ``typ`` can be encoded by this codec.
            Otherwise, ``False``.
        )r   has_encoder)r   r)   s     r   r,   zABIEncoder.is_encodable_typek   s     ~~))#..r   N)r   r   r   r   r   r   r   bytesr(   boolr/   r,   r   r   r   r   r   1   sW    HW- Xc] u . c d </W / /r   r   c                   @    e Zd ZdZeZ	 d	dee   dede	de
edf   fdZy)

ABIDecoderzG
    Wraps a registry to provide last-mile decoding functionality.
    r    datastrictr"   .c                    t        |d       t        |d       |D cg c]  }| j                  j                  ||      ! }}t	        |      }| j                  |      }t        t        t        df    ||            S c c}w )ak  
        Decodes the binary value ``data`` as a sequence of values of the ABI types
        in ``types`` via the head-tail mechanism into a tuple of equivalent python
        values.

        :param types: A list or tuple of string representations of the ABI types that
            will be used for decoding e.g. ``('uint256', 'bytes[]', '(int,int)')``
        :param data: The binary value to be decoded.
        :param strict: If ``False``, dynamic-type decoders will ignore validations such
            as making sure the data is padded to a multiple of 32 bytes or checking that
            padding bytes are zero / empty. ``False`` is how the Solidity ABI decoder
            currently works. However, ``True`` is the default for the eth-abi library.

        :returns: A tuple of equivalent python values for the ABI values
            represented in ``data``.
        r    r6   )r7   )decoders.)	r   r   r   get_decoderr
   stream_classr   r   r   )r   r    r6   r7   r&   r9   decoderstreams           r   decodezABIDecoder.decode   s    . 	!0T6* QV
DLDNN&&x&?
 
 1""4(E#s(OWV_55
s   $A?N)T)r   r   r   r   r	   r;   r   r   r   r3   r   r   r>   r   r   r   r5   r5   z   sK     (L 	!6 !6 !6 	!6
 
sCx!6r   r5   c                       e Zd Zy)ABICodecN)r   r   r   r   r   r   r@   r@      s    r   r@   N)typingr   r   r   r   eth_typing.abir   r   eth_abi.decodingr	   r
   eth_abi.encodingr   eth_abi.exceptionsr   eth_abi.registryr   eth_abi.utils.validationr   r   r   r   r5   r@   r   r   r   <module>rH      sa    
" ""F/ F/R(6 (6V	z: 	r   