B
    u9a1                 @   s   d dl T d ddZdd Zd!d
dZdd Zdd Zd"ddZdd Zdd Zd#ddZ	dd Z
G dd deZG dd deZdS )$    )*	<unknown>execc             C   s   t | ||tS )N)compileZPyCF_ONLY_AST)sourcefilenamemode r	   /usr/lib/python3.7/ast.pyparse   s    r   c                sR   t | trt| dd} t | tr&| j} dd fdd fdd  | S )	Neval)r   c             S   sH   t | tr$t | jtttfr4| jS nt | tr4| jS tdt	|  d S )Nzmalformed node or string: )

isinstanceConstantvalueintfloatcomplexNumn
ValueErrorrepr)noder	   r	   r
   _convert_num1   s    

z"literal_eval.<locals>._convert_numc                sD   t | tr<t | jttfr< | j}t | jtr6|
 S | S  | S )N)r   ZUnaryOpopZUAddZUSuboperand)r   r   )r   r	   r
   _convert_signed_num8   s    
z)literal_eval.<locals>._convert_signed_numc                s.  t | tr| jS t | ttfr$| jS t | tr4| jS t | trNt	t
 | jS t | trhtt
 | jS t | trtt
 | jS t | trttt
 | jt
 | jS t | tr| jS t | tr&t | jttfr&| j}| j}t |ttfr&t |tr&t | jtr|| S || S | S )N)r   r   r   StrZBytessr   r   ZTupletuplemapZeltsZListlistSetsetZDictdictzipkeysvaluesZNameConstantZBinOpr   ZAddZSubleftrightr   r   r   )r   r'   r(   )_convertr   r   r	   r
   r)   @   s2    








zliteral_eval.<locals>._convert)r   strr   Z
Expressionbody)Znode_or_stringr	   )r)   r   r   r
   literal_eval&   s    

r,   TFc                s2    fdd t | ts*td| jj  | S )Nc                s   t  trfddt D }d jjdr>dd |D ndd |D f }r jr||rfdphd7 }|d fd	d jD 7 }|d
 S t  trddfdd D  S t S )Nc                s   g | ]\}}| |fqS r	   r	   ).0ab)_formatr	   r
   
<listcomp>i   s    z)dump.<locals>._format.<locals>.<listcomp>z%s(%sz, c             s   s   | ]}d | V  qdS )z%s=%sNr	   )r-   fieldr	   r	   r
   	<genexpr>k   s    z(dump.<locals>._format.<locals>.<genexpr>c             s   s   | ]\}}|V  qd S )Nr	   )r-   r.   r/   r	   r	   r
   r3   m   s     c             3   s$   | ]}d | t |f V  qdS )z%s=%sN)getattr)r-   r.   )r0   r   r	   r
   r3   q   s   )z[%s]c             3   s   | ]} |V  qd S )Nr	   )r-   x)r0   r	   r
   r3   u   s    )	r   ASTiter_fields	__class____name__join_attributesr    r   )r   Zfieldsrv)r0   annotate_fieldsinclude_attributes)r   r
   r0   g   s    


zdump.<locals>._formatzexpected AST, got %r)r   r8   	TypeErrorr:   r;   )r   r?   r@   r	   )r0   r?   r@   r
   dump^   s    	
rB   c             C   sB   x<dD ]4}||j kr|| j krt||rt| |t|| qW | S )N)lineno
col_offset)r=   hasattrsetattrr5   )new_nodeZold_nodeattrr	   r	   r
   copy_location|   s
    

rI   c                s    fdd  | dd | S )Nc                sf   d| j kr"t| ds|| _n| j}d| j krDt| ds>|| _n| j}xt| D ]} ||| qNW d S )NrC   rD   )r=   rE   rC   rD   iter_child_nodes)r   rC   rD   child)_fixr	   r
   rL      s    



z#fix_missing_locations.<locals>._fix   r   r	   )r   r	   )rL   r
   fix_missing_locations   s    rN   rM   c             C   s2   x,t | D ] }d|jkr
t|dd| |_q
W | S )NrC   r   )walkr=   r5   rC   )r   r   rK   r	   r	   r
   increment_lineno   s    
rP   c          	   c   s>   x8| j D ].}y|t| |fV  W q tk
r4   Y qX qW d S )N)_fieldsr5   AttributeError)r   r2   r	   r	   r
   r9      s
    r9   c             c   sT   xNt | D ]B\}}t|tr$|V  q
t|tr
x|D ]}t|tr4|V  q4W q
W d S )N)r9   r   r8   r    )r   namer2   itemr	   r	   r
   rJ      s    



rJ   c             C   s   t | ttttfs"td| jj | jr8t | jd t	s<d S | jd j
} t | trZ| j}n"t | trxt | j
trx| j
}nd S |rdd l}||}|S )Nz%r can't have docstringsr   )r   ZAsyncFunctionDefZFunctionDefZClassDefZModulerA   r:   r;   r+   ZExprr   r   r   r   r*   inspectZcleandoc)r   ZcleantextrU   r	   r	   r
   get_docstring   s    	

rW   c             c   s@   ddl m} || g}x$|r:| } |t|  | V  qW d S )Nr   )deque)collectionsrX   popleftextendrJ   )r   rX   Ztodor	   r	   r
   rO      s    
rO   c               @   s   e Zd Zdd Zdd ZdS )NodeVisitorc             C   s"   d|j j }t| || j}||S )NZvisit_)r:   r;   r5   generic_visit)selfr   methodZvisitorr	   r	   r
   visit  s    zNodeVisitor.visitc             C   s\   xVt |D ]J\}}t|tr@x6|D ]}t|tr"| | q"W q
t|tr
| | q
W d S )N)r9   r   r    r8   r`   )r^   r   r2   r   rT   r	   r	   r
   r]     s    



zNodeVisitor.generic_visitN)r;   
__module____qualname__r`   r]   r	   r	   r	   r
   r\      s   r\   c               @   s   e Zd Zdd ZdS )NodeTransformerc             C   s   xt |D ]\}}t|tr|g }xL|D ]D}t|tr`| |}|d krJq&nt|ts`|| q&|| q&W ||d d < q
t|tr
| |}|d krt|| q
t||| q
W |S )N)	r9   r   r    r8   r`   r[   appenddelattrrF   )r^   r   r2   	old_valueZ
new_valuesr   rG   r	   r	   r
   r]   7  s&    







zNodeTransformer.generic_visitN)r;   ra   rb   r]   r	   r	   r	   r
   rc     s   $rc   N)r   r   )TF)rM   )T)_astr   r,   rB   rI   rN   rP   r9   rJ   rW   rO   objectr\   rc   r	   r	   r	   r
   <module>   s   
8


%