o
    oh
                     @   s`   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ G dd deZdd Zd	S )
a  
This module implements the functionality to take any Python expression as a
string and fix all numbers and other things before evaluating it,
thus

1/2

returns

Integer(1)/Integer(2)

We use the ast module for this. It is well documented at docs.python.org.

Some tips to understand how this works: use dump() to get a nice
representation of any node. Then write a string of what you want to get,
e.g. "Integer(1)", parse it, dump it and you'll see that you need to do
"Call(Name('Integer', Load()), [node], [], None, None)". You do not need
to bother with lineno and col_offset, just call fix_missing_locations()
before returning the node.
    )Basic)SympifyError)parseNodeTransformerCallNameLoadfix_missing_locationsConstantTuplec                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	Transformc                 C   s   t |  || _|| _d S )N)r   __init__
local_dictglobal_dict)selfr   r    r   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/parsing/ast_parser.pyr      s   

zTransform.__init__c                 C   sT   t |jtrtttdt |gg dS t |jtr(tttdt |gg dS |S )NIntegerfuncargskeywordsFloat)
isinstancevalueintr	   r   r   r   float)r   noder   r   r   visit_Constant#   s   zTransform.visit_Constantc                 C   st   |j | jv r|S |j | jv r"| j|j  }t|ttfst|r!|S n|j dv r)|S ttt	dt
 t|j gg dS )N)TrueFalseSymbolr   )idr   r   r   r   typecallabler	   r   r   r   r
   )r   r   name_objr   r   r   
visit_Name,   s   
zTransform.visit_Namec                    sL    fdd|j j D } |j}ttdt t|t |gg d}t|S )Nc                    s   g | ]}  |qS r   )visit).0argr   r   r   
<listcomp>:   s    z*Transform.visit_Lambda.<locals>.<listcomp>Lambdar   )r   r'   bodyr   r   r   r   r	   )r   r   r   r-   nr   r*   r   visit_Lambda9   s   zTransform.visit_LambdaN)__name__
__module____qualname__r   r   r&   r/   r   r   r   r   r      s
    	r   c                 C   sj   i }t d| z
t|  dd}W n ty    tdt|  w t|||}t|dd}t	|||S )z
    Converts the string "s" to a SymPy expression, in local_dict.

    It converts all numbers to Integers before feeding it to Python and
    automatically creates Symbols.
    zfrom sympy import *eval)modezCannot parse %s.z<string>)
execr   stripSyntaxErrorr   reprr   r'   compiler3   )sr   r   aer   r   r   
parse_expr@   s   
r=   N)__doc__sympy.core.basicr   sympy.core.sympifyr   astr   r   r   r   r   r	   r
   r   r   r=   r   r   r   r   <module>   s    ($