o
    ¢ØÆhG0  ã                   @   sÎ   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 d¡ZG dd„ dej	ƒZ	e	ƒ Z
G dd„ dƒZG d	d
„ d
eƒZG dd„ deƒZdddddddœZe dd dd„ e ¡ D ƒ¡› d�¡Zdd„ Ze
jZdS )é    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                       s|   e Zd ZdZdd„ ZeZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡ fdd„Z‡  ZS )ÚNodeVisitorz—
    Parsimonious node visitor which performs both parsing of type strings and
    post-processing of parse trees.  Parsing operations are cached.
    c                 C   s   t jd d�| jƒ| _d S )N)Úmaxsize)Ú	functoolsÚ	lru_cacheÚ_parse_uncachedÚparse©Úself© r   ú\/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/eth_abi/grammar.pyÚ__init__/   s   zNodeVisitor.__init__c                 C   s   |\}}}}|f| S ©Nr   )r   ÚnodeÚvisited_childrenÚ_ÚfirstÚrestr   r   r   Úvisit_non_zero_tuple4   s   
z NodeVisitor.visit_non_zero_tuplec                 C   s   |\}}t |||d�S ©N©r   )Ú	TupleType)r   r   r   Ú
componentsÚarrlistr   r   r   Úvisit_tuple_type:   s   zNodeVisitor.visit_tuple_typec                 C   s   |\}}|S r   r   )r   r   r   r   Úabi_typer   r   r   Úvisit_next_type?   s   zNodeVisitor.visit_next_typec                 C   s   |\}}}t ||||d�S r   )Ú	BasicType)r   r   r   ÚbaseÚsubr   r   r   r   Úvisit_basic_typeE   s   
zNodeVisitor.visit_basic_typec                 C   s   |\}}}||fS r   r   )r   r   r   r   r   Úsecondr   r   r   Úvisit_two_sizeJ   s   
zNodeVisitor.visit_two_sizec                 C   s   |\}}}|fS r   r   )r   r   r   r   Ú	int_valuer   r   r   Úvisit_const_arrP   s   
zNodeVisitor.visit_const_arrc                 C   s   t ƒ S r   )Útuple©r   r   r   r   r   r   Úvisit_dynam_arrV   ó   zNodeVisitor.visit_dynam_arrc                 C   s   |j S r   )Útextr(   r   r   r   Úvisit_alphasY   r*   zNodeVisitor.visit_alphasc                 C   s
   t |jƒS r   )Úintr+   r(   r   r   r   Úvisit_digits\   s   
zNodeVisitor.visit_digitsc                 C   sZ   |j }t|tjƒr|d S t|tjƒr)|jdkr)|jdkr)t|ƒdkr'|d S d S t|ƒS )Nr   é   )	ÚexprÚ
isinstancer   ÚOneOfÚ
QuantifierÚminÚmaxÚlenr'   )r   r   r   r0   r   r   r   Úgeneric_visit_   s    zNodeVisitor.generic_visitc              
      sp   t |tƒstdt|ƒ› �ƒ‚ztƒ j|fi |¤ŽW S  tjy7 } zd|v r*tdƒ‚t|j	|j
|jƒ‚d}~w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)r1   ÚstrÚ	TypeErrorÚtypeÚsuperr
   Úparsimoniousr   Ú
ValueErrorr+   Úposr0   )r   Útype_strÚkwargsÚe©Ú	__class__r   r   r	   n   s   

€ùzNodeVisitor._parse_uncached)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úgrammarr   r   r   r"   r$   r&   r)   r,   r.   r7   r	   Ú__classcell__r   r   rB   r   r   )   s    r   c                   @   sv   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
d„ Ze	dd„ ƒZ
dd„ Zdd„ Ze	dd„ ƒZe	dd„ ƒZe	dd„ ƒZdS )ÚABITypezC
    Base class for results of type string parsing operations.
    ©r   r   Nc                 C   s   || _ 	 || _d S r   rK   )r   r   r   r   r   r   r   ‘   s   zABIType.__init__c                 C   s    dt | ƒj› dt|  ¡ ƒ› d�S )NÚ<Ú Ú>)r:   rF   ÚreprÚto_type_strr   r   r   r   Ú__repr__ž   s    zABIType.__repr__c                 C   s    t | ƒt |ƒu o|  ¡ | ¡ kS r   )r:   rP   )r   Úotherr   r   r   Ú__eq__¡   s    zABIType.__eq__c                 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   r   r   r   rP   ¥   s   zABIType.to_type_strc                 C   rT   )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`rU   r   r   r   r   Ú	item_type¬   ó   zABIType.item_typec                 C   rT   )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`rU   r   r   r   r   Úvalidate´   s   zABIType.validatec              	   C   s0   | j }td|j› d|jd › d|j› d|› �ƒ‚)NzFor 'z' type at column r/   z in 'z': )r   r   r+   ÚstartÚ	full_text)r   Ú	error_msgr   r   r   r   Ú
invalidate¾   s   ÿÿÿzABIType.invalidatec                 C   s
   | 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   r   r   r   Úis_arrayÉ   s   
zABIType.is_arrayc                 C   rT   )zv
        Equal to ``True`` if a type has a dynamically sized encoding.
        Otherwise, equal to ``False``.
        zMust implement `is_dynamic`rU   r   r   r   r   Ú
is_dynamicÑ   rX   zABIType.is_dynamicc                 C   s   | j otdd„ | jD ƒƒS )Nc                 s   s   � | ]	}t |ƒd kV  qdS )r   N)r6   )Ú.0Údimr   r   r   Ú	<genexpr>Û   ó   € z/ABIType._has_dynamic_arrlist.<locals>.<genexpr>)r^   Úanyr   r   r   r   r   Ú_has_dynamic_arrlistÙ   s   zABIType._has_dynamic_arrlist©NN)rD   rE   rF   rG   Ú	__slots__r   rQ   rS   rP   ÚpropertyrW   rY   r]   r^   r_   re   r   r   r   r   rJ   Š   s"    




rJ   c                       sT   e Zd ZdZdZdddœ‡ fdd„Zdd„ Zed	d
„ ƒZdd„ Z	edd„ ƒZ
‡  ZS )r   zQ
    Represents the result of parsing a tuple type string e.g. "(int,bool)".
    )r   Nr   c                   s   t ƒ  ||¡ || _d S r   )r;   r   r   )r   r   r   r   rB   r   r   r   å   s   zTupleType.__init__c                 C   sL   | j }t|tƒrd dd„ |D ƒ¡}nd}dd dd„ | jD ƒ¡› d|› �S )NÚ c                 s   ó   � | ]	}t t|ƒƒV  qd S r   ©rO   Úlist©r`   Úar   r   r   rb   ò   rc   z(TupleType.to_type_str.<locals>.<genexpr>ú(ú,c                 s   s   � | ]}|  ¡ V  qd S r   )rP   ©r`   Úcr   r   r   rb   ö   ó   € ú))r   r1   r'   Újoinr   )r   r   r   r   r   rP   î   s
   
"zTupleType.to_type_strc                 C   s>   | j std|  ¡ › d�ƒ‚t| ƒ| j| jd d… pd | jd�S ©Nz/Cannot determine item type for non-array type 'ú'éÿÿÿÿr   )r^   r=   rP   r:   r   r   r   r   r   r   r   rW   ø   s   ÿýzTupleType.item_typec                 C   s   | j D ]}| ¡  qd S r   )r   rY   )r   rr   r   r   r   rY     s   

ÿzTupleType.validatec                 C   s   | j rdS tdd„ | jD ƒƒS )NTc                 s   s   � | ]}|j V  qd S r   )r_   rq   r   r   r   rb     s   € z'TupleType.is_dynamic.<locals>.<genexpr>)re   rd   r   r   r   r   r   r_   	  s   zTupleType.is_dynamicr   )rD   rE   rF   rG   rg   r   rP   rh   rW   rY   r_   rI   r   r   rB   r   r   Þ   s    	

r   c                       sT   e Zd ZdZdZdddœ‡ fdd„Zdd„ Zed	d
„ ƒZedd„ ƒZ	dd„ Z
‡  ZS )r   zo
    Represents the result of parsing a basic type string e.g. "uint", "address",
    "ufixed128x19[][2]".
    )r    r!   Nr   c                   s    t ƒ  ||¡ || _	 || _d S r   )r;   r   r    r!   )r   r    r!   r   r   rB   r   r   r     s
   zBasicType.__init__c                 C   sx   | j | j}}t|tƒrt|ƒ}nt|tƒr!d dd„ |D ƒ¡}nd}t|tƒr3d dd„ |D ƒ¡}nd}| j| | S )NÚxc                 s   s   � | ]}t |ƒV  qd S r   )r8   )r`   Úsr   r   r   rb   ,  rs   z(BasicType.to_type_str.<locals>.<genexpr>ri   c                 s   rj   r   rk   rm   r   r   r   rb   1  rc   )r!   r   r1   r-   r8   r'   ru   r    )r   r!   r   r   r   r   rP   &  s   



zBasicType.to_type_strc                 C   sB   | j std|  ¡ › d�ƒ‚t| ƒ| j| j| jd d… pd | jd�S rv   )r^   r=   rP   r:   r    r!   r   r   r   r   r   r   rW   7  s   ÿüzBasicType.item_typec                 C   s4   | j rdS | jdkrdS | jdkr| jd u rdS dS )NTÚstringÚbytesF)re   r    r!   r   r   r   r   r_   E  s   
zBasicType.is_dynamicc                 C   s˜  | j | j}}|dkr|d ur|  d¡ d S d S |dkr>|d u s*t|tƒs*|  d¡ t|tƒr:|dkr<|  d¡ d S d S d S |dv rht|tƒsL|  d¡ |d	k sTd
|k rY|  d¡ |d	 dkrf|  d¡ d S d S |dv r§t|tƒsv|  d¡ |\}}|d	k s‚d
|k r‡|  d¡ |d	 dkr’|  d¡ |dk sšd|k r¥|  d|› d�¡ d S d S |dkr¹t|tƒs·|  d¡ d S d S |dkrÈ|d urÊ|  d¡ d S d S d S )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)r-   Ú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!   r]   r1   r-   r'   )r   r    r!   ÚbitsÚminus_er   r   r   rY   R  sZ   ÿÿÿ


ÿ
ÿ


ÿÿ
ÿþzBasicType.validaterf   )rD   rE   rF   rG   rg   r   rP   rh   rW   r_   rY   rI   r   r   rB   r   r     s    

r   Úint256Úuint256Úfixed128x18Úufixed128x18Úbytes24Úbytes1)r-   r~   r�   r‚   ÚfunctionÚbytez\b(Ú|c                 c   s   � | ]}t  |¡V  qd S r   )ÚreÚescaperm   r   r   r   rb   ™  s   € rb   z)\bc                 C   s   t  d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                 S   s   t |  d¡ S )Nr   )ÚTYPE_ALIASESÚgroup)Úmatchr   r   r   Ú<lambda>¦  s    znormalize.<locals>.<lambda>)ÚTYPE_ALIAS_REr!   )r?   r   r   r   Ú	normalize�  s   þr˜   )r   r‘   r<   r   Úeth_abi.exceptionsr   r   ÚGrammarrH   r   ÚvisitorrJ   r   r   r“   Úcompileru   Úkeysr—   r˜   r
   r   r   r   r   Ú<module>   s2    ÿ^T3ú	ÿ
