
    E#iF0              	       j   S SK r S SKrSSKJrJrJrJr  SSKJrJr  \" S5      r	 " S S\5      r\" 5       r
 " S	 S
5      r " S S\5      r " S S\5      rSSSSSSS.r\R                  " SR!                  SR#                  S \R%                  5        5       5      5      5      rS r\
R*                  rg)    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                      ^  \ rS rSrSr\rS rS rS rS r	S r
S rS	 rS
 rS rS rS r\R$                  " SS9U 4S j5       rSrU =r$ )r   -   z
Parsimonious node visitor which performs both parsing of type strings and
post-processing of parse trees.  Parsing operations are cached.
c                     Uu  p4pSU4U-   $ N )selfnodevisited_children_firstrests         g/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/ethereum/abi/grammar.pyvisit_non_zero_tuple NodeVisitor.visit_non_zero_tuple5   s    ,$x$    c                     Uu  p4[        X4US9$ Nr   )	TupleType)r   r   r   
componentsarrlists        r   visit_tuple_typeNodeVisitor.visit_tuple_type;   s    .
488r   c                     Uu  p4U$ r   r   )r   r   r   r   abi_types        r   visit_next_typeNodeVisitor.visit_next_type@   s    &r   c                     [        5       $ r   tupler   r   r   s      r   visit_zero_tupleNodeVisitor.visit_zero_tupleF   	    wr   c                      Uu  p4n[        X4XQS9$ r   )	BasicType)r   r   r   basesubr   s         r   visit_basic_typeNodeVisitor.visit_basic_typeI   s    -7G77r   c                     Uu  p4nX54$ r   r   )r   r   r   r   r   seconds         r   visit_two_sizeNodeVisitor.visit_two_sizeN   s    +&}r   c                     Uu  p4nU4$ r   r   )r   r   r   r   	int_values        r   visit_const_arrNodeVisitor.visit_const_arrT   s    *a|r   c                     [        5       $ r   r&   r(   s      r   visit_dynam_arrNodeVisitor.visit_dynam_arrZ   r+   r   c                     UR                   $ r   )textr(   s      r   visit_alphasNodeVisitor.visit_alphas]   s    yyr   c                 ,    [        UR                  5      $ r   )intr>   r(   s      r   visit_digitsNodeVisitor.visit_digits`   s    499~r   c                     [        UR                  [        R                  5      (       a  US   $ [        UR                  [        R                  5      (       a  [        U5      S:w  a  US   $ g [        U5      $ Nr   )
isinstanceexprr   OneOfOptionallenr'   r(   s      r   generic_visitNodeVisitor.generic_visitc   sc    dii!2!233#A&&dii!5!566#$)'**%&&r   N)maxsizec                   > [        U[        5      (       d#  [        SR                  [	        U5      5      5      e [
        TU ]  U5      $ ! [         a0  n[        UR                  UR                  UR                  5      eSnAff = f)aQ  
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)rG   str	TypeErrorformattypesuperparser   r>   posrH   )r   type_stre	__class__s      r   rU   NodeVisitor.parsep   sp     (C((6==d8nM 	47=** 	4QVVQUUAFF33	4s   A
 

B+A??Br   )__name__
__module____qualname____firstlineno____doc__grammarr   r   r#   r)   r0   r4   r8   r;   r?   rC   rL   	functools	lru_cacherU   __static_attributes____classcell__rY   s   @r   r   r   -   se    
 G9
8
' &4 '4r   r   c                       \ rS rSrSrSrSS jrS rS rS r	\
S	 5       rS
 rS r\
S 5       r\
S 5       r\
S 5       rSrg)ABIType   z;
Base class for results of type string parsing operations.
r   r   Nc                     Xl          X l        g r   ri   )r   r   r   s      r   __init__ABIType.__init__   s    	
 		r   c                 z    SR                  [        U 5      R                  [        U R	                  5       5      5      $ )Nz<{} {}>)rR   rS   r]   reprto_type_strr   s    r   __repr__ABIType.__repr__   s3    J##!!#$
 	
r   c                 ~    [        U 5      [        U5      L =(       a!    U R                  5       UR                  5       :H  $ r   )rS   ro   )r   others     r   __eq__ABIType.__eq__   s1    DzT%[(VT-=-=-?5CTCTCV-VVr   c                     [        S5      e)zu
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`NotImplementedErrorrp   s    r   ro   ABIType.to_type_str   s    
 ""@AAr   c                     [        S5      e)zz
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`rx   rp   s    r   	item_typeABIType.item_type   s     "">??r   c                     [        S5      e)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`rx   rp   s    r   validateABIType.validate   s     ""=>>r   c           	          U R                   n[        SR                  UR                  UR                  S-   UR
                  US95      e)NzBFor '{comp_str}' type at column {col} in '{type_str}': {error_msg}r   )comp_strcolrW   	error_msg)r   r	   rR   r>   start	full_text)r   r   r   s      r   
invalidateABIType.invalidate   sJ     yy++16JJN#	 ,2 ,
 	
r   c                     U R                   SL$ )zx
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   rp   s    r   is_arrayABIType.is_array   s     ||4''r   c                     [        S5      e)z^
Equal to ``True`` if a type has a dynamically sized encoding.
Otherwise, equal to ``False``.
zMust implement `is_dynamic`rx   rp   s    r   
is_dynamicABIType.is_dynamic   s     ""?@@r   c                 `    U R                   =(       a    [        S U R                   5       5      $ )Nc              3   >   #    U  H  n[        U5      S :H  v   M     g7f)r   N)rK   ).0dims     r   	<genexpr>/ABIType._has_dynamic_arrlist.<locals>.<genexpr>   s     $KlsSX]ls   )r   anyr   rp   s    r   _has_dynamic_arrlistABIType._has_dynamic_arrlist   s     }}K$Kdll$K!KKr   NN)r[   r\   r]   r^   r_   	__slots__rk   rq   ru   ro   propertyr|   r   r   r   r   r   rc   r   r   r   rg   rg      s     $I
WB @ @?
  ( ( A A L Lr   rg   c                   h   ^  \ rS rSrSrSrSSS.U 4S jjjrS r\S 5       r	S	 r
\S
 5       rSrU =r$ )r      zI
Represents the result of parsing a tuple type string e.g. "(int,bool)".
)r   Nr   c                0   > [         TU ]  X#5        Xl        g r   )rT   rk   r   )r   r   r   r   rY   s       r   rk   TupleType.__init__   s    '$	r   c                     U R                   n[        U[        5      (       a  SR                  S U 5       5      nOSnSR	                  SR                  S U R
                   5       5      U5      $ )N c              3   J   #    U  H  n[        [        U5      5      v   M     g 7fr   rn   listr   as     r   r   (TupleType.to_type_str.<locals>.<genexpr>        =Wd47mmW   !#z({}){},c              3   @   #    U  H  oR                  5       v   M     g 7fr   )ro   r   cs     r   r   r      s     >o]]__os   )r   rG   r'   joinrR   r   )r   r   s     r   ro   TupleType.to_type_str   s[    ,,gu%%gg=W==GGHH>doo>>
 	
r   c                     U R                   (       d(  [        SR                  U R                  5       5      5      e[	        U 5      " U R
                  U R                  S S =(       d    S U R                  S9$ Nz2Cannot determine item type for non-array type '{}'r   )r   
ValueErrorrR   ro   rS   r   r   r   rp   s    r   r|   TupleType.item_type  sd    }}DKK$$&  DzOOLL"%
 	
r   c                 J    U R                    H  nUR                  5         M     g r   )r   r   )r   r   s     r   r   TupleType.validate  s    AJJL !r   c                 ^    U R                   (       a  g[        S U R                   5       5      $ )NTc              3   8   #    U  H  oR                   v   M     g 7fr   )r   r   s     r   r   'TupleType.is_dynamic.<locals>.<genexpr>  s     9A<<   )r   r   r   rp   s    r   r   TupleType.is_dynamic  s#    $$9999r   r   )r[   r\   r]   r^   r_   r   rk   ro   r   r|   r   r   rc   rd   re   s   @r   r   r      sR      I  
 
 
 : :r   r   c                   h   ^  \ rS rSrSrSrSSS.U 4S jjjrS r\S 5       r	\S	 5       r
S
 rSrU =r$ )r-   i  zc
Represents the result of parsing a basic type string e.g. "uint", "address",
"ufixed128x19[][2]".
)r.   r/   Nr   c                >   > [         TU ]  X45        Xl         X l        g r   )rT   rk   r.   r/   )r   r.   r/   r   r   rY   s        r   rk   BasicType.__init__%  s"    '	E	r   c                 V   U R                   U R                  p![        U[        5      (       a  [	        U5      nO0[        U[
        5      (       a  SR                  S U 5       5      nOSn[        U[
        5      (       a  SR                  S U 5       5      nOSnU R                  U-   U-   $ )Nxc              3   8   #    U  H  n[        U5      v   M     g 7fr   )rP   )r   ss     r   r   (BasicType.to_type_str.<locals>.<genexpr>8  s     /3a3q663r   r   c              3   J   #    U  H  n[        [        U5      5      v   M     g 7fr   r   r   s     r   r   r   =  r   r   )r/   r   rG   rB   rP   r'   r   r.   )r   r/   r   s      r   ro   BasicType.to_type_str2  s    xxWc3c(CU##((/3//CCgu%%gg=W==GGyy3((r   c                     U R                   (       d(  [        SR                  U R                  5       5      5      e[	        U 5      " U R
                  U R                  U R                  S S =(       d    S U R                  S9$ r   )	r   r   rR   ro   rS   r.   r/   r   r   rp   s    r   r|   BasicType.item_typeC  sk    }}DKK$$&  DzIIHHLL"%	
 	
r   c                     U R                   (       a  gU R                  S:X  a  gU R                  S:X  a  U R                  c  gg)NTstringbytesF)r   r.   r/   rp   s    r   r   BasicType.is_dynamicS  s8    $$99 99DHH$4r   c                    U R                   U R                  p!US:X  a  Ub  U R                  S5        g g US:X  aX  Ub&  [        U[        5      (       d  U R                  S5        [        U[        5      (       a  US:  a  U R                  S5        g g g US;   a_  [        U[        5      (       d  U R                  S5        US	:  d  S
U:  a  U R                  S5        US	-  S:w  a  U R                  S5        g g US;   a  [        U[
        5      (       d  U R                  S5        Uu  p4US	:  d  S
U:  a  U R                  S5        US	-  S:w  a  U R                  S5        US:  d  SU:  a!  U R                  SR                  U5      5        g g US:X  a(  [        U[        5      (       d  U R                  S5        g g US:X  a  Ub  U R                  S5        g g g )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)rB   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/   r   rG   rB   r'   rR   )r   r.   r/   bitsminus_es        r   r   BasicType.validate`  s   IItxxc 8 @A  W_K:c3#7#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   )r[   r\   r]   r^   r_   r   rk   ro   r   r|   r   r   rc   rd   re   s   @r   r-   r-     sW    
  IT  )" 
 
 
 
<> <>r   r-   int256uint256fixed128x18ufixed128x18bytes24bytes1)rB   r   r   r   functionbytez\b({})\b|c              #   N   #    U  H  n[         R                  " U5      v   M     g 7fr   )reescaper   s     r   r   r     s     J6I		!6Is   #%c                 0    [         R                  S U 5      $ )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    [         U R                  S5         $ rF   )TYPE_ALIASESgroup)matchs    r   <lambda>normalize.<locals>.<lambda>  s    l5;;q>2r   )TYPE_ALIAS_REr/   )rW   s    r   	normalizer     s     2 r   )ra   r   parsimoniousr   r   r   r   
exceptionsr	   r`   visitorrg   r   r-   r   compilerR   r   keysr   r   rU   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   