
    Dg,                     0   d Z ddlZddlZddlZddlmZmZ d Zd Z G d de	          Z
d(d	Zd)d
Zd Zi ej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej        dej         dej!        dej"        d ej#        d!iZ$ej%        d"ej&        d#ej'        d$ej(        d%iZ) G d& d'ej*                  Z+dS )*z
Find intermediate evalutation results in assert statements through builtin AST.
This should replace _assertionold.py eventually.
    N)_format_explanationBuiltinAssertionErrorc                 6    t          | t          j                  S N)
isinstanceastexprnodes    K/var/www/sysmax/venv/lib/python3.11/site-packages/py/_code/_assertionnew.py_is_ast_exprr          dCH%%%    c                 6    t          | t          j                  S r   )r   r   stmtr
   s    r   _is_ast_stmtr      r   r   c                       e Zd ZdZddZdS )Failurez#Error found while interpreting AST. c                 D    t          j                    | _        || _        d S r   )sysexc_infocauseexplanation)selfr   s     r   __init__zFailure.__init__   s    \^^
&r   N)r   )__name__
__module____qualname____doc__r    r   r   r   r      s.        --' ' ' ' ' 'r   r   Fc                     t          j        |           }t          |          }	 |                    |           n8# t          $ r+ t          j                    d         }t          |          cY S w xY w|rdS d S )N   z(assertion failed, but when it was re-run for printing intermediate values, it did not fail.  Suggestions: compute assert expression before the assert or use --no-assert))r   parseDebugInterpretervisitr   r   r   
getfailure)sourceframeshould_failmodvisitorfailures         r   	interpretr.      s    
)F

Cu%%G#c # # #,..#'"""""#  SR RS Ss   ; 2A0/A0c                     |1t           j                            t          j        d                    }t          | |          S )Nr#   )pycodeFramer   	_getframer.   )offending_liner)   s     r   runr5   (   s4    }cmA..//^U+++r   c                 x   t          | j                  }| j        d         }t          |          rS|                                }|s|                    d           |dxx         d|z  cc<   d                    |          }| j        d         j        d|}|                    d          r
|dd          }|S )	Nr#   r   r   z << 
z: zAssertionError: assert    )	r   r   r   str
splitlinesappendjoinr   
startswith)r-   r   valuelinestexts        r   r'   r'   -   s    %g&9::KM!E
5zz '&&(( 	LLa''ii&&}Q'000++>D011 BCCyKr   |^&z<<z>>+-*/z//%z==z!=<z<=>z>=**iszis notinznot inznot %sz~%sz-%sz+%sc                   n    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd ZdS )r%   z;Interpret AST nodes to gleam useful debugging information. c                     || _         d S r   )r)   )r   r)   s     r   r   zDebugInterpreter.__init__`   s    


r   c                 *   t          |          rt          j        |          }|                     |          }	 | j                            |          }n# t          $ r t                      w xY w| j                            |          }||fS t          |          ret          j
        |g          }|                     |d          }	 | j                            |           n# t          $ r t                      w xY wdS t          d|          )Nexec)NNzcan't handle )r   r   
Expression_compiler)   eval	Exceptionr   reprr   Moduleexec_AssertionError)r   r   r+   coresultr   s         r   generic_visitzDebugInterpreter.generic_visitc   s    	=.&&Cs##B ,,      ii *//&11K&&$ 		=*dV$$CsF++B 
  $$$$      ii : .TT!;<<<s   A A.
C% %C>rT   c                 $    t          |d|          S )Nz<assertion interpretation>)compile)r   r(   modes      r   rS   zDebugInterpreter._compiley   s    v;TBBBr   c                 6    |                      |j                  S r   )r&   r>   )r   r	   s     r   
visit_ExprzDebugInterpreter.visit_Expr|   s    zz$*%%%r   c                 D    |j         D ]}|                     |           d S r   )bodyr&   )r   r+   r   s      r   visit_ModulezDebugInterpreter.visit_Module   s2    H 	 	DJJt	 	r   c                     |                      |          \  }}|j        d}|                     |          }	 | j                            |          }n# t
          $ r d}Y nw xY w|s	|j        |fS ||fS )Nz in locals() is not globals()F)r\   idrS   r)   rT   rU   )r   namer   r[   r(   rZ   locals          r   
visit_NamezDebugInterpreter.visit_Name   s    "0066V6:ggg?]]6""	JOOB''EE 	 	 	EEE	  	#7F?"F""s   A A#"A#c                    |j         }|                     |          \  }}t          |j        |j                  D ]\  }}|                     |          \  }}t
          |j                 }	|d|	d|}
d|	d}|                     |          }	 | j        	                    |||          }n# t          $ r t          |
          w xY w	 |s nn# t          $ r   Y  nxY w||}}t          j        j        }|r ||	||          }|r|}
|
|fS )N __exprinfo_left  __exprinfo_right__exprinfo_left__exprinfo_right)leftr&   zipopscomparatorsoperator_map	__class__rS   r)   rT   rU   r   KeyboardInterruptr0   r1   _reprcompare)r   comprq   left_explanationleft_resultopnext_opnext_explanationnext_result	op_symbolr   r(   rZ   r[   rcompress                   r   visit_ComparezDebugInterpreter.visit_Compare   s{   y(,

4(8(8%+tx)9:: 	J 	JKB,0JJw,?,?)k$R\2I(8(8(8)))(8(8:KK>GiiIFv&&B+[:E ) G G + + +k***+ E$   ,<kk$ 	"%	;<<C "!F""s   B--CCCc                    t          |j        t          j                  }g }|j        D ]7}|                     |          \  }}|                    |           ||k    r n8|rdpd}d|                    |          z   dz   }||fS )Nz or z and ())r   r|   r   Orvaluesr&   r;   r<   )r   boolopis_orexplanationsoperandr   r[   rg   s           r   visit_BoolOpzDebugInterpreter.visit_BoolOp   s    69cf--} 	 	G"&**W"5"5K,,, *7DIIl333c9F""r   c                 $   t           |j        j                 }|                     |j                  \  }}||fz  }|                     |dz            }	 | j                            ||          }n# t          $ r t          |          w xY w||fS )N__exprinfo_expr)
	unary_mapr|   rv   r&   r   rS   r)   rT   rU   r   )r   unarypatternoperand_explanationoperand_resultr   rZ   r[   s           r   visit_UnaryOpzDebugInterpreter.visit_UnaryOp   s    EH./.2jj.G.G+^!4 66]]7%99::	'Z__R_HHFF 	' 	' 	'+&&&	'F""s   A1 1Bc                 r   |                      |j                  \  }}|                      |j                  \  }}t          |j        j                 }d|d|d|d}d|d}|                     |          }		 | j                            |	||          }
n# t          $ r t          |          w xY w||
fS )Nr   rk   r   rl   rm   rn   )r&   rq   rightru   r|   rv   rS   r)   rT   rU   r   )r   binoprz   r{   right_explanationright_resultsymbolr   r(   rZ   r[   s              r   visit_BinOpzDebugInterpreter.visit_BinOp   s    (,

5:(>(>%+*.**U[*A*A'<eh01&6&6&6&7&7&79:@&&B]]6""	'Z__R6B % D DFF 	' 	' 	'+&&&	'F""s   :B B2c                    |                      |j                  \  }}g }d|i}g }|j        D ][}|                      |          \  }}	dt          |          }
|	||
<   |                    |
           |                    |           \|j        D ]r}|                      |j                  \  }}	dt          |          }
|	||
<   d|j        z  }|                    ||
fz             |                    ||fz             s|j        rT|                      |j                  \  }}	d}
|	||
<   |                    d|
           |                    d|           |j	        rT|                      |j	                  \  }}	d}
|	||
<   |                    d|
           |                    d|           d
                    |          }|d	|d
}d
                    |          }d|d
}|                     |          }	  | j        j        |fi |}n# t          $ r t          |          w xY wd}| j                            |          }||||fz  }||fS )N__exprinfo_func__exprinfo_z%s=%%s__exprinfo_starrF   __exprinfo_kwdsrK   z, r   r   z__exprinfo_func(%s
{%s = %s
})r&   funcargslenr;   keywordsr>   argstarargskwargsr<   rS   r)   rT   rU   r   rV   )r   callfunc_explanationr   arg_explanationsns	argumentsr   arg_explanation
arg_resultarg_namekeywordkeyword_sourceargs_explainedr   r   r(   rZ   r[   r   reps                        r   
visit_CallzDebugInterpreter.visit_Call   s   !%DI!6!6$$'	9 	5 	5C*.**S//'OZZ*-b'''3H%BxLX&&&##O4444} 	I 	IG*.**W]*C*C'OZZ*-b'''3H%BxL%5N^xk9:::##No5G$GHHHH= 	@*.**T]*C*C'OZ(H%BxLhh0111###__$>???; 	A*.**T[*A*A'OZ(H%BxLxx1222###oo$?@@@#344"2"2"2NNNCyy##*.$$0]]6""	'$TZ_R..2..FF 	' 	' 	'+&&&	'#joof%%c; 77F""s   H H5c                     d}||j         |j         fz  }|                     |          }	 | j                            |          S # t          $ r Y dS w xY w)Nz*%r not in globals() and %r not in locals()F)rf   rS   r)   rT   rU   )r   rg   r   r(   rZ   s        r   _is_builtin_namez!DebugInterpreter._is_builtin_name  sf    >DGTW--]]6""	:??2&&& 	 	 	55	s   A 
AAc                    t          |j        t          j                  s|                     |          S |                     |j                  \  }}|d|j        }d|j        }|                     |          }	 | j	        
                    ||          }n# t          $ r t          |          w xY w| j	                            |          d| j	                            |          d|d|j        d}d}||j        fz  }|                     |          }	 | j	        
                    ||          }n# t          $ r d}Y nw xY w|r$| j	                            |          }	d	}
|
|	|	|fz  }||fS )
N.z__exprinfo_expr.r   z
{z = z
}z.%r in getattr(__exprinfo_expr, '__dict__', {})Tr   )r   ctxr   Loadr\   r&   r>   attrrS   r)   rT   rU   r   rV   )r   r   source_explanationsource_resultr   r(   rZ   r[   from_instancer   r   s              r   visit_Attributez DebugInterpreter.visit_Attribute  s   $(CH-- 	,%%d+++,0JJtz,B,B)M!3!3!3TYY?)-4]]6""	'Z__R_GGFF 	' 	' 	'+&&&	'.2joof.E.E.E.E.2joof.E.E.E.E.@.@.@$)))M B49,&]]6""	! JOOBONNMM 	! 	! 	! MMM	! 	<*//&))C'G!S#{$;;KF""s   >B B5D; ;E
	E
c                    |                      |j                  \  }}|                    d          r|                    d          r
|dd         }d|}|s%	 t          # t
          $ r t          |          w xY w||fS )NzFalse
{False =r7      zassert )r&   testr=   endswithr   rU   r   )r   assrttest_explanationtest_resultr   s        r   visit_AssertzDebugInterpreter.visit_Assert'  s    (,

5:(>(>%+&&'899 	7 ))$//	7/26%5%57 	++++ + + +k***+K''s   A! !A;c                    |                      |j                  \  }}d|}t          j        dt          j                    |j        j        |j        j                  }t          j        |j        ||j        |j                  }t          j	        |g          }| 
                    |d          }	 | j                            ||           n# t          $ r t          |          w xY w||fS )Nz... = r   )lineno
col_offsetrQ   r   )r&   r>   r   Namer   r   r   AssigntargetsrW   rS   r)   rX   rU   r   )	r   assignvalue_explanationvalue_resultr   rg   
new_assignr+   rZ   s	            r   visit_AssignzDebugInterpreter.visit_Assign4  s    *.**V\*B*B'<<$5$57x)38::%|2#)<#:< < < ZV]+1+<> > >
j*&&]]3''	'JR>>>> 	' 	' 	'+&&&	'L((s   3C C*N)rT   )r   r   r   r    r   r\   rS   ra   rd   ri   r   r   r   r   r   r   r   r   r   r!   r   r   r%   r%   ]   s       EE  = = =,C C C C& & &  # # ## # #>
# 
# 
#	# 	# 	## # #*# *# *#X  # # #8( ( () ) ) ) )r   r%   )Fr   ),r    r   r   r0   py._code.assertionr   r   r   r   rU   r   r.   r5   r'   BitOrBitXorBitAndLShiftRShiftAddSubMultDivFloorDivModEqNotEqLtLtEGtGtEPowIsIsNotInNotInru   NotInvertUSubUAddr   NodeVisitorr%   r!   r   r   <module>r      sL   
 


 



 				 I I I I I I I I& & && & &' ' ' ' 'i ' ' 'S S S S, , , ,
  IJ J J	
 J Gc Gc Hs Gc L4 Gc FT I FS Gd  FS!" Gd#$ GdFTIFTI- 4 GhJHuHu		e) e) e) e) e)s e) e) e) e) e)r   