
    (iG0                     x   d dl Z d dlZd dlZd dlmZ d dlmZmZ  ej                  d      Z G d dej                        Z	 e	       Z
 G d d      Z G d	 d
e      Z G d de      ZdddddddZ ej                  ddj!                  d ej#                         D               d      Zd Ze
j(                  Zy)    N)expressions)ABITypeError
ParseErrora  
    type = tuple_type / basic_type

    tuple_type = components arrlist?
    components = non_zero_tuple

    non_zero_tuple = "(" type next_type* ")"
    next_type = "," type

    basic_type = base sub? arrlist?

    base = alphas

    sub = two_size / digits
    two_size = (digits "x" digits)

    arrlist = (const_arr / dynam_arr)+
    const_arr = "[" digits "]"
    dynam_arr = "[]"

    alphas = ~"[A-Za-z]+"
    digits = ~"[1-9][0-9]*"
    c                   h     e Zd ZdZd ZeZd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Z fdZ xZS )NodeVisitorz
    Parsimonious node visitor which performs both parsing of type strings and
    post-processing of parse trees.  Parsing operations are cached.
    c                 Z     t        j                  d       | j                        | _        y )N)maxsize)	functools	lru_cache_parse_uncachedparseselfs    @/var/www/br/venv/lib/python3.12/site-packages/eth_abi/grammar.py__init__zNodeVisitor.__init__/   s!    6Y((6t7K7KL
    c                     |\  }}}}|f|z   S N )r   nodevisited_children_firstrests         r   visit_non_zero_tuplez NodeVisitor.visit_non_zero_tuple4   s    ,5$x$r   c                 (    |\  }}t        |||      S Nr   )	TupleType)r   r   r   
componentsarrlists        r   visit_tuple_typezNodeVisitor.visit_tuple_type:   s    .
GW488r   c                     |\  }}|S r   r   )r   r   r   r   abi_types        r   visit_next_typezNodeVisitor.visit_next_type?   s    &8r   c                 ,    |\  }}}t        ||||      S r   )	BasicType)r   r   r   basesubr!   s         r   visit_basic_typezNodeVisitor.visit_basic_typeE   s    -c7sG$77r   c                     |\  }}}||fS r   r   )r   r   r   r   r   seconds         r   visit_two_sizezNodeVisitor.visit_two_sizeJ   s    +q&f}r   c                     |\  }}}|fS r   r   )r   r   r   r   	int_values        r   visit_const_arrzNodeVisitor.visit_const_arrP   s    *9a|r   c                     t               S r   )tupler   r   r   s      r   visit_dynam_arrzNodeVisitor.visit_dynam_arrV   s	    wr   c                     |j                   S r   )textr3   s      r   visit_alphaszNodeVisitor.visit_alphasY   s    yyr   c                 ,    t        |j                        S r   )intr6   r3   s      r   visit_digitszNodeVisitor.visit_digits\   s    499~r   c                    |j                   }t        |t        j                        r|d   S t        |t        j                        r2|j
                  dk(  r#|j                  dk(  rt        |      dk7  r|d   S y t        |      S )Nr      )	expr
isinstancer   OneOf
Quantifierminmaxlenr2   )r   r   r   r=   s       r   generic_visitzNodeVisitor.generic_visit_   ss    yydK--.#A&&dK223A$((VW-#$)'**%&&r   c                    t        |t              st        dt        |             	 t	        |   |fi |S # t        j                  $ r?}d|v rt        d      t        |j                  |j                  |j                        d}~ww xY w)a  
        Parses a type string into an appropriate instance of
        :class:`~eth_abi.grammar.ABIType`.  If a type string cannot be parsed,
        throws :class:`~eth_abi.exceptions.ParseError`.

        :param type_str: The type string to be parsed.
        :returns: An instance of :class:`~eth_abi.grammar.ABIType` containing
            information about the parsed type string.
        z"Can only parse string values: got z()z.Zero-sized tuple types "()" are not supported.N)r>   str	TypeErrortypesuperr   parsimoniousr   
ValueErrorr6   posr=   )r   type_strkwargse	__class__s       r   r   zNodeVisitor._parse_uncachedn   s     (C(@h@PQRR		47=4V44&& 	4 x !QRRQVVQUUAFF33	4s   : B:BB)__name__
__module____qualname____doc__r   grammarr   r"   r%   r*   r-   r0   r4   r7   r:   rD   r   __classcell__rP   s   @r   r   r   )   sQ    
M G9
8
'4 4r   r   c                   z    e Zd ZdZdZddZd Zd Zd Ze	d        Z
d	 Zd
 Ze	d        Ze	d        Ze	d        Zy)ABITypezC
    Base class for results of type string parsing operations.
    r!   r   Nc                 "    || _         	 || _        y r   rZ   )r   r!   r   s      r   r   zABIType.__init__   s    	
 		r   c                 h    dt        |       j                   dt        | j                                dS )N< >)rH   rS   reprto_type_strr   s    r   __repr__zABIType.__repr__   s1    4:**+1T$2B2B2D-E,FaHHr   c                 t    t        |       t        |      u xr! | j                         |j                         k(  S r   )rH   ra   )r   others     r   __eq__zABIType.__eq__   s1    DzT%[(VT-=-=-?5CTCTCV-VVr   c                     t        d      )z
        Returns the string representation of an ABI type.  This will be equal to
        the type string from which it was created.
        zMust implement `to_type_str`NotImplementedErrorr   s    r   ra   zABIType.to_type_str   s    
 ""@AAr   c                     t        d      )z
        If this type is an array type, equal to an appropriate
        :class:`~eth_abi.grammar.ABIType` instance for the array's items.
        zMust implement `item_type`rg   r   s    r   	item_typezABIType.item_type   s     "">??r   c                     t        d      )z
        Validates the properties of an ABI type against the solidity ABI spec:

        https://solidity.readthedocs.io/en/develop/abi-spec.html

        Raises :class:`~eth_abi.exceptions.ABITypeError` if validation fails.
        zMust implement `validate`rg   r   s    r   validatezABIType.validate   s     ""=>>r   c           
          | j                   }t        d|j                   d|j                  dz    d|j                   d|       )NzFor 'z' type at column r<   z in 'z': )r   r   r6   start	full_text)r   	error_msgr   s      r   
invalidatezABIType.invalidate   sP     yyDII;/

Q/? @>>"#i[2
 	
r   c                     | j                   duS )z
        Equal to ``True`` if a type is an array type (i.e. if it has an array
        dimension list).  Otherwise, equal to ``False``.
        N)r!   r   s    r   is_arrayzABIType.is_array   s     ||4''r   c                     t        d      )zv
        Equal to ``True`` if a type has a dynamically sized encoding.
        Otherwise, equal to ``False``.
        zMust implement `is_dynamic`rg   r   s    r   
is_dynamiczABIType.is_dynamic   s     ""?@@r   c                 V    | j                   xr t        d | j                  D              S )Nc              3   8   K   | ]  }t        |      d k(    yw)r   N)rC   ).0dims     r   	<genexpr>z/ABIType._has_dynamic_arrlist.<locals>.<genexpr>   s     $KsSX]$Ks   )rs   anyr!   r   s    r   _has_dynamic_arrlistzABIType._has_dynamic_arrlist   s     }}K$Kdll$K!KKr   NN)rQ   rR   rS   rT   	__slots__r   rb   re   ra   propertyrj   rl   rq   rs   ru   r|   r   r   r   rY   rY      s     $IIWB @ @?	
 ( ( A A L Lr   rY   c                   Z     e Zd ZdZdZd
dd fdZd Zed        Zd Z	ed	        Z
 xZS )r   zQ
    Represents the result of parsing a tuple type string e.g. "(int,bool)".
    )r    Nr   c                4    t         |   ||       || _        y r   )rI   r   r    )r   r    r!   r   rP   s       r   r   zTupleType.__init__   s    $'$	r   c                     | j                   }t        |t              rdj                  d |D              }nd}ddj                  d | j                  D               d| S )N c              3   D   K   | ]  }t        t        |              y wr   r`   listrx   as     r   rz   z(TupleType.to_type_str.<locals>.<genexpr>        =d47m=    (,c              3   <   K   | ]  }|j                           y wr   )ra   rx   cs     r   rz   z(TupleType.to_type_str.<locals>.<genexpr>   s     EAMMOEs   ))r!   r>   r2   joinr    )r   r!   s     r   ra   zTupleType.to_type_str   sU    ,,gu%gg=W==GG388ET__EEFayQQr   c                     | j                   st        d| j                          d       t        |       | j                  | j
                  d d xs d | j                        S Nz/Cannot determine item type for non-array type ''r   )rs   rK   ra   rH   r    r!   r   r   s    r   rj   zTupleType.item_type   sc    }}A$BRBRBTAUUVW  tDzOOLL"%
 	
r   c                 F    | j                   D ]  }|j                           y r   )r    rl   )r   r   s     r   rl   zTupleType.validate  s     	AJJL	r   c                 T    | j                   ryt        d | j                  D              S )NTc              3   4   K   | ]  }|j                     y wr   )ru   r   s     r   rz   z'TupleType.is_dynamic.<locals>.<genexpr>  s     9A1<<9s   )r|   r{   r    r   s    r   ru   zTupleType.is_dynamic	  s#    $$9999r   r   )rQ   rR   rS   rT   r~   r   ra   r   rj   rl   ru   rV   rW   s   @r   r   r      sN      I R 

 

 : :r   r   c                   Z     e Zd ZdZdZd
dd fdZd Zed        Zed        Z	d	 Z
 xZS )r'   zo
    Represents the result of parsing a basic type string e.g. "uint", "address",
    "ufixed128x19[][2]".
    )r(   r)   Nr   c                D    t         |   ||       || _        	 || _        y r   )rI   r   r(   r)   )r   r(   r)   r!   r   rP   s        r   r   zBasicType.__init__  s(    $'	E	r   c                 :   | j                   | j                  }}t        |t              rt	        |      }n+t        |t
              rdj                  d |D              }nd}t        |t
              rdj                  d |D              }nd}| j                  |z   |z   S )Nxc              3   2   K   | ]  }t        |        y wr   )rF   )rx   ss     r   rz   z(BasicType.to_type_str.<locals>.<genexpr>,  s     /a3q6/s   r   c              3   D   K   | ]  }t        t        |              y wr   r   r   s     r   rz   z(BasicType.to_type_str.<locals>.<genexpr>1  r   r   )r)   r!   r>   r9   rF   r2   r   r(   )r   r)   r!   s      r   ra   zBasicType.to_type_str&  s    xxWc3c(CU#((/3//CCgu%gg=W==GGyy3((r   c                     | j                   st        d| j                          d       t        |       | j                  | j
                  | j                  d d xs d | j                        S r   )rs   rK   ra   rH   r(   r)   r!   r   r   s    r   rj   zBasicType.item_type7  sj    }}A$BRBRBTAUUVW  tDzIIHHLL"%	
 	
r   c                 v    | j                   ry| j                  dk(  ry| j                  dk(  r| j                  yy)NTstringbytesF)r|   r(   r)   r   s    r   ru   zBasicType.is_dynamicE  s8    $$99 99DHH$4r   c                 B   | j                   | j                  }}|dk(  r|| j                  d       y y |dk(  rL|!t        |t              s| j                  d       t        |t              r|dkD  r| j                  d       y y y |dv rWt        |t              s| j                  d       |d	k  sd
|k  r| j                  d       |d	z  dk7  r| j                  d       y y |dv r{t        |t
              s| j                  d       |\  }}|d	k  sd
|k  r| j                  d       |d	z  dk7  r| j                  d       |dk  sd|k  r| j                  d| d       y y |dk(  r#t        |t              s| j                  d       y y |dk(  r|| j                  d       y y y )Nr   zstring type cannot have suffixr   z;bytes type must have either no suffix or a numerical suffix    z'maximum 32 bytes for fixed-length bytes)r9   uintz'integer type must have numerical suffix      z)integer size out of bounds (max 256 bits)r   z"integer size must be multiple of 8)fixedufixedzBfixed type must have suffix of form <bits>x<exponent>, e.g. 128x19z'fixed size out of bounds (max 256 bits)z fixed size must be multiple of 8r<   P   z#fixed exponent size out of bounds, z must be in 1-80hashz$hash type must have numerical suffixaddresszaddress cannot have suffix)r(   r)   rq   r>   r9   r2   )r   r(   r)   bitsminus_es        r   rl   zBasicType.validateR  s   IItxxc 8 @A  W_K:c3#7Q #s#b IJ )1# _$c3' IJQw#) KLQw!| DE  ((c5)"
  MD'ax3: IJax1} BC{b7l9'BRS + V^c3' FG ( Y <=  r   r}   )rQ   rR   rS   rT   r~   r   ra   r   rj   ru   rl   rV   rW   s   @r   r'   r'     sM    
  IT )" 
 
 
 
:>r   r'   int256uint256fixed128x18ufixed128x18bytes24bytes1)r9   r   r   r   functionbytez\b(|c              #   F   K   | ]  }t        j                  |        y wr   )reescaper   s     r   rz   rz     s     >QBIIaL>s   !z)\bc                 0    t         j                  d |       S )z
    Normalizes a type string into its canonical version e.g. the type string
    'int' becomes 'int256', etc.

    :param type_str: The type string to be normalized.
    :returns: The canonical version of the input type string.
    c                 2    t         | j                  d         S )Nr   )TYPE_ALIASESgroup)matchs    r   <lambda>znormalize.<locals>.<lambda>  s    l5;;q>2 r   )TYPE_ALIAS_REr)   )rM   s    r   	normalizer     s     2 r   )r
   r   rJ   r   eth_abi.exceptionsr   r   GrammarrU   r   visitorrY   r   r'   r   compiler   keysr   r   r   r   r   r   <module>r      s     	 
 ,

6[4,** [4| -QL QLh0: 0:f{> {>~  


388>,*;*;*=>>
?sC
 	r   