
    aE                     f   d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	 d dl
Z
e j                  j                  Z G d d      Z G d de      Zd Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Zg Zej0                  dej2                  dij5                         D ]!  \  ZZ G d de      Zej=                  e       # ej>                  dej@                  dejB                  dejD                  dejF                  dejH                  dij5                         D ]!  \  ZZ G d de      Z%ej=                  e%       #  G d d e      Z& G d! d"e      Z' G d# d$e      Z( G d% d&e      Z) G d' d(e      Z* G d) d*e      Z+d+ Z,dEd,Z-dFd-Z.d. Z/d/ Z0dEd0Z1e2d1k(  rd2 Z3d3 Z4d4 Z5 e-d5        e-d6        e-d7        e-d8       d9Z6 e-d:        e-d;        e-d<        e1d=        e-d>        e1d?        e1d@        e1dA        e-dB        e-dC        e1dD       yy)G    N)parseast	pycodegen)BuiltinAssertionError_format_explanationc                       e Zd Zd Zy)Failurec                 `    t        j                         \  | _        | _        | _        || _        y N)sysexc_infoexcvaluetbnode)selfr   s     8/usr/lib/python3/dist-packages/py/_code/_assertionold.py__init__zFailure.__init__
   s!    (+%$*dg	    N)__name__
__module____qualname__r    r   r   r	   r	   	   s    r   r	   c                   <    e Zd ZdZi ZdZd Zd Zd Zd Z	d Z
d Zy	)
Viewa  View base class.

    If C is a subclass of View, then C(x) creates a proxy object around
    the object x.  The actual class of the proxy is not C in general,
    but a *subclass* of C determined by the rules below.  To avoid confusion
    we call view class the class of the proxy (a subclass of C, so of View)
    and object class the class of x.

    Attributes and methods not found in the proxy are automatically read on x.
    Other operations like setting attributes are performed on the proxy, as
    determined by its view class.  The object x is available from the proxy
    as its __obj__ attribute.

    The view class selection is determined by the __view__ tuples and the
    optional __viewkey__ method.  By default, the selected view class is the
    most specific subclass of C whose __view__ mentions the class of x.
    If no such subclass is found, the search proceeds with the parent
    object classes.  For example, C(True) will first look for a subclass
    of C with __view__ = (..., bool, ...) and only if it doesn't find any
    look for one with __view__ = (..., int, ...), and then ..., object,...
    If everything fails the class C itself is considered to be the default.

    Alternatively, the view class selection can be driven by another aspect
    of the object x, instead of the class of x, by overriding __viewkey__.
    See last example at the end of this module.
    r   c                     t         j                  |       }||_        | |_        |j	                         }	 |j
                  |   |_        |S # t        $ r |j                  |      |_        Y |S w xY wr   )	object__new____obj____rootclass____viewkey__
_viewcache	__class__KeyError_selectsubclass)	rootclassobjargskwdsr   keys         r   r   zView.__new__-   sq    ~~i(& 	7!__S1DN   	7!11#6DN	7s   A A.-A.c                 .    t        | j                  |      S r   )getattrr   )r   attrs     r   __getattr__zView.__getattr__8   s     t||T**r   c                 .    | j                   j                  S r   )r   r#   r   s    r   r!   zView.__viewkey__=   s    ||%%%r   c                     t        j                  |      rt        j                  |      }n|g}|D ]&  }|D cg c]  }||j                  v s| }}|s$|c S  g S c c}w r   )inspectisclassgetmro__view__)r   r*   
subclasseskeysCresults         r   __matchkey__zView.__matchkey__@   se    ??3>>#&D5D 	C!+AAsajj/@aAFA	 	 Bs   AAc                 8   t        t        | j                              }|D ]/  }t        |j                  t
              r|j                  f|_        1 | j                  ||      }|s| j                  S t        |      dk(  r|d   S t        dt        |      i       S )N   r   ?)	listenumsubclassesr    
isinstancer5   tupler:   lentype)r   r*   r6   r8   choicess        r   r%   zView._selectsubclassK   s    .););<=
 	+Aajj%0jj]
	+ ##C4%%%\Q1: U7^R00r   c                 N    | j                   j                  d| j                  dS )N())r    r   r   r0   s    r   __repr__zView.__repr__Y   s    --66EEr   N)r   r   r   __doc__r"   r5   r   r.   r!   r:   r%   rH   r   r   r   r   r      s2    6 JH	+
&	1Fr   r   c              #   f   K   | j                         D ]  }t        |      D ]  }|   |  y wr   )__subclasses__r?   )clssubclssubsubclasss      r   r?   r?   ]   s?     $$& )&1 	K	 Is   /1c                   ,    e Zd ZdZdZd Zd Zd Zd Zy)Interpretablez+A parse tree node with a few extra methods.Nc                      y)NFr   )r   frames     r   
is_builtinzInterpretable.is_builtinh   s    r   c                 x   	 t        j                  | j                        }d|_        d| j                  _        t	        j
                  |      j                         }|j                  |      }|| _
        | j                  xs |j                  | j                        | _        y # t        $ r   t        |       xY w)Nz<eval>)r   
Expressionr   filenamer   ExpressionCodeGeneratorgetCodeevalpassthroughexr	   r9   explanationrepr)r   rR   exprcor9   s        r   rY   zInterpretable.evalk   s    		 >>$,,/D$DM$,DLL!2248@@BBZZ^F
 ++Fuzz$++/F  		 $-s   A+B# #B9c                    	 t        j                  d t        j                  | j                  g            }d|_        t        j                  |      j                         }|j                  |       y # t        $ r   t        |       xY w)N<run>)r   ModuleStmtr   rV   r   ModuleCodeGeneratorrX   exec_rZ   r	   )r   rR   r]   r^   s       r   runzInterpretable.runz   sm    	 ::dCHHdll^$<=D#DM..t4<<>BKKO 		 $-s   A/A2 2Bc                 ,    t        | j                        S r   )r   r[   r0   s    r   nice_explanationzInterpretable.nice_explanation   s    "4#3#344r   )	r   r   r   rI   r[   rS   rY   re   rg   r   r   r   rP   rP   d   s    5KG
 5r   rP   c                   H     e Zd Zej                  Zd Zd Zd Z fdZ	 xZ
S )Namec                     d| j                   z  }	 |j                  |j                  |            S # t        $ r   Y yxY w)Nz%r in locals() is not globals()Fnameis_truerY   rZ   r   rR   sources      r   is_localzName.is_local   sB    2TYY>	==F!344 		   1 >c                     d| j                   z  }	 |j                  |j                  |            S # t        $ r   Y yxY w)Nz%r in globals()Frk   rn   s      r   	is_globalzName.is_global   sB    "TYY.	==F!344 		rq   c                     | j                   d| j                   d}	 |j                  |j                  |            S # t        $ r   Y yxY w)Nz not in locals() and z not in globals()Frk   rn   s      r   rS   zName.is_builtin   sH    IItyy"	==F!344 		s	   > Ac                 r    t         t        |   |       | j                  |      s| j                  | _        y y r   )superri   rY   rp   rl   r[   )r   rR   r#   s     r   rY   z	Name.eval   s/    dDu%}}U##yyD $r   )r   r   r   r   ri   r5   rp   rs   rS   rY   __classcell__)r#   s   @r   ri   ri      s%    xxH) )r   ri   c                   *    e Zd Zej                  Zd Zy)Comparec                    t        | j                        }|j                  |       | j                  D ]  \  }}t	        | d      r|j                  | j                        s y t        |      }|j                  |       |j                  d|d|j                  | _        d|z  }	 |j                  ||j                  |j                        | _        |} y # t        $ r   t        |       xY w)Nr9    z#__exprinfo_left %s __exprinfo_right__exprinfo_left__exprinfo_right)
rP   r]   rY   opshasattrrm   r9   r[   rZ   r	   )r   rR   r]   	operationexpr2ro   s         r   rY   zCompare.eval   s    TYY'		% $ 	IutX&}}T[[1!%(EJJu  )U->-> @D:YFF$#jj9=:?,, ) H D%	 ! $dm#s   '-CC/N)r   r   r   r   ry   r5   rY   r   r   r   ry   ry      s    {{Hr   ry   c                   *    e Zd Zej                  Zd Zy)Andc                 ,   g }| j                   D ]g  }t        |      }|j                  |       |j                  |j                         |j
                  | _        |j                  |j
                        rg n ddj                  |      z   dz   | _        y )NrF   z and rG   nodesrP   rY   appendr[   r9   rm   joinr   rR   explanationsr]   s       r   rY   zAnd.eval   s    JJ 	D &DIIe 0 01++DK==-	 l!;;cAr   N)r   r   r   r   r   r5   rY   r   r   r   r   r      s    wwH	Br   r   c                   *    e Zd Zej                  Zd Zy)Orc                 ,   g }| j                   D ]g  }t        |      }|j                  |       |j                  |j                         |j
                  | _        |j                  |j
                        sg n ddj                  |      z   dz   | _        y )NrF   z or rG   r   r   s       r   rY   zOr.eval   s    JJ 	D &DIIe 0 01++DK}}T[[)	 \!::S@r   N)r   r   r   r   r   r5   rY   r   r   r   r   r      s    vvH	Ar   r   znot __exprinfo_exprz(~__exprinfo_expr)c                       e Zd ZeZefdZy)
UnaryArithc                 
   t        | j                        }|j                  |       |j                  d|j                        | _        	 |j                  ||j
                        | _        y # t        $ r   t        |       xY w)N__exprinfo_exprr   )rP   r]   rY   replacer[   r9   rZ   r	   )r   rR   
astpatternr]   s       r   rY   zUnaryArith.eval   s|     +DIIe)112C262B2B DD$#jj9= ) F  $dm#s   	"A, ,BNr   r   r   astclassr5   r   rY   r   r   r   r   r      s    )3 	$r   r   z$(__exprinfo_left + __exprinfo_right)z$(__exprinfo_left - __exprinfo_right)z$(__exprinfo_left * __exprinfo_right)z$(__exprinfo_left / __exprinfo_right)z$(__exprinfo_left % __exprinfo_right)z%(__exprinfo_left ** __exprinfo_right)c                       e Zd ZeZefdZy)BinaryArithc                    t        | j                        }|j                  |       t        | j                        }|j                  |       |j	                  d|j
                        j	                  d|j
                        | _        	 |j                  ||j                  |j                        | _        y # t        $ r   t        |       xY w)Nr}   r~   r|   )	rP   leftrY   rightr   r[   r9   rZ   r	   )r   rR   r   r   r   s        r   rY   zBinaryArith.eval  s     +DIIe!$**-EJJu *!():T=N=N!O!();U=N=N!O $#jj9=:?,, ) H ! $dm#s   	-B7 7CNr   r   r   r   r   r     s    )3 	$r   r   c                   0    e Zd Zej                  Zd Zd Zy)CallFuncc                     d}	 |j                  |j                  || j                              S # t        $ r   Y yxY w)Nz"isinstance(__exprinfo_value, bool))__exprinfo_valueF)rm   rY   r9   rZ   rn   s      r   is_boolzCallFunc.is_bool"  sN    5	==F=A[[ ", "J K K 		s   +0 =c                 Z   t        | j                        }|j                  |       g }d|j                  i}d}| j                  D ]  }t        |t        j                        r|j                  }|j                  }nd }t        |      }|j                  |       dt        |      z  }|j                  ||<   |$||dz   z  }|j                  |j                         ||d|dz  }|j                  |d|j                          | j                  r`t        | j                        }	|	j                  |       d}|	j                  ||<   |d|z   dz   z  }|j                  d|	j                  z          | j                  r`t        | j                        }
|
j                  |       d}|
j                  ||<   |d	|z   dz   z  }|j                  d	|
j                  z          |j                  d
dj                  |      d| _        |j!                  d      r|d d }|dz  }	  |j                  |fi || _        |j'                  |      r| j)                  |      s6|j+                  | j                        }|d|d| j                  d| _        y y # t"        $ r   t%        |       xY w)N__exprinfo_fnz__exprinfo_fn(z__exprinfo_%d,=__exprinfo_star*__exprinfo_kwdsz**rF   z, rG   
{ = 
})rP   r   rY   r9   r(   r@   r   Keywordrl   r]   rB   r   r[   	star_args
dstar_argsr   endswithrZ   r	   rS   r   r\   )r   rR   r   r   varsro   akeywordargnamer   r   rs               r   rY   zCallFunc.eval,  sk   TYY'		%-! 	HA!S[[)&&FFa AFF5M%D	1GHHDM'C-'##AMM2gw77##w$FG	H  >>%dnn5INN5!'G%,,DMcGmc))Fi&;&; ;<??&t7JOOE"'G&--DMdWns**Fz'='= =>dii57??3CR[F#	 $%**V4t4DK
 u%T\\%-@

4;;'A45q$:J:JKD .A	  		 $-s   #J J*N)r   r   r   r   r   r5   r   rY   r   r   r   r   r     s    ||H1Lr   r   c                   *    e Zd Zej                  Zd Zy)Getattrc                 2   t        | j                        }|j                  |       d| j                  z  }	 |j                  ||j                        | _        |j                  d| j                  | _        d| j                  z  }	 |j                  |j                  ||j                              }|r6|j                  | j                        }|d|d| j                  d| _        y y # t
        $ r   t        |       xY w# t
        $ r   d}Y axY w)	Nz__exprinfo_expr.%sr   .zGhasattr(__exprinfo_expr, "__dict__") and %r in __exprinfo_expr.__dict__Tr   r   r   )
rP   r]   rY   attrnamer9   rZ   r	   r[   rm   r\   )r   rR   r]   ro   from_instancer   s         r   rY   zGetattr.evalb  s   TYY'		%%5	 **VT[[*IDK
 '+&6&6F359]]C	!!MM

64;;
?AM 

4;;'A45q$:J:JKD   		 $-  		! Ms   "C. 	,D .DDN)r   r   r   r   r   r5   rY   r   r   r   r   r   _  s    {{HLr   r   c                   *    e Zd Zej                  Zd Zy)Assertc                    t        | j                        }|j                  |       |j                  j	                  d      r/|j                  j                  d      r|j                  dd |_        |j                  | _        d|j                  z   | _        |j                  |j                        s	 t        y # t        $ r   t        |       xY w)NzFalse
{False = r      zassert )rP   testrY   r[   
startswithr   r9   rm   r   rZ   r	   )r   rR   r   s      r   re   z
Assert.run  s    TYY'		%''(:;%%e,#//26Dkk$t'7'77}}T[[)$++ * ! $dm#s   2B9 9CN)r   r   r   r   r   r5   re   r   r   r   r   r   }  s    zzH$r   r   c                   *    e Zd Zej                  Zd Zy)Assignc                    t        | j                        }|j                  |       |j                  | _        d|j                  z   | _        t        j                  | j                  t        j                  d            }t        j                  d t        j                  |g            }d|_        t        j                  |      j                         }	 |j                  ||j                         y # t         $ r   t#        |       xY w)Nz... = r   r`   r   )rP   r]   rY   r9   r[   r   r   r   ri   ra   rb   rV   r   rc   rX   rd   rZ   r	   )r   rR   r]   assmodr^   s         r   re   z
Assign.run  s    TYY'		%kk#d&6&66jjSXX.?%@Ajjsxx/**3/779	 KKDKKK8 		 $-s   C2 2DN)r   r   r   r   r   r5   re   r   r   r   r   r     s    zzH r   r   c                   *    e Zd Zej                  Zd Zy)Discardc                     t        | j                        }|j                  |       |j                  | _        |j                  | _        y r   )rP   r]   rY   r9   r[   )r   rR   r]   s      r   re   zDiscard.run  s5    TYY'		%kk++r   N)r   r   r   r   r   r5   re   r   r   r   r   r     s    {{H,r   r   c                   *    e Zd Zej                  Zd Zy)rb   c                 ^    | j                   D ]  }t        |      }|j                  |         y r   )r   rP   re   )r   rR   stmts      r   re   zStmt.run  s*    JJ 	D &DHHUO	r   N)r   r   r   r   rb   r5   re   r   r   r   rb   rb     s    xxHr   rb   c                     | j                   j                         }|rd|z   }nd}t        j                  j	                  | j
                  j                  d| j                  |d       y )Nz, in:  : 
)r   rg   r   stdoutwriter   r   r   )er[   s     r   report_failurer     sK    &&))+K,JJQUU^^QWWkJKr   c                    |4t        j                  d      }t        j                  j	                  |      }t        | d      }t        |t        j                        sJ t        |j                        }	 |j                  |       |j                  |j                        s1t         j                  j                  d|j!                         z         y y # t"        $ r  t$        $ r% t        j&                         d   }t)        |       Y y w xY w)Nr<   rY   zassertion failed: %s
)r   	_getframepycodeFramer   r@   r   rU   rP   r   rY   rm   r9   stderrr   rg   rZ   r	   r   r   )srR   r]   r   r   s        r   checkr     s    }a e$FDdCNN+++#D	Q		% }}T[[)JJ58M8M8OOP *   LLN1qs   5C 4D
	D
c                 ~   t        t        | d      j                        }t        |t        j
                        rt        j                  j                  |      }	 |j                  |       |ryy # t        $ r% t        j                         d   }t        |      cY S t        $ r   dd l}|j!                          Y QxY w)Nexecr<   r   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 --nomagic))rP   r   r   r@   types	FrameTyper   r   r   re   r	   r   r   
getfailurerZ   	traceback	print_exc)ro   rR   should_failmoduler   r   s         r   	interpretr     s    50556F%)e$	

5 P   LLN1!} s   A/ /+B<B<c                 4   t        | t              rt        j                  j	                  |       } | j
                  d   }t        |j                        j                         }t        ||j                  d      }t        |t              st        d|      |S )Nr   T)r   zinterpret returned non-string )r@   rA   r   r   ExceptionInfor   str	statementstripr   rR   	TypeError)excinfor   ro   xs       r   getmsgr     sx    '5!''''0
 
		2	B$$&F&"((5AaaABBHr   c                 >   | j                   j                         }t        | j                        r<|j	                  d      }|dxx   d| j                  z  cc<   dj                  |      }| j                  j                  d|}|j                  d      r|dd  }|S )Nr   r   z  << r   zAssertionError: assert    )	r   rg   r   r   splitr   r   r   r   )r   r[   linestexts       r   r   r     s    &&))+K
177|!!$'a**ii&uu~~{3D01BCyKr   c                 4   |4t        j                  d      }t        j                  j	                  |      }t        t        | d      j                        }	 |j                  |       y # t        $ r% t        j                         d   }t        |       Y y w xY w)Nr<   r   )r   r   r   r   r   rP   r   r   re   r	   r   r   )r   rR   r   r   s       r   re   re     sv    }a e$5F+001F

5 LLN1qs   A) )+BB__main__c                       y)N   r   r   r   r   fr         r   c                       y)N   r   r   r   r   gr     r   r   c                      y)Nneverr   )r   s    r   hr    s    r   zf() * g() == 5znot f()znot (f() and g() or 0)z
f() == g()   zi == f()zlen(f()) == 0zisinstance(2+3+4, float)zx = izx == 5zassert not f(), 'oops'za, b, c = 1, 2za, b, c = f()zmax([f(),g()]) == 4z'hello'[g()] == 'h'z'guk%d' % h(f())r   )F)7r   r   r2   compilerr   r   r   py._code.assertionr   r   r   builtin_sysexrZ   r	   r   r   r?   rP   ri   ry   r   r   	keepaliveNotInvertitemsr   r   r   r   AddSubMulDivModPowerr   r   r   r   r   r   rb   r   r   r   r   r   re   r   r   r   r  ir   r   r   <module>r     sf   	  * * I 

!! 
LF6 LF^#5D #5L")= ")Hm 4B- BA A  	GG&JJ% eg!Hj
$] $  Z +!2 GG7GG7GG7GG7GG7II8 eg"Hj$m $( [!;"@>L} >L@Lm L<$] $* ]  (,m ,= LQ.,		 z	
	)	
"#	,	A	*	/	
$%L	(O !	
 	
 5 r   