
    ":hF0              	       j   d dl Z d dlZddlmZmZmZmZ ddlmZmZ  ed      Z	 G d de      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j!                  dj#                  d ej%                         D                          Zd Ze
j*                  Zy)    N   )expressions
ParseErrorNodeVisitorGrammar   )ABITypeErrorr   a  
    type = tuple_type / basic_type

    tuple_type = components arrlist?
    components = non_zero_tuple / zero_tuple

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

    zero_tuple = "()"

    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                        e 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d Z ej"                  d       fd       Z xZS )r   z
    Parsimonious node visitor which performs both parsing of type strings and
    post-processing of parse trees.  Parsing operations are cached.
    c                     |\  }}}}|f|z   S N )selfnodevisited_children_firstrests         g/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/static_dependencies/ethereum/abi/grammar.pyvisit_non_zero_tuplez NodeVisitor.visit_non_zero_tuple5   s    ,5$x$    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   tupler   r   r   s      r   visit_zero_tuplezNodeVisitor.visit_zero_tupleF   	    wr   c                 ,    |\  }}}t        ||||      S r   )	BasicType)r   r   r   basesubr   s         r   visit_basic_typezNodeVisitor.visit_basic_typeI   s    -c7sG$77r   c                     |\  }}}||fS r   r   )r   r   r   r   r   seconds         r   visit_two_sizezNodeVisitor.visit_two_sizeN   s    +q&f}r   c                     |\  }}}|fS r   r   )r   r   r   r   	int_values        r   visit_const_arrzNodeVisitor.visit_const_arrT   s    *9a|r   c                     t               S r   r"   r$   s      r   visit_dynam_arrzNodeVisitor.visit_dynam_arrZ   r&   r   c                     |j                   S r   )textr$   s      r   visit_alphaszNodeVisitor.visit_alphas]   s    yyr   c                 ,    t        |j                        S r   )intr5   r$   s      r   visit_digitszNodeVisitor.visit_digits`   s    499~r   c                     t        |j                  t        j                        r|d   S t        |j                  t        j                        rt        |      dk7  r|d   S y t        |      S Nr   )
isinstanceexprr   OneOfOptionallenr#   r$   s      r   generic_visitzNodeVisitor.generic_visitc   s]    dii!2!23#A&&dii!5!56#$)'**%&&r   N)maxsizec                    t        |t              s#t        dj                  t	        |                  	 t
        |   |      S # t        $ r0}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 {}N)r<   str	TypeErrorformattypesuperparser   r5   posr=   )r   type_stre	__class__s      r   rI   zNodeVisitor.parsep   sm     (C(6==d8nM 	47=** 	4QVVQUUAFF33	4s   A 	A>+A99A>)__name__
__module____qualname____doc__grammarr   r   r    r%   r+   r.   r1   r3   r6   r9   rA   	functools	lru_cacherI   __classcell__rM   s   @r   r   r   -   sg    
 G9
8
' Y&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   rY   )r   r   r   s      r   __init__zABIType.__init__   s    	
 		r   c                 z    dj                  t        |       j                  t        | j	                                     S )Nz<{} {}>)rF   rG   rP   reprto_type_strr   s    r   __repr__zABIType.__repr__   s3    J##!!#$
 	
r   c                 t    t        |       t        |      u xr! | j                         |j                         k(  S r   )rG   r^   )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   r^   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`re   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`re   r_   s    r   validatezABIType.validate   s     ""=>>r   c                     | j                   }t        dj                  |j                  |j                  dz   |j
                  |            )NzBFor '{comp_str}' type at column {col} in '{type_str}': {error_msg}r   )comp_strcolrK   	error_msg)r   r	   rF   r5   start	full_text)r   rn   r   s      r   
invalidatezABIType.invalidate   sJ     yy++16JJN#	 ,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`re   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)r@   ).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)rN   rO   rP   rQ   	__slots__r[   r`   rc   r^   propertyrh   rj   rq   rs   ru   r|   r   r   r   rX   rX      s     $I
WB @ @?
  ( ( A A L Lr   rX   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   )rH   r[   r   )r   r   r   r   rM   s       r   r[   zTupleType.__init__   s    $'$	r   c                     | j                   }t        |t              rdj                  d |D              }nd}dj	                  dj                  d | j
                  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=    z({}){},c              3   <   K   | ]  }|j                           y wr   )r^   rx   cs     r   rz   z(TupleType.to_type_str.<locals>.<genexpr>   s     >Q]]_>s   )r   r<   r#   joinrF   r   )r   r   s     r   r^   zTupleType.to_type_str   sX    ,,gu%gg=W==GGHH>doo>>
 	
r   c                     | j                   s(t        dj                  | j                                      t	        |       | j
                  | j                  d d xs d | j                        S Nz2Cannot determine item type for non-array type '{}'r   )rs   
ValueErrorrF   r^   rG   r   r   r   r_   s    r   rh   zTupleType.item_type  sf    }}DKK$$&  tDzOOLL"%
 	
r   c                 F    | j                   D ]  }|j                           y r   )r   rj   )r   r   s     r   rj   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   )rN   rO   rP   rQ   r~   r[   r^   r   rh   rj   ru   rU   rV   s   @r   r   r      sM      I 
 
 
 : :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   )rH   r[   r)   r*   )r   r)   r*   r   r   rM   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   )rD   )rx   ss     r   rz   z(BasicType.to_type_str.<locals>.<genexpr>8  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>=  r   r   )r*   r   r<   r8   rD   r#   r   r)   )r   r*   r   s      r   r^   zBasicType.to_type_str2  s    xxWc3c(CU#((/3//CCgu%gg=W==GGyy3((r   c                     | j                   s(t        dj                  | j                                      t	        |       | j
                  | j                  | j                  d d xs d | j                        S r   )	rs   r   rF   r^   rG   r)   r*   r   r   r_   s    r   rh   zBasicType.item_typeC  sm    }}DKK$$&  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_dynamicS  s8    $$99 99DHH$4r   c                 X   | 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 rt        |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j                  |             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)r8   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   z5fixed exponent size out of bounds, {} must be in 1-80hashz$hash type must have numerical suffixaddresszaddress cannot have suffix)r)   r*   rq   r<   r8   r#   rF   )r   r)   r*   bitsminus_es        r   rj   zBasicType.validate`  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KRR + V^c3' FG ( Y <=  r   r}   )rN   rO   rP   rQ   r~   r[   r^   r   rh   ru   rj   rU   rV   s   @r   r(   r(     sM    
  IT )" 
 
 
 
<>r   r(   int256uint256fixed128x18ufixed128x18bytes24bytes1)r8   r   r   r   functionbytez\b({})\b|c              #   F   K   | ]  }t        j                  |        y wr   )reescaper   s     r   rz   rz     s     J		!Js   !c                 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 r;   )TYPE_ALIASESgroup)matchs    r   <lambda>znormalize.<locals>.<lambda>  s    l5;;q>2 r   )TYPE_ALIAS_REr*   )rK   s    r   	normalizer     s     2 r   )rS   r   parsimoniousr   r   r   r   
exceptionsr	   rR   visitorrX   r   r(   r   compilerF   r   keysr   r   rI   r   r   r   <module>r      s     	 
 :V4+ V4r -YL YLx5: 5:p> >F  

sxxJl6G6G6IJJK
 	r   