a
    /§»aÍE  ã                   @   sˆ  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„ dƒZG dd„ deƒZdd	„ ZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZg Zejdejdi ¡ D ]"\ZZG dd„ deƒZe e¡ qÚejdej dej!dej"dej#dej$di ¡ D ]$\ZZG dd„ deƒZ%e e%¡ �q*G d d!„ d!eƒZ&G d"d#„ d#eƒZ'G d$d%„ d%eƒZ(G d&d'„ d'eƒZ)G d(d)„ d)eƒZ*G d*d+„ d+eƒZ+d,d-„ Z,dPd.d/„Z-dQd1d2„Z.d3d4„ Z/d5d6„ Z0dRd7d8„Z1e2d9k�r„d:d;„ Z3d<d=„ Z4d>d?„ Z5e-d@ƒ e-dAƒ e-dBƒ e-dCƒ dDZ6e-dEƒ e-dFƒ e-dGƒ e1dHƒ e-dIƒ e1dJƒ e1dKƒ e1dLƒ e-dMƒ e-dNƒ e1dOƒ dS )Sé    N)ÚparseÚastÚ	pycodegen)ÚBuiltinAssertionErrorÚ_format_explanationc                   @   s   e Zd Zdd„ ZdS )ÚFailurec                 C   s   t  ¡ \| _| _| _|| _d S ©N)ÚsysÚexc_infoÚexcÚvalueÚtbÚnode)Úselfr   © r   úP/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/py/_code/_assertionold.pyÚ__init__
   s    zFailure.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   	   s   r   c                   @   sH   e Zd ZdZi ZdZdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ ZdS )Ú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                 O   sR   t  | ¡}||_| |_| ¡ }z|j| |_W n tyL   | |¡|_Y n0 |S r   )	ÚobjectÚ__new__Ú__obj__Ú__rootclass__Ú__viewkey__Ú
_viewcacheÚ	__class__ÚKeyErrorÚ_selectsubclass)Z	rootclassÚobjÚargsÚkwdsr   Úkeyr   r   r   r   -   s    
zView.__new__c                 C   s   t | j|ƒS r   )Úgetattrr   )r   Úattrr   r   r   Ú__getattr__8   s    zView.__getattr__c                 C   s   | j jS r   )r   r   ©r   r   r   r   r   =   s    zView.__viewkey__c                    sH   t  ˆ ¡rt  ˆ ¡}nˆ g}|D ]"‰ ‡ fdd„|D ƒ}|r |  S q g S )Nc                    s   g | ]}ˆ |j v r|‘qS r   )Ú__view__)Ú.0ÚC©r#   r   r   Ú
<listcomp>F   ó    z%View.__matchkey__.<locals>.<listcomp>)ÚinspectÚisclassÚgetmro)r   r#   Ú
subclassesÚkeysÚresultr   r+   r   Ú__matchkey__@   s    

zView.__matchkey__c                 C   sl   t t| jƒƒ}|D ]}t|jtƒs|jf|_q|  ||¡}|sD| jS t|ƒdkrX|d S tdt|ƒi ƒS d S )Né   r   ú?)	ÚlistÚenumsubclassesr   Ú
isinstancer(   Útupler4   ÚlenÚtype)r   r#   r1   r*   Úchoicesr   r   r   r   K   s    zView._selectsubclassc                 C   s   d| j j| jf S )Nz%s(%r))r   r   r   r'   r   r   r   Ú__repr__Y   s    zView.__repr__N)r   r   r   Ú__doc__r   r(   r   r&   r   r4   r   r>   r   r   r   r   r      s   r   c                 c   s,   |   ¡ D ]}t|ƒD ]
}|V  qq| V  d S r   )Ú__subclasses__r8   )ÚclsÚsubclsZsubsubclassr   r   r   r8   ]   s    
r8   c                   @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚInterpretablez+A parse tree node with a few extra methods.Nc                 C   s   dS )NFr   ©r   Úframer   r   r   Ú
is_builtinh   s    zInterpretable.is_builtinc                 C   s|   z6t  | j¡}d|_d| j_t |¡ ¡ }| |¡}W n& tyJ   ‚ Y n   t	| ƒ‚Y n0 || _
| jpt| | j
¡| _d S )Nz<eval>)r   Ú
Expressionr   Úfilenamer   ZExpressionCodeGeneratorÚgetCodeÚevalÚpassthroughexr   r3   ÚexplanationÚrepr)r   rE   ÚexprÚcor3   r   r   r   rJ   k   s    zInterpretable.evalc                 C   sd   z8t  d t  | jg¡¡}d|_t |¡ ¡ }| |¡ W n& t	yL   ‚ Y n   t
| ƒ‚Y n0 d S )Nú<run>)r   ÚModuleÚStmtr   rH   r   ÚModuleCodeGeneratorrI   Úexec_rK   r   )r   rE   rN   rO   r   r   r   Úrunz   s    zInterpretable.runc                 C   s
   t | jƒS r   )r   rL   r'   r   r   r   Únice_explanation†   s    zInterpretable.nice_explanation)	r   r   r   r?   rL   rF   rJ   rU   rV   r   r   r   r   rC   d   s   rC   c                       s:   e Zd ZejZdd„ Zdd„ Zdd„ Z‡ fdd„Z	‡  Z
S )	ÚNamec                 C   sB   d| j  }z| | |¡¡W S  ty0   ‚ Y n   Y dS 0 d S )Nz%r in locals() is not globals()F©ÚnameÚis_truerJ   rK   ©r   rE   Úsourcer   r   r   Úis_local�   s    
zName.is_localc                 C   sB   d| j  }z| | |¡¡W S  ty0   ‚ Y n   Y dS 0 d S )Nz%r in globals()FrX   r[   r   r   r   Ú	is_global–   s    
zName.is_globalc                 C   sH   d| j | j f }z| | |¡¡W S  ty6   ‚ Y n   Y dS 0 d S )Nz*%r not in locals() and %r not in globals()FrX   r[   r   r   r   rF   Ÿ   s    ÿzName.is_builtinc                    s&   t t| ƒ |¡ |  |¡s"| j| _d S r   )ÚsuperrW   rJ   r]   rY   rL   rD   ©r   r   r   rJ   ©   s    
z	Name.eval)r   r   r   r   rW   r(   r]   r^   rF   rJ   Ú__classcell__r   r   r`   r   rW   Š   s
   		
rW   c                   @   s   e Zd ZejZdd„ ZdS )ÚComparec              	   C   s¶   t | jƒ}| |¡ | jD ]–\}}t| dƒr<| | j¡s< q²t |ƒ}| |¡ d|j||jf | _d| }z|j||j|jd�| _W n& ty˜   ‚ Y n   t	| ƒ‚Y n0 |}qd S )Nr3   z%s %s %sz#__exprinfo_left %s __exprinfo_right©Ú__exprinfo_leftÚ__exprinfo_right)
rC   rN   rJ   ÚopsÚhasattrrZ   r3   rL   rK   r   )r   rE   rN   Z	operationZexpr2r\   r   r   r   rJ   ±   s,    




ÿþzCompare.evalN)r   r   r   r   rb   r(   rJ   r   r   r   r   rb   ®   s   rb   c                   @   s   e Zd ZejZdd„ ZdS )ÚAndc                 C   s^   g }| j D ]:}t|ƒ}| |¡ | |j¡ |j| _| |j¡s
 qFq
dd |¡ d | _d S )Nú(z and ú)©ÚnodesrC   rJ   ÚappendrL   r3   rZ   Újoin©r   rE   ÚexplanationsrN   r   r   r   rJ   Ë   s    

zAnd.evalN)r   r   r   r   rh   r(   rJ   r   r   r   r   rh   È   s   rh   c                   @   s   e Zd ZejZdd„ ZdS )ÚOrc                 C   s^   g }| j D ]:}t|ƒ}| |¡ | |j¡ |j| _| |j¡r
 qFq
dd |¡ d | _d S )Nri   z or rj   rk   ro   r   r   r   rJ   Ù   s    

zOr.evalN)r   r   r   r   rq   r(   rJ   r   r   r   r   rq   Ö   s   rq   znot __exprinfo_exprz(~__exprinfo_expr)c                   @   s   e Zd ZeZefdd„ZdS )Ú
UnaryArithc                 C   sf   t | jƒ}| |¡ | d|j¡| _z|j||jd�| _W n& tyN   ‚ Y n   t| ƒ‚Y n0 d S )NÚ__exprinfo_expr©rs   )rC   rN   rJ   ÚreplacerL   r3   rK   r   )r   rE   Ú
astpatternrN   r   r   r   rJ   ï   s    

ÿÿzUnaryArith.evalN©r   r   r   Úastclassr(   rv   rJ   r   r   r   r   rr   ì   s   rr   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                   @   s   e Zd ZeZefdd„ZdS )ÚBinaryArithc                 C   sˆ   t | jƒ}| |¡ t | jƒ}| |¡ | d|j¡ d|j¡| _z|j||j|jd�| _W n& typ   ‚ Y n   t| ƒ‚Y n0 d S )Nrd   re   rc   )	rC   ÚleftrJ   Úrightru   rL   r3   rK   r   )r   rE   rv   rz   r{   r   r   r   rJ     s$    



ÿþþzBinaryArith.evalNrw   r   r   r   r   ry     s   ry   c                   @   s"   e Zd ZejZdd„ Zdd„ ZdS )ÚCallFuncc                 C   sB   d}z|  |j|| jd�¡W S  ty0   ‚ Y n   Y dS 0 d S )Nz"isinstance(__exprinfo_value, bool))Z__exprinfo_valueF)rZ   rJ   r3   rK   r[   r   r   r   Úis_bool"  s    
ÿ
zCallFunc.is_boolc                 C   s  t | jƒ}| |¡ g }d|ji}d}| jD ]�}t|tjƒrJ|j}|j	}nd }t |ƒ}| |¡ dt
|ƒ }|j||< |d u r˜||d 7 }| |j¡ q,|d||f 7 }| d||jf ¡ q,| j�rt | jƒ}	|	 |¡ d}|	j||< |d| d 7 }| d|	j ¡ | j�rRt | jƒ}
|
 |¡ d	}|
j||< |d
| d 7 }| d
|
j ¡ d|jd |¡f | _| d¡�r€|d d… }|d7 }z|j|fi |¤Ž| _W n( t�y¶   ‚ Y n   t| ƒ‚Y n0 | |¡�râ|  |¡�s | | j¡}d||| jf | _d S )NZ__exprinfo_fnz__exprinfo_fn(z__exprinfo_%dú,z%s=%s,z%s=%sZ__exprinfo_starÚ*Z__exprinfo_kwdsz**z%s(%s)z, éÿÿÿÿrj   ú%s
{%s = %s
})rC   r   rJ   r3   r!   r9   r   ÚKeywordrY   rN   r;   rm   rL   Ú	star_argsÚ
dstar_argsrn   ÚendswithrK   r   rF   r}   rM   )r   rE   r   rp   Úvarsr\   ÚaÚkeywordÚargnamerƒ   r„   Úrr   r   r   rJ   ,  s`    











ÿzCallFunc.evalN)r   r   r   r   r|   r(   r}   rJ   r   r   r   r   r|     s   
r|   c                   @   s   e Zd ZejZdd„ ZdS )ÚGetattrc                 C   sÜ   t | jƒ}| |¡ d| j }z|j||jd�| _W n& tyH   ‚ Y n   t| ƒ‚Y n0 d|j| jf | _d| j }z| |j||jd�¡}W n" ty¦   ‚ Y n   d}Y n0 |rØ| 	| j¡}d||| jf | _d S )Nz__exprinfo_expr.%srt   z%s.%szGhasattr(__exprinfo_expr, "__dict__") and %r in __exprinfo_expr.__dict__Tr�   )
rC   rN   rJ   Úattrnamer3   rK   r   rL   rZ   rM   )r   rE   rN   r\   Zfrom_instancerŠ   r   r   r   rJ   b  s0    


ÿÿ
zGetattr.evalN)r   r   r   r   r‹   r(   rJ   r   r   r   r   r‹   _  s   r‹   c                   @   s   e Zd ZejZdd„ ZdS )ÚAssertc                 C   s�   t | jƒ}| |¡ |j d¡r<|j d¡r<|jdd… |_|j| _d|j | _| |j¡sŒzt‚W n& t	yx   ‚ Y n   t
| ƒ‚Y n0 d S )NzFalse
{False = z
}é   éþÿÿÿzassert )rC   ÚtestrJ   rL   Ú
startswithr…   r3   rZ   r   rK   r   )r   rE   r�   r   r   r   rU   €  s    


ÿz
Assert.runN)r   r   r   r   r�   r(   rU   r   r   r   r   r�   }  s   r�   c                   @   s   e Zd ZejZdd„ ZdS )ÚAssignc                 C   s¤   t | jƒ}| |¡ |j| _d|j | _t | jt d¡¡}t 	d t 
|g¡¡}d|_t |¡ ¡ }z|j||jd� W n& tyŒ   ‚ Y n   t| ƒ‚Y n0 d S )Nz... = rs   rP   rt   )rC   rN   rJ   r3   rL   r   r’   rl   rW   rQ   rR   rH   r   rS   rI   rT   rK   r   )r   rE   rN   ZassÚmodrO   r   r   r   rU   •  s    

z
Assign.runN)r   r   r   r   r’   r(   rU   r   r   r   r   r’   ’  s   r’   c                   @   s   e Zd ZejZdd„ ZdS )ÚDiscardc                 C   s(   t | jƒ}| |¡ |j| _|j| _d S r   )rC   rN   rJ   r3   rL   )r   rE   rN   r   r   r   rU   ©  s    

zDiscard.runN)r   r   r   r   r”   r(   rU   r   r   r   r   r”   ¦  s   r”   c                   @   s   e Zd ZejZdd„ ZdS )rR   c                 C   s"   | j D ]}t|ƒ}| |¡ qd S r   )rl   rC   rU   )r   rE   Ústmtr   r   r   rU   ²  s    
zStmt.runN)r   r   r   r   rR   r(   rU   r   r   r   r   rR   ¯  s   rR   c                 C   s<   | j  ¡ }|rd| }nd}tj d| jj| j|f ¡ d S )Nz, in: Ú z	%s: %s%s
)r   rV   r	   ÚstdoutÚwriter   r   r   )ÚerL   r   r   r   Úreport_failure¸  s
    

rš   c                 C   s®   |d u rt  d¡}tj |¡}t| dƒ}t|tjƒs8J ‚t	|j
ƒ}z| |¡ W n8 tyd   ‚ Y nF tyˆ   t  ¡ d }t|ƒ Y n"0 | |j¡sªt j d| ¡  ¡ d S )Nr5   rJ   zassertion failed: %s
)r	   Ú	_getframeÚpyÚcodeÚFramer   r9   r   rG   rC   r   rJ   rK   r   r
   rš   rZ   r3   Ústderrr˜   rV   )ÚsrE   rN   r   r™   r   r   r   ÚcheckÀ  s    


r¡   Fc                 C   sš   t t| dƒjƒ}t|tjƒr(tj |¡}z| 	|¡ W nR t
y\   t ¡ d }t|ƒ Y S  tyn   ‚ Y n   dd l}| ¡  Y n0 |r’dS d S d S )NÚexecr5   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))rC   r   r   r9   ÚtypesÚ	FrameTyperœ   r�   rž   rU   r   r	   r
   Ú
getfailurerK   Ú	tracebackÚ	print_exc)r\   rE   Úshould_failÚmoduler™   r¦   r   r   r   Ú	interpret×  s     rª   c                 C   sZ   t | tƒrtj | ¡} | jd }t|jƒ ¡ }t	||j
dd�}t |tƒsVtd|f ƒ‚|S )Nr€   T)r¨   z interpret returned non-string %r)r9   r:   rœ   r�   ZExceptionInfor¦   ÚstrZ	statementÚstriprª   rE   Ú	TypeError)Úexcinfor   r\   Úxr   r   r   Úgetmsgí  s    


r°   c                 C   sj   | j  ¡ }t| jƒr@| d¡}|d  d| jf 7  < d |¡}d| jj|f }| d¡rf|dd … }|S )NÚ
r   z  << %sz%s: %szAssertionError: assert é   )	r   rV   r«   r   Úsplitrn   r   r   r‘   )r™   rL   ÚlinesÚtextr   r   r   r¥   û  s    




r¥   c                 C   sh   |d u rt  d¡}tj |¡}tt| dƒjƒ}z| |¡ W n& t	yb   t  
¡ d }t|ƒ Y n0 d S )Nr5   r¢   )r	   r›   rœ   r�   rž   rC   r   r   rU   r   r
   rš   )r    rE   r©   r™   r   r   r   rU     s    
rU   Ú__main__c                   C   s   dS )Né   r   r   r   r   r   Úf  s    r¸   c                   C   s   dS )Né   r   r   r   r   r   Úg  s    rº   c                 C   s   dS )NÚneverr   )r¯   r   r   r   Úh  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()))N)F)N)7rœ   r	   r.   Úcompilerr   r   r   Zpy._code.assertionr   r   r£   ÚbuiltinZ_sysexrK   r   r   r   r8   rC   rW   rb   rh   rq   Ú	keepaliveÚNotÚInvertÚitemsrx   rv   rr   rm   ÚAddÚSubZMulÚDivÚModZPowerry   r|   r‹   r�   r’   r”   rR   rš   r¡   rª   r°   r¥   rU   r   r¸   rº   r¼   Úir   r   r   r   Ú<module>   sx   O&$þú	@		



