B
    -¦a;  ã            h   @   sÂ  d dl Zd dlZd dlmZmZmZmZmZm	Z	 d dlm
Z
mZmZmZmZ d dlmZmZ yd dlmZ W n$ ek
r   G dd„ deƒZY nX dd	„ Zd
ddefffdddefffdddefffdddefffdddefffdddefffdddefffdddefffdddefffdddefffdddefffdd defffd!d"defffd#d$defffd%d&defffd'd&defffd(d)defffd*d)defffd+d,defffd-d,defffd.d/defffd0d1defffd2d3defffd4d5defffd6d7defffd8d9defffd:d5defffd;d5defffd<ddefffd=ddefffd>ddefffd?ddefffd@dAdefffdBdCdefffdDdEdefffdFdGdefffdHd)defffdIdJdefffdKdLdefffdMdNdefffdOdNdefffdPdQdefffdRdNdefffdSddefffdTddefffdUddefffdVdWdefffdXdYdefffdZddefffd[d\defffd]d^defffd_d`defffdadbdefffdcdddefffdedfdefffdgdhdefffdidjdefffdkdjdefffdlddefffdmddefffdnddefffdoddefffdpddefffdqddefffdrdsde
fffdtddefffduddefffdvdde	fffdwdde	fffdxdde	fffdydde	fffdzdde	fffd{dde	fffd|dde	fffd}dde	fffd~dde	fffddde	fffd€dde	fffddde	fffd‚dde	fffdƒddeefffd„ddeefffd…ddeefffd†ddeefffd‡ddefffdˆddefffd‰ddefffdŠddefffd‹ddefffdŒddefffdddefffdŽddefffdddefffdddefffd‘d’defffd“d”defffd•d–defffd—d˜defffd™dšdefffd›dœdefffdddžeffffeZx eD ]\ZZeefežŽ  q2W ejjdŸkrld d¡lmZmZ ejjd¢krŠd d¡lmZmZ d£d¤„ Zd¥d¦„ Zd°d¨d©„Zdªd«„ Z d¬d­„ Z!d±d®d¯„Z"dS )²é    N)ÚboolopÚcmpopÚexcepthandlerÚexprÚexpr_contextÚoperator)ÚsliceÚstmtÚunaryopÚmodÚAST)Úiter_child_nodesÚwalk)Ú
TypeIgnorec               @   s   e Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__© r   r   ú-/tmp/pip-unpacked-wheel-m2hdu3mj/gast/gast.pyr   
   s   r   c                s2   ‡ ‡‡fdd„}t tjt ˆtˆ|d|iƒƒ d S )Nc                s¦   t |ƒt |ƒ }|dt ˆƒfks6td ˆ|t ˆƒ¡ƒ‚ˆ| _ˆ | _x$t| j|ƒD ]\}}t| ||ƒ qPW x8| ¡ D ],\}}|ˆks’td ˆ|¡ƒ‚t| ||ƒ qrW d S )Nr   z,Bad argument number for {}: {}, expecting {}z#Invalid Keyword argument for {}: {})ÚlenÚAssertionErrorÚformatÚ_fieldsÚ_attributesÚzipÚsetattrÚitems)ÚselfÚargsÚkwargsZnbparamÚargnameÚargval)Ú
AttributesÚFieldsÚNamer   r   Úcreate_node   s    
z_make_node.<locals>.create_nodeÚ__init__)r   Ú_sysÚmodulesr   Útype)r$   r#   r"   ZBasesr%   r   )r"   r#   r$   r   Ú
_make_node   s    
r*   ÚModule)ÚbodyZtype_ignoresr   ZInteractive)r,   Z
ExpressionÚFunctionType)ÚargtypesÚreturnsZSuiteÚFunctionDef)Únamer   r,   Údecorator_listr/   Útype_comment)ÚlinenoÚ
col_offsetÚ
end_linenoÚend_col_offsetZAsyncFunctionDefÚClassDef)r1   ÚbasesÚkeywordsr,   r2   ZReturn)ÚvalueZDelete)ÚtargetsZAssign)r<   r;   Z	AugAssign)ÚtargetÚopr;   Z	AnnAssign)r=   Ú
annotationr;   ÚsimpleZPrint)ÚdestÚvaluesÚnlZFor)r=   Úiterr,   Úorelser3   ZAsyncForZWhile)Útestr,   rE   ZIfZWith)r   r,   r3   Z	AsyncWithZRaise)ÚexcÚcauseZTry)r,   ÚhandlersrE   Z	finalbodyZAssert)rF   ÚmsgZImport)ÚnamesZ
ImportFrom)ÚmodulerK   ÚlevelZExec)r,   ÚglobalsÚlocalsZGlobalZNonlocalÚExprZPassZBreakÚContinueZBoolOp)r>   rB   ZBinOp)Úleftr>   ÚrightZUnaryOp)r>   ZoperandÚLambda)r   r,   ZIfExpÚDict)ÚkeysrB   ÚSet)ÚeltsZListComp)ÚeltÚ
generatorsZSetCompZDictComp)Úkeyr;   rZ   ZGeneratorExpZAwaitZYieldZ	YieldFromZCompare)rR   ÚopsZcomparatorsZCall)Úfuncr   r:   ÚReprZFormattedValue)r;   Ú
conversionÚformat_specZ	JoinedStr)rB   ÚConstant)r;   ÚkindÚ	Attribute)r;   ÚattrÚctxZ	Subscript)r;   r   re   ZStarred)r;   re   r$   )Úidre   r?   r3   ÚList)rX   re   ÚTupleÚLoadZStoreZDelZAugLoadZAugStoreZParamZSlice)ÚlowerÚupperÚstepÚAndÚOrZAddZSubZMultZMatMultZDivZModZPowZLShiftZRShiftZBitOrZBitXorZBitAndZFloorDivZInvertZNotZUAddZUSubZEqZNotEqZLtZLtEZGtZGtEZIsZIsNotZInZNotInZcomprehension)r=   rD   ZifsZis_asyncZExceptHandler)r)   r1   r,   Ú	arguments)r   ZposonlyargsÚvarargÚ
kwonlyargsÚkw_defaultsÚkwargÚdefaultsÚkeyword)Úargr;   Úalias)r1   ZasnameZwithitem)Zcontext_exprZoptional_varsZtype_ignore)r4   Útagé   é   )Úast_to_gastÚgast_to_asté   c              O   s   t tj| |ŽƒS )N)r{   Ú_astÚparse)r   r   r   r   r   r   +  s    r   c             C   s   t | tƒrt| ƒ} t | ¡S )N)Ú
isinstancer   r|   r~   Úliteral_eval)Znode_or_stringr   r   r   r   /  s    
r   Tc             C   sˆ   t | tttfƒs td| jj ƒ‚| jr„t | jd tƒr„t | jd j	t
ƒr„|rvdd l}| jd j	}| t||jd ƒ¡S | jd j	jS d S )Nz%r can't have docstringsr   )r€   r0   r8   r+   Ú	TypeErrorÚ	__class__r   r,   rP   r;   ra   ÚinspectÚcleandocÚgetattrr   Ús)ÚnodeÚcleanr„   Zholderr   r   r   Úget_docstring5  s    rŠ   c             C   sB   x<dD ]4}||j kr|| j krt||ƒrt| |t||ƒƒ qW | S )z°
    Copy source location (`lineno`, `col_offset`, `end_lineno`, and
    `end_col_offset` attributes) from *old_node* to *new_node* if possible,
    and return *new_node*.
    )r4   r5   r6   r7   )r   Úhasattrr   r†   )Znew_nodeZold_noderd   r   r   r   Úcopy_locationC  s
    

rŒ   c                s    ‡ fdd„‰ ˆ | ddddƒ | S )a{  
    When you compile a node tree with compile(), the compiler expects lineno
    and col_offset attributes for every node that supports them.  This is
    rather tedious to fill in for generated nodes, so this helper adds these
    attributes recursively where not already set, by setting them to the values
    of the parent node.  It works recursively starting at *node*.
    c                s®   d| j kr"t| dƒs|| _n| j}d| j krDt| dƒs>|| _n| j}d| j krft| dƒs`|| _n| j}d| j krˆt| dƒs‚|| _n| j}x t| ƒD ]}ˆ |||||ƒ q’W d S )Nr4   r6   r5   r7   )r   r‹   r4   r6   r5   r7   r   )rˆ   r4   r5   r6   r7   Úchild)Ú_fixr   r   rŽ   X  s$    







z#fix_missing_locations.<locals>._fixrz   r   r   )rˆ   r   )rŽ   r   Úfix_missing_locationsP  s    r   c             C   sV   xPt | ƒD ]D}d|jkr.t|ddƒp&d| |_d|jkr
t|ddƒpFd| |_q
W | S )z´
    Increment the line number and end line number of each node in the tree
    starting at *node* by *n*. This is useful to "move code" to a different
    location in a file.
    r4   r   r6   )r   r   r†   r4   r6   )rˆ   Únr   r   r   r   Úincrement_linenos  s    

r‘   )T)rz   )#Úsysr'   Úastr~   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   ÚImportErrorr*   Ú_nodesr1   ÚdescrÚversion_infoÚmajorZast2r{   r|   Zast3r   r   rŠ   rŒ   r   r‘   r   r   r   r   Ú<module>   sÒ   

#