o
    e"k  ã                   @   s²   d Z ddlmZmZ ddlZddlZddlZddlZddlZddlm	Z	 de
ejjd ƒ Zdd„ ZG d	d
„ d
ƒZejfdd„Zdd„ Zdd„ ZedkrWeejdd… ƒ dS dS )z'Usage: unparse.py <path to source file>é    )Úprint_functionÚunicode_literalsN)ÚStringIOZ1eé   c                 C   sJ   t |ƒ}z|t|ƒƒ W n
 ty   Y dS w |D ]	}| ƒ  ||ƒ qdS )z<Call f on each item in seq, calling inter() in between.
    N)ÚiterÚnextÚStopIteration)ÚinterÚfÚseqÚx© r   úCD:\Projects\ConvertPro\env\Lib\site-packages\astunparse/unparser.pyÚ
interleave   s   ÿ
þr   c                   @   s2  e Zd ZdZejfdd„ZdÓdd„Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Z d9d:„ Z!d;d<„ Z"d=d>„ Z#d?d@„ Z$dAdB„ Z%dCdD„ Z&dEdF„ Z'dGdH„ Z(dIdJ„ Z)dKdL„ Z*dMdN„ Z+dOdP„ Z,dQdR„ Z-dSdT„ Z.dUdV„ Z/dWdX„ Z0dÔdZd[„Z1d\d]„ Z2d^d_„ Z3d`da„ Z4dbdc„ Z5ddde„ Z6dfdg„ Z7dhdi„ Z8djdk„ Z9dldm„ Z:dndo„ Z;dpdq„ Z<drds„ Z=dtdu„ Z>dvdw„ Z?dxdy„ Z@dzd{„ ZAd|d}„ ZBd~d„ ZCd€d„ ZDd‚dƒ„ ZEd„d…„ ZFd†d‡„ ZGdˆd‰„ ZHdŠd‹„ ZIdŒd„ ZJdŽd„ ZKdd‘d’d“d”œZLd•d–„ ZMd’d“d—d˜d™dšd›dœddždŸd d¡d¢œZNd£d¤„ ZOd¥d¦d§d¨d©dªd«d¬d­d®d¯œ
ZPd°d±„ ZQeRjSd²eRjTd³iZUd´dµ„ ZVd¶d·„ ZWd¸d¹„ ZXdºd»„ ZYd¼d½„ ZZd¾d¿„ Z[dÀdÁ„ Z\dÂdÃ„ Z]dÄdÅ„ Z^dÆdÇ„ Z_dÈdÉ„ Z`dÊdË„ ZadÌdÍ„ ZbdÎdÏ„ ZcdÐdÑ„ ZddÒS )ÕÚUnparserzŽMethods in this class recursively traverse an AST and
    output source code for the abstract syntax; original formatting
    is disregarded. c                 C   s8   || _ g | _d| _|  |¡ td| j d | j  ¡  dS )zTUnparser(tree, file=sys.stdout) -> None.
         Print the source for tree to file.r   Ú ©ÚfileN)r
   Úfuture_importsÚ_indentÚdispatchÚprintÚflush)ÚselfÚtreer   r   r   r   Ú__init__    s   
zUnparser.__init__r   c                 C   s   | j  dd| j  | ¡ dS )zBIndent a piece of text, according to the current indentation levelÚ
z    N)r
   Úwriter   ©r   Útextr   r   r   Úfill*   s   zUnparser.fillc                 C   s   | j  t |¡¡ dS )z+Append a piece of text to the current line.N)r
   r   ÚsixÚ	text_typer   r   r   r   r   .   s   zUnparser.writec                 C   s   |   d¡ |  jd7  _dS )z(Print ':', and increase the indentation.ú:r   N)r   r   ©r   r   r   r   Úenter2   s   
zUnparser.enterc                 C   s   |  j d8  _ dS )zDecrease the indentation level.r   N)r   r$   r   r   r   Úleave7   s   zUnparser.leavec                 C   s@   t |tƒr|D ]}|  |¡ qdS t| d|jj ƒ}||ƒ dS )z:Dispatcher function, dispatching tree type T to method _T.NÚ_)Ú
isinstanceÚlistr   ÚgetattrÚ	__class__Ú__name__)r   r   ÚtÚmethr   r   r   r   ;   s   
zUnparser.dispatchc                 C   ó   |j D ]}|  |¡ qd S ©N©Úbodyr   ©r   r   Ústmtr   r   r   Ú_ModuleL   ó   
ÿzUnparser._Modulec                 C   r/   r0   r1   r3   r   r   r   Ú_InteractiveP   r6   zUnparser._Interactivec                 C   ó   |   |j¡ d S r0   )r   r2   ©r   r   r   r   r   Ú_ExpressionT   ó   zUnparser._Expressionc                 C   s   |   ¡  |  |j¡ d S r0   )r    r   Úvaluer9   r   r   r   Ú_ExprX   s   zUnparser._Exprc                 C   s:   |   d¡ |  |j¡ |   d¡ |  |j¡ |   d¡ d S )Nú(z := ú))r   r   Útargetr<   r9   r   r   r   Ú
_NamedExpr\   ó
   

zUnparser._NamedExprc                    ó&   ˆ   d¡ t‡ fdd„ˆ j|jƒ d S )Nzimport c                      ó
   ˆ   d¡S ©Nú, ©r   r   r$   r   r   Ú<lambda>e   ó   
 z"Unparser._Import.<locals>.<lambda>)r    r   r   Únames©r   r-   r   r$   r   Ú_Importc   ó   
zUnparser._Importc                    sz   |j r|j dkrˆ j dd„ |jD ƒ¡ ˆ  d¡ ˆ  d|j ¡ |j r*ˆ  |j ¡ ˆ  d¡ t‡ fdd„ˆ j|jƒ d S )	NÚ
__future__c                 s   s    | ]}|j V  qd S r0   )Úname©Ú.0Únr   r   r   Ú	<genexpr>j   s   € z'Unparser._ImportFrom.<locals>.<genexpr>zfrom Ú.z import c                      rD   rE   rG   r   r$   r   r   rH   q   rI   z&Unparser._ImportFrom.<locals>.<lambda>)	Úmoduler   ÚextendrJ   r    r   Úlevelr   r   rK   r   r$   r   Ú_ImportFromg   s   

zUnparser._ImportFromc                 C   s8   |   ¡  |jD ]}|  |¡ |  d¡ q|  |j¡ d S )Nú = )r    Útargetsr   r   r<   )r   r-   r@   r   r   r   Ú_Assigns   s
   

zUnparser._Assignc                 C   sB   |   ¡  |  |j¡ |  d| j|jjj  d ¡ |  |j¡ d S )Nú z= )	r    r   r@   r   ÚbinopÚopr+   r,   r<   rK   r   r   r   Ú
_AugAssignz   s   zUnparser._AugAssignc                 C   sŠ   |   ¡  |jst|jtjƒr|  d¡ |  |j¡ |js(t|jtjƒr(|  d¡ |  d¡ |  |j¡ |j	rC|  d¡ |  |j	¡ d S d S )Nr>   r?   ú: rY   )
r    Úsimpler(   r@   ÚastÚNamer   r   Ú
annotationr<   rK   r   r   r   Ú
_AnnAssign€   s   



þzUnparser._AnnAssignc                 C   s.   |   d¡ |jr|  d¡ |  |j¡ d S d S )NÚreturnr\   )r    r<   r   r   rK   r   r   r   Ú_Return   s
   

þzUnparser._Returnc                 C   ó   |   d¡ d S )NÚpass©r    rK   r   r   r   Ú_Pass“   ó   zUnparser._Passc                 C   rh   )NÚbreakrj   rK   r   r   r   Ú_Break–   rl   zUnparser._Breakc                 C   rh   )NÚcontinuerj   rK   r   r   r   Ú	_Continue™   rl   zUnparser._Continuec                    rC   )Nzdel c                      rD   rE   rG   r   r$   r   r   rH   ž   rI   z"Unparser._Delete.<locals>.<lambda>)r    r   r   rZ   rK   r   r$   r   Ú_Deleteœ   rM   zUnparser._Deletec                 C   s:   |   d¡ |  |j¡ |jr|  d¡ |  |j¡ d S d S )Nzassert rF   )r    r   ÚtestÚmsgr   rK   r   r   r   Ú_Assert    s   

þzUnparser._Assertc                 C   sV   |   d¡ |  |j¡ |jr|  d¡ |  |j¡ |jr)|  d¡ |  |j¡ d S d S )Nzexec ú in rF   )r    r   r2   Úglobalsr   ÚlocalsrK   r   r   r   Ú_Exec§   s   


þzUnparser._Execc                 C   sp   |   d¡ d}|jr|  d¡ |  |j¡ d}|jD ]}|r$|  d¡ nd}|  |¡ q|js6|  d¡ d S d S )Nzprint Fú>>TrF   ú,)r    Údestr   r   ÚvaluesÚnl)r   r-   Zdo_commaÚer   r   r   Ú_Print±   s   


ÿzUnparser._Printc                    rC   )Nzglobal c                      rD   rE   rG   r   r$   r   r   rH   Á   rI   z"Unparser._Global.<locals>.<lambda>©r    r   r   rJ   rK   r   r$   r   Ú_Global¿   rM   zUnparser._Globalc                    rC   )Nz	nonlocal c                      rD   rE   rG   r   r$   r   r   rH   Å   rI   z$Unparser._Nonlocal.<locals>.<lambda>r€   rK   r   r$   r   Ú	_NonlocalÃ   rM   zUnparser._Nonlocalc                 C   ó>   |   d¡ |   d¡ |jr|   d¡ |  |j¡ |   d¡ d S )Nr>   Úawaitr\   r?   ©r   r<   r   rK   r   r   r   Ú_AwaitÇ   ó   


zUnparser._Awaitc                 C   rƒ   )Nr>   Úyieldr\   r?   r…   rK   r   r   r   Ú_YieldÏ   r‡   zUnparser._Yieldc                 C   rƒ   )Nr>   z
yield fromr\   r?   r…   rK   r   r   r   Ú
_YieldFrom×   r‡   zUnparser._YieldFromc                 C   sº   |   d¡ tjr/|js|jrJ ‚d S |  d¡ |  |j¡ |jr-|  d¡ |  |j¡ d S d S |  d¡ |jr=|  |j¡ |jrK|  d¡ |  |j¡ |j	r[|  d¡ |  |j	¡ d S d S )NÚraiser\   z from rF   )
r    r!   ÚPY3ÚexcÚcauser   r   ÚtypeÚinstZtbackrK   r   r   r   Ú_Raiseß   s*   



þ


þzUnparser._Raisec                 C   sœ   |   d¡ |  ¡  |  |j¡ |  ¡  |jD ]}|  |¡ q|jr4|   d¡ |  ¡  |  |j¡ |  ¡  |jrL|   d¡ |  ¡  |  |j¡ |  ¡  d S d S )NÚtryÚelseÚfinally)r    r%   r   r2   r&   ÚhandlersÚorelseÚ	finalbody©r   r-   Úexr   r   r   Ú_Tryõ   s"   



üzUnparser._Tryc                 C   sp   |   d¡ |  ¡  |  |j¡ |  ¡  |jD ]}|  |¡ q|jr6|   d¡ |  ¡  |  |j¡ |  ¡  d S d S )Nr’   r“   )r    r%   r   r2   r&   r•   r–   r˜   r   r   r   Ú
_TryExcept  s   


üzUnparser._TryExceptc                 C   s~   t |jƒdkrt|jd tjƒr|  |j¡ n|  d¡ |  ¡  |  |j¡ |  ¡  |  d¡ |  ¡  |  |j	¡ |  ¡  d S )Nr   r   r’   r”   )
Úlenr2   r(   rb   Z	TryExceptr   r    r%   r&   r—   rK   r   r   r   Ú_TryFinally  s    

zUnparser._TryFinallyc                 C   sv   |   d¡ |jr|  d¡ |  |j¡ |jr+|  d¡ tjr%|  |j¡ n|  |j¡ |  ¡  |  |j¡ |  	¡  d S )NÚexceptr\   ú as )
r    r   r   r   rO   r!   rŒ   r%   r2   r&   rK   r   r   r   Ú_ExceptHandler$  s   


zUnparser._ExceptHandlerc                 C   sz  |   d¡ |jD ]}|  d¡ |  |¡ q|  d|j ¡ tjr|   d¡ d}|jD ]}|r4|   d¡ nd}|  |¡ q*|jD ]}|rI|   d¡ nd}|  |¡ q?t	j
d d… d	k rŠ|jrr|re|   d¡ nd}|   d
¡ |  |j¡ |jrŠ|r}|   d¡ nd}|   d¡ |  |j¡ |   d¡ n|jr­|   d¡ |jD ]}|  |¡ |   d¡ q›|   d¡ |  ¡  |  |j¡ |  ¡  d S )Nr   ú@zclass r>   FrF   Té   ©é   é   Ú*ú**r?   )r   Údecorator_listr    r   rO   r!   rŒ   ÚbasesÚkeywordsÚsysÚversion_infoÚstarargsÚkwargsr%   r2   r&   )r   r-   ÚdecoÚcommar~   Úar   r   r   Ú	_ClassDef3  sJ   











zUnparser._ClassDefc                 C   ó   |   |d¡ d S )NÚdef©Ú_Unparser__FunctionDef_helperrK   r   r   r   Ú_FunctionDefZ  r;   zUnparser._FunctionDefc                 C   r³   )Nz	async defrµ   rK   r   r   r   Ú_AsyncFunctionDef]  r;   zUnparser._AsyncFunctionDefc                 C   sž   |   d¡ |jD ]}|  d¡ |  |¡ q|d |j d }|  |¡ |  |j¡ |   d¡ t|ddƒr?|   d¡ |  |j¡ |  ¡  |  |j	¡ |  
¡  d S )	Nr   r¡   r\   r>   r?   ÚreturnsFz -> )r   r¨   r    r   rO   Úargsr*   r¹   r%   r2   r&   )r   r-   Úfill_suffixr¯   Údef_strr   r   r   Z__FunctionDef_helper`  s   





zUnparser.__FunctionDef_helperc                 C   ó   |   d|¡ d S )Nzfor ©Ú_Unparser__For_helperrK   r   r   r   Ú_Forp  r;   zUnparser._Forc                 C   r½   )Nz
async for r¾   rK   r   r   r   Ú	_AsyncFors  r;   zUnparser._AsyncForc                 C   s|   |   |¡ |  |j¡ |  d¡ |  |j¡ |  ¡  |  |j¡ |  ¡  |jr<|   d¡ |  ¡  |  |j¡ |  ¡  d S d S )Nru   r“   )	r    r   r@   r   r   r%   r2   r&   r–   )r   r    r-   r   r   r   Z__For_helperv  s   


üzUnparser.__For_helperc                 C   sî   |   d¡ |  |j¡ |  ¡  |  |j¡ |  ¡  |jr]t|jƒdkr]t|jd t	j
ƒr]|jd }|   d¡ |  |j¡ |  ¡  |  |j¡ |  ¡  |jr]t|jƒdkr]t|jd t	j
ƒs,|jru|   d¡ |  ¡  |  |j¡ |  ¡  d S d S )Nzif r   r   zelif r“   )r    r   rr   r%   r2   r&   r–   rœ   r(   rb   ÚIfrK   r   r   r   Ú_If„  s.   
ÿ

ùÿ	
üzUnparser._Ifc                 C   sf   |   d¡ |  |j¡ |  ¡  |  |j¡ |  ¡  |jr1|   d¡ |  ¡  |  |j¡ |  ¡  d S d S )Nzwhile r“   )r    r   rr   r%   r2   r&   r–   rK   r   r   r   Ú_Whileš  s   

üzUnparser._WhileFc                    s~   ˆ   |rdnd¡ t|dƒrt‡ fdd„ˆ j|jƒ nˆ  |j¡ |jr/ˆ  d¡ ˆ  |j¡ ˆ  ¡  ˆ  |j	¡ ˆ  
¡  d S )Nzasync with zwith Úitemsc                      rD   rE   rG   r   r$   r   r   rH   ©  rI   z(Unparser._generic_With.<locals>.<lambda>rŸ   )r    Úhasattrr   r   rÅ   Úcontext_exprÚoptional_varsr   r%   r2   r&   )r   r-   Úasync_r   r$   r   Ú_generic_With¦  s   

zUnparser._generic_Withc                 C   s   |   |¡ d S r0   ©rÊ   rK   r   r   r   Ú_With³  rl   zUnparser._Withc                 C   s   | j |dd d S )NT)rÉ   rË   rK   r   r   r   Ú
_AsyncWith¶  s   zUnparser._AsyncWithc                 C   ó   |   t|jƒ¡ d S r0   )r   ÚreprÚsrK   r   r   r   Ú_Bytesº  ó   zUnparser._Bytesc                 C   sŠ   t jr|  t|jƒ¡ d S d| jvr|  t|jƒ¡ d S t|jtƒr.|  dt|jƒ ¡ d S t|jtƒrA|  t|jƒ 	d¡¡ d S J dƒ‚)Nr   ÚbÚuFzshouldn't get here)
r!   rŒ   r   rÏ   rÐ   r   r(   ÚstrÚunicodeÚlstripr9   r   r   r   Ú_Str½  s   
zUnparser._Strc                 C   s‚   |   d¡ tƒ }|  ||j ¡ | ¡ }d|v sd|v r ddg}ng d¢}|D ]}||vr5dj||d} nq&t|ƒ}|   |¡ d S )	Nr
   r   úú'''ú""")ú'ú"rÛ   rÚ   z{quote_type}{v}{quote_type})Ú
quote_typeÚv)r   r   Ú_fstring_JoinedStrÚgetvalueÚformatrÏ   )r   r-   Ústringrß   Úquote_typesrÞ   r   r   r   Ú
_JoinedStrÍ  s   

þzUnparser._JoinedStrc                 C   s4   |   d¡ tƒ }|  ||j ¡ |   t| ¡ ƒ¡ d S )Nr
   )r   r   rà   rÏ   rá   )r   r-   rã   r   r   r   Ú_FormattedValueá  s   
zUnparser._FormattedValuec                 C   s.   |j D ]}t| dt|ƒj ƒ}|||ƒ qd S )NÚ	_fstring_)r|   r*   r   r,   )r   r-   r   r<   r.   r   r   r   rà   è  s   
þzUnparser._fstring_JoinedStrc                 C   s"   |j  dd¡ dd¡}||ƒ d S ©NÚ{z{{Ú}z}})rÐ   Úreplace©r   r-   r   r<   r   r   r   Ú_fstring_Strí  s   zUnparser._fstring_Strc                 C   s2   t |jtƒsJ ‚|j dd¡ dd¡}||ƒ d S rè   )r(   r<   rÕ   rë   rì   r   r   r   Ú_fstring_Constantñ  s   zUnparser._fstring_Constantc                 C   s®   |dƒ t ƒ }t|j|ƒ | ¡  d¡}| d¡r|dƒ ||ƒ |jdkr9t|jƒ}|dv s1J ‚|dj|dƒ |j	rQ|dƒ t
| d	t|j	ƒj ƒ}||j	|ƒ |d
ƒ d S )Nré   r   r\   éÿÿÿÿÚsraz!{conversion})Ú
conversionr#   rç   rê   )r   r   r<   rá   ÚrstripÚ
startswithrñ   Úchrrâ   Úformat_specr*   r   r,   )r   r-   r   Úexprrñ   r.   r   r   r   Ú_fstring_FormattedValueö  s    


z Unparser._fstring_FormattedValuec                 C   r8   r0   )r   ÚidrK   r   r   r   Ú_Name  r;   zUnparser._Namec                 C   rÎ   r0   )r   rÏ   r<   rK   r   r   r   Ú_NameConstant  rÒ   zUnparser._NameConstantc                 C   s$   |   d¡ |  |j¡ |   d¡ d S )Nú`©r   r   r<   rK   r   r   r   Ú_Repr  s   
zUnparser._Reprc                 C   s:   t |ttfƒr|  t|ƒ dt¡¡ d S |  t|ƒ¡ d S )NÚinf)r(   ÚfloatÚcomplexr   rÏ   rë   ÚINFSTR)r   r<   r   r   r   Ú_write_constant  s   zUnparser._write_constantc                    sž   |j }t|tƒr2ˆ  d¡ t|ƒdkr ˆ  |d ¡ ˆ  d¡ nt‡ fdd„ˆ j|ƒ ˆ  d¡ d S |tu r=ˆ  d¡ d S |jd	krGˆ  d	¡ ˆ  |j ¡ d S )
Nr>   r   r   rz   c                      rD   rE   rG   r   r$   r   r   rH   "  rI   z$Unparser._Constant.<locals>.<lambda>r?   ú...rÔ   )	r<   r(   Útupler   rœ   r  r   ÚEllipsisÚkind)r   r-   r<   r   r$   r   Ú	_Constant  s   



zUnparser._Constantc                 C   s†   t |jƒ}tjr|  | dt¡¡ d S | d¡r|  d¡ d|v r,| d¡r,| dd¡}|  | dt¡¡ | d¡rA|  d¡ d S d S )Nrþ   ú-r>   z*jÚjr?   )	rÏ   rR   r!   rŒ   r   rë   r  ró   Úendswith)r   r-   Zrepr_nr   r   r   Ú_Num+  s   



ÿzUnparser._Numc                    s0   ˆ   d¡ t‡ fdd„ˆ j|jƒ ˆ   d¡ d S )Nú[c                      rD   rE   rG   r   r$   r   r   rH   <  rI   z Unparser._List.<locals>.<lambda>ú])r   r   r   ÚeltsrK   r   r$   r   Ú_List:  s   
zUnparser._Listc                 C   ó:   |   d¡ |  |j¡ |jD ]}|  |¡ q|   d¡ d S ©Nr  r  ©r   r   ÚeltÚ
generators©r   r-   Úgenr   r   r   Ú	_ListComp?  rB   zUnparser._ListCompc                 C   r  )Nr>   r?   r  r  r   r   r   Ú_GeneratorExpF  rB   zUnparser._GeneratorExpc                 C   r  )Nré   rê   r  r  r   r   r   Ú_SetCompM  rB   zUnparser._SetCompc                 C   sP   |   d¡ |  |j¡ |   d¡ |  |j¡ |jD ]}|  |¡ q|   d¡ d S )Nré   r`   rê   )r   r   Úkeyr<   r  r  r   r   r   Ú	_DictCompT  ó   


zUnparser._DictCompc                 C   sh   t |ddƒr|  d¡ n|  d¡ |  |j¡ |  d¡ |  |j¡ |jD ]}|  d¡ |  |¡ q%d S )NÚis_asyncFz async for z for ru   ú if )r*   r   r   r@   r   Úifs)r   r-   Ú	if_clauser   r   r   Ú_comprehension]  s   



þzUnparser._comprehensionc                 C   sP   |   d¡ |  |j¡ |   d¡ |  |j¡ |   d¡ |  |j¡ |   d¡ d S )Nr>   r  z else r?   )r   r   r2   rr   r–   rK   r   r   r   Ú_IfExpi  r  zUnparser._IfExpc                    s:   |j sJ ‚ˆ  d¡ t‡ fdd„ˆ j|j ƒ ˆ  d¡ d S )Nré   c                      rD   rE   rG   r   r$   r   r   rH   u  rI   zUnparser._Set.<locals>.<lambda>rê   )r  r   r   r   rK   r   r$   r   Ú_Setr  s   

zUnparser._Setc                    sP   ˆ   d¡ ‡ fdd„‰‡ ‡fdd„}t‡ fdd„|t|j|jƒƒ ˆ   d¡ d S )	Nré   c                    s"   ˆ   | ¡ ˆ  d¡ ˆ   |¡ d S ©Nr`   )r   r   )Úkrß   r$   r   r   Úwrite_key_value_pairz  s   

z,Unparser._Dict.<locals>.write_key_value_pairc                    s6   | \}}|d u rˆ   d¡ ˆ  |¡ d S ˆ||ƒ d S )Nr§   )r   r   )Úitemr%  rß   ©r   r&  r   r   Ú
write_item  s
   
z"Unparser._Dict.<locals>.write_itemc                      rD   rE   rG   r   r$   r   r   rH   ˆ  rI   z Unparser._Dict.<locals>.<lambda>rê   )r   r   ÚzipÚkeysr|   )r   r-   r)  r   r(  r   Ú_Dictx  s
   
	zUnparser._Dictc                    s^   ˆ   d¡ t|jƒdkr|jd }ˆ  |¡ ˆ   d¡ nt‡ fdd„ˆ j|jƒ ˆ   d¡ d S )Nr>   r   r   rz   c                      rD   rE   rG   r   r$   r   r   rH   ’  rI   z!Unparser._Tuple.<locals>.<lambda>r?   )r   rœ   r  r   r   )r   r-   r  r   r$   r   Ú_Tuple‹  s   


zUnparser._Tupleú~Únotú+r  )ÚInvertÚNotÚUAddÚUSubc                 C   sˆ   |   d¡ |   | j|jjj ¡ |   d¡ tjr7t|jtj	ƒr7t|j
tjƒr7|   d¡ |  |j
¡ |   d¡ n|  |j
¡ |   d¡ d S ©Nr>   r\   r?   )r   Úunopr^   r+   r,   r!   ÚPY2r(   rb   r4  ÚoperandÚNumr   rK   r   r   r   Ú_UnaryOp–  s   

"
zUnparser._UnaryOpr¦   r¡   ú/ú%z<<ry   ú|ú^ú&z//r§   )ÚAddÚSubÚMultÚMatMultÚDivÚModÚLShiftÚRShiftÚBitOrÚBitXorÚBitAndÚFloorDivÚPowc                 C   sN   |   d¡ |  |j¡ |   d| j|jjj  d ¡ |  |j¡ |   d¡ d S r5  )r   r   Úleftr]   r^   r+   r,   ÚrightrK   r   r   r   Ú_BinOpª  s
   
zUnparser._BinOpz==z!=ú<z<=ú>z>=Úiszis notÚinznot in)
ÚEqÚNotEqÚLtÚLtEÚGtÚGtEÚIsÚIsNotÚInÚNotInc                 C   sb   |   d¡ |  |j¡ t|j|jƒD ]\}}|   d| j|jj  d ¡ |  |¡ q|   d¡ d S r5  )	r   r   rM  r*  ÚopsÚcomparatorsÚcmpopsr+   r,   )r   r-   Úor~   r   r   r   Ú_Compare³  s   
zUnparser._CompareÚandÚorc                    sD   ˆ  d¡ dˆj|jj  ‰ t‡ ‡fdd„ˆj|jƒ ˆ  d¡ d S )Nr>   z %s c                      s
   ˆ  ˆ ¡S r0   rG   r   ©rÐ   r   r   r   rH   ¿  rI   z"Unparser._BoolOp.<locals>.<lambda>r?   )r   Úboolopsr^   r+   r   r   r|   rK   r   re  r   Ú_BoolOp¼  s   
zUnparser._BoolOpc              	   C   sZ   |   |j¡ t|jttdttdd ƒƒƒr t|jjtƒr |  d¡ |  d¡ |  |j¡ d S )NÚConstantr9  r\   rT   )	r   r<   r(   r*   rb   rR   Úintr   ÚattrrK   r   r   r   Ú
_AttributeÂ  s
   *

zUnparser._Attributec                 C   sî   |   |j¡ |  d¡ d}|jD ]}|r|  d¡ nd}|   |¡ q|jD ]}|r/|  d¡ nd}|   |¡ q%tjd d… dk rp|jrX|rK|  d¡ nd}|  d¡ |   |j¡ |jrp|rc|  d¡ nd}|  d¡ |   |j¡ |  d	¡ d S )
Nr>   FrF   Tr¢   r£   r¦   r§   r?   )	r   Úfuncr   rº   rª   r«   r¬   r­   r®   )r   r-   r°   r~   r   r   r   Ú_CallÌ  s.   




zUnparser._Callc                 C   s0   |   |j¡ |  d¡ |   |j¡ |  d¡ d S r  )r   r<   r   ÚslicerK   r   r   r   Ú
_Subscriptå  s   
zUnparser._Subscriptc                 C   s   |   d¡ |  |j¡ d S )Nr¦   rü   rK   r   r   r   Ú_Starredë  s   
zUnparser._Starredc                 C   rh   )Nr  rG   rK   r   r   r   Ú	_Ellipsisð  rl   zUnparser._Ellipsisc                 C   r8   r0   )r   r<   rK   r   r   r   Ú_Indexó  r;   zUnparser._Indexc                 C   sR   |j r	|  |j ¡ |  d¡ |jr|  |j¡ |jr'|  d¡ |  |j¡ d S d S )Nr#   )Úlowerr   r   ÚupperÚsteprK   r   r   r   Ú_Sliceö  s   

þzUnparser._Slicec                    s   t ‡ fdd„ˆ j|jƒ d S )Nc                      rD   rE   rG   r   r$   r   r   rH     rI   z$Unparser._ExtSlice.<locals>.<lambda>)r   r   ÚdimsrK   r   r$   r   Ú	_ExtSlice   s   zUnparser._ExtSlicec                 C   s0   |   |j¡ |jr|   d¡ |  |j¡ d S d S r$  )r   Úargrd   r   rK   r   r   r   Ú_arg  ó
   
þzUnparser._argc           	      C   sL  d}t |dg ƒ|j }d gt|ƒt|jƒ  |j }tt||ƒdƒD ]2\}}|\}}|r/d}n|  d¡ |  |¡ |rE|  d¡ |  |¡ |tt |ddƒƒkrT|  d¡ q"|js^t |d	dƒr¥|rcd}n|  d¡ |  d
¡ |jr¥t	|jdƒrŽ|  |jj
¡ |jjr|  d¡ |  |jj¡ n|  |j¡ t |dd ƒr¥|  d¡ |  |j¡ t |d	dƒrÓt|j|jƒD ] \}}|r»d}n|  d¡ |  |¡f |rÒ|  d¡ |  |¡ q²|jr"|rÜd}n|  d¡ t	|jdƒr|  d|jj
 ¡ |jjr|  d¡ |  |jj¡ d S d S |  d|j ¡ t |dd ƒr$|  d¡ |  |j¡ d S d S d S )NTÚposonlyargsr   FrF   ú=r   z, /Ú
kwonlyargsr¦   ry  r`   Úvarargannotationr§   Úkwargannotation)r*   rº   rœ   ÚdefaultsÚ	enumerater*  r   r   ÚvarargrÆ   ry  rd   r  r~  Úkw_defaultsÚkwargr€  )	r   r-   ÚfirstÚall_argsr  ÚindexÚelementsr±   Údr   r   r   Ú
_arguments  sj   





€



€




€



þ
ô
zUnparser._argumentsc                 C   s<   |j d u r|  d¡ n|  |j ¡ |  d¡ |  |j¡ d S )Nr§   r}  )ry  r   r   r<   rK   r   r   r   Ú_keywordE  s
   

zUnparser._keywordc                 C   sD   |   d¡ |   d¡ |  |j¡ |   d¡ |  |j¡ |   d¡ d S )Nr>   zlambda r`   r?   )r   r   rº   r2   rK   r   r   r   Ú_LambdaN  s   


zUnparser._Lambdac                 C   s*   |   |j¡ |jr|   d|j ¡ d S d S ©NrŸ   )r   rO   ÚasnamerK   r   r   r   Ú_aliasV  s   ÿzUnparser._aliasc                 C   s0   |   |j¡ |jr|  d¡ |   |j¡ d S d S rŽ  )r   rÇ   rÈ   r   rK   r   r   r   Ú	_withitem[  r{  zUnparser._withitemN)r   )F)er,   Ú
__module__Ú__qualname__Ú__doc__r«   Ústdoutr   r    r   r%   r&   r   r5   r7   r:   r=   rA   rL   rX   r[   r_   re   rg   rk   rn   rp   rq   rt   rx   r   r   r‚   r†   r‰   rŠ   r‘   rš   r›   r   r    r²   r·   r¸   r¶   rÀ   rÁ   r¿   rÃ   rÄ   rÊ   rÌ   rÍ   rÑ   rØ   rå   ræ   rà   rí   rî   r÷   rù   rú   rý   r  r  r  r  r  r  r  r  r!  r"  r#  r,  r-  r6  r:  r]   rO  r`  rb  rb   ÚAndÚOrrf  rg  rk  rm  ro  rp  rq  rr  rv  rx  rz  r‹  rŒ  r  r  r‘  r   r   r   r   r      sÆ    


'
		

þÿ

:	r   c                 C   sÌ   t jr<t| dƒ}t |j¡d }W d   ƒ n1 sw   Y  t| d|d}| ¡ }W d   ƒ n1 s6w   Y  nt| dƒ}| ¡ }W d   ƒ n1 sPw   Y  t|| dtj	dd}t
||ƒ d S )NÚrbr   Úr)ÚencodingÚexecT)Údont_inherit)r!   rŒ   ÚopenÚtokenizeÚdetect_encodingÚreadlineÚreadÚcompilerb   ÚPyCF_ONLY_ASTr   )ÚfilenameÚoutputZpyfilerš  Úsourcer   r   r   r   Ú	roundtripa  s   ÿ
ÿ€
ÿr§  c                 C   sÒ   zdd„ t  | ¡D ƒ}W n ty   td|  tjd Y d S w |D ]D}t j | |¡}t j |¡r\t	ƒ }td| ƒ zt
||ƒ W q" ty[ } ztdt|ƒ ƒ W Y d }~q"d }~ww t j |¡rft|ƒ q"d S )Nc                 S   s   g | ]	}|  d ¡r|‘qS )z.py)r
  rP   r   r   r   Ú
<listcomp>q  s    ztestdir.<locals>.<listcomp>zDirectory not readable: %sr   z
Testing %sz$  Failed to compile, exception is %s)ÚosÚlistdirÚOSErrorr   r«   ÚstderrÚpathÚjoinÚisfiler   r§  Ú	ExceptionrÏ   ÚisdirÚtestdir)r±   rJ   rR   Úfullnamer¥  r~   r   r   r   r²  o  s(   ÿ€ÿ€ör²  c                 C   s@   | d dkr| dd … D ]}t |ƒ qd S | D ]}t|ƒ qd S )Nr   z	--testdirr   )r²  r§  )rº   r±   r   r   r   Úmain  s   
ÿ
ÿr´  Ú__main__)r”  rN   r   r   r!   r«   rb   r©  rž  r   rÏ   Ú
float_infoÚ
max_10_expr  r   r   r•  r§  r²  r´  r,   Úargvr   r   r   r   Ú<module>   s.          Lÿ