
    wg
                     d    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e      Zd Zy)	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                   $    e Zd Zd Zd Zd Zd Zy)	Transformc                 J    t        j                  |        || _        || _        y )N)r   __init__
local_dictglobal_dict)selfr   r   s      ]/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/parsing/ast_parser.pyr   zTransform.__init__   s      &$&    c           	         t        |j                  t              r*t        t	        t        dt                     |gg             S t        |j                  t              r*t        t	        t        dt                     |gg             S |S )NIntegerfuncargskeywordsFloat)
isinstancevalueintr
   r   r   r	   float)r   nodes     r   visit_ConstantzTransform.visit_Constant#   so    djj#&(4	463J"*. / /

E*(43H"*. / /r   c           	      x   |j                   | j                  v r|S |j                   | j                  v r<| j                  |j                      }t        |t        t
        f      st        |      r|S |j                   dv r|S t        t        t        dt                     t        |j                         gg             S )N)TrueFalseSymbolr   )idr   r   r   r   typecallabler
   r   r   r	   r   )r   r!   name_objs      r   
visit_NamezTransform.visit_Name,   s    77doo%KWW(((''0H(UDM2hx6HWW))K$TtHdf/Etww'(2&7 8 	8r   c                 $   |j                   j                   D cg c]  }| j                  |       }}| j                  |j                        }t        t	        dt                     t        |t                     |gg       }t        |      S c c}w )NLambdar   )r   visitbodyr   r   r	   r   r
   )r   r!   argr   r/   ns         r   visit_LambdazTransform.visit_Lambda9   so    +/99>>:C

3::zz$))$d8TV,df%t,r;$Q''	 ;s   BN)__name__
__module____qualname__r   r"   r+   r2    r   r   r   r      s    '
8(r   r   c                    i }t        d|       	 t        | j                         d      }t        ||      j                  |      }t        |dd      }t        |||      S # t        $ r t	        dt        |       z        w xY w)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.   compiler8   )sr   r   aes        r   
parse_exprrB   @   s     K	,9!'')&) 	*k*003A:v&A;
++	  9-Q7889s   A   !BN)__doc__sympy.core.basicr   sympy.core.sympifyr   astr   r   r   r   r	   r
   r   r   r   rB   r6   r   r   <module>rG      s3   * # ++ + +"( "(H,r   