B
    è¹`¾O  ã               @   sr  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lm	Z	 dd
lm
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lm Z  dd!l!m"Z" ed"ed#iZ#ed$ed%ed&ed'e
d(ed)ed*ed+ed,ed-ed.iZ$e	d/ed0ed1ed2ed3ed4ed5ed6ed7ed8i
Z%ed9ed:ed$e d%iZ&i Z'e' (e#¡ e' (e$¡ e' (e%¡ e' (e&¡ dHd=d>„Z)d?d@„ Z*G dAdB„ dBe+ƒZ,G dCdD„ dDe,ƒZ-G dEdF„ dFe,ƒZ.dGS )Iz§
    ast
    ~~~

    This is a stripped down version of Armin Ronacher's ast module.

    :copyright: Copyright 2008 by Armin Ronacher.
    :license: Python License.
é    )ÚAdd)ÚAnd)ÚAST)ÚBitAnd)ÚBitOr)ÚBitXor)ÚDiv)ÚEq)ÚFloorDiv)ÚGt)ÚGtE)ÚIf)ÚIn)ÚInvert)ÚIs)ÚIsNot)ÚLShift)ÚLt)ÚLtE)ÚMod)ÚMult)ÚName)ÚNot)ÚNotEq)ÚNotIn)ÚOr)ÚPyCF_ONLY_AST)ÚRShift)ÚSub)ÚUAdd)ÚUSub)Úarg_stringnameÚandÚorú+ú-Ú*ú/z//ú%z<<z>>ú|ú&ú^z==ú>z>=ÚinÚiszis notú<z<=z!=znot inú~Únotú	<unknown>Úexecc             C   s   t | ||tƒS )z%Parse an expression into an AST node.)Úcompiler   )ÚexprÚfilenameÚmode© r8   úV/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/mako/_ast_util.pyÚparseZ   s    r:   c          	   c   sR   t | dƒr| jsdS x8| jD ].}y|t| |ƒfV  W q tk
rH   Y qX qW dS )zAIterate over all fields of a node, only yielding existing fields.Ú_fieldsN)Úhasattrr;   ÚgetattrÚAttributeError)ÚnodeÚfieldr8   r8   r9   Úiter_fields_   s    rA   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚNodeVisitoraÖ  
    Walks the abstract syntax tree and call visitor functions for every node
    found.  The visitor functions may return values which will be forwarded
    by the `visit` method.

    Per default the visitor functions for the nodes are ``'visit_'`` +
    class name of the node.  So a `TryFinally` node visit function would
    be `visit_TryFinally`.  This behavior can be changed by overriding
    the `get_visitor` function.  If no visitor function exists for a node
    (return value `None`) the `generic_visit` visitor is used instead.

    Don't use the `NodeVisitor` if you want to apply changes to nodes during
    traversing.  For this a special visitor exists (`NodeTransformer`) that
    allows modifications.
    c             C   s   d|j j }t| |dƒS )z³
        Return the visitor function for this node or `None` if no visitor
        exists for this node.  In that case the generic visit function is
        used instead.
        Zvisit_N)Ú	__class__Ú__name__r=   )Úselfr?   Úmethodr8   r8   r9   Úget_visitor}   s    zNodeVisitor.get_visitorc             C   s$   |   |¡}|dk	r||ƒS |  |¡S )zVisit a node.N)rG   Úgeneric_visit)rE   r?   Úfr8   r8   r9   Ú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 )z9Called if no explicit visitor function exists for a node.N)rA   Ú
isinstanceÚlistr   rJ   )rE   r?   r@   ÚvalueÚitemr8   r8   r9   rH      s    



zNodeVisitor.generic_visitN)rD   Ú
__module__Ú__qualname__Ú__doc__rG   rJ   rH   r8   r8   r8   r9   rB   k   s   	rB   c               @   s   e Zd ZdZdd„ ZdS )ÚNodeTransformera  
    Walks the abstract syntax tree and allows modifications of nodes.

    The `NodeTransformer` will walk the AST and use the return value of the
    visitor functions to replace or remove the old node.  If the return
    value of the visitor function is `None` the node will be removed
    from the previous location otherwise it's replaced with the return
    value.  The return value may be the original node in which case no
    replacement takes place.

    Here an example transformer that rewrites all `foo` to `data['foo']`::

        class RewriteName(NodeTransformer):

            def visit_Name(self, node):
                return copy_location(Subscript(
                    value=Name(id='data', ctx=Load()),
                    slice=Index(value=Str(s=node.id)),
                    ctx=node.ctx
                ), node)

    Keep in mind that if the node you're operating on has child nodes
    you must either transform the child nodes yourself or call the generic
    visit function for the node first.

    Nodes that were part of a collection of statements (that applies to
    all statement nodes) may also return a list of nodes rather than just
    a single node.

    Usually you use the transformer like this::

        node = YourTransformer().visit(node)
    c             C   sÄ   x¾t |ƒD ]²\}}t||d ƒ}t|tƒrˆg }xL|D ]D}t|tƒrl|  |¡}|d krVq2nt|tƒsl| |¡ q2| |¡ q2W ||d d …< q
t|tƒr
|  |¡}|d kr°t||ƒ q
t	|||ƒ q
W |S )N)
rA   r=   rK   rL   r   rJ   ÚextendÚappendÚdelattrÚsetattr)rE   r?   r@   Ú	old_valueZ
new_valuesrM   Znew_noder8   r8   r9   rH   ¼   s(    







zNodeTransformer.generic_visitN)rD   rO   rP   rQ   rH   r8   r8   r8   r9   rR   ˜   s   "rR   c               @   s   e Zd ZdZdd„ Z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/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+e+dSdTƒZ,e+dUdVƒZ-[+dWdX„ Z.dYdZ„ Z/d[d\„ Z0d]d^„ Z1d_d`„ Z2dadb„ Z3dcdd„ Z4dedf„ Z5dgdh„ Z6didj„ Z7dkdl„ Z8dmdn„ Z9e9dSdTƒZ:e9dodpƒZ;e9dUdVƒZ<[9dqdr„ Z=dsdt„ Z>dudv„ Z?dwdx„ Z@dydz„ ZAd{d|„ ZBd}d~„ ZCdS )ÚSourceGeneratorz¶
    This visitor is able to transform a well formed syntax tree into python
    sourcecode.  For more details have a look at the docstring of the
    `node_to_source` function.
    c             C   s   g | _ || _d| _d| _d S )Nr   )ÚresultÚindent_withÚindentationÚ	new_lines)rE   rZ   r8   r8   r9   Ú__init__Ü   s    zSourceGenerator.__init__c             C   sH   | j r8| jr| j d| j  ¡ | j | j| j ¡ d| _ | j |¡ d S )NÚ
r   )r\   rY   rT   rZ   r[   )rE   Úxr8   r8   r9   Úwriteâ   s    zSourceGenerator.writeé   c             C   s   t | j|ƒ| _d S )N)Úmaxr\   )rE   Únr8   r8   r9   Únewlineê   s    zSourceGenerator.newlinec             C   s>   d| _ |  jd7  _x|D ]}|  |¡ qW |  jd8  _d S )NTra   )Únew_liner[   rJ   )rE   Z
statementsZstmtr8   r8   r9   Úbodyí   s
    
zSourceGenerator.bodyc             C   s4   |   |j ¡ |jr0|  ¡  |  d¡ |   |j¡ d S )Nzelse:)rf   Úorelserd   r`   )rE   r?   r8   r8   r9   Úbody_or_elseô   s
    
zSourceGenerator.body_or_elsec                sÄ   g ‰‡ ‡fdd„}d gt |jƒt |jƒ  }xJt|j||j ƒD ]4\}}|ƒ  ˆ  |¡ |d k	r@ˆ  d¡ ˆ  |¡ q@W |jd k	rœ|ƒ  ˆ  dt|jƒ ¡ |jd k	rÀ|ƒ  ˆ  dt|jƒ ¡ d S )Nc                  s   ˆrˆ   d¡ n
ˆ d¡ d S )Nz, T)r`   rT   r8   )rE   Ú
want_commar8   r9   Úwrite_commaþ   s    z.SourceGenerator.signature.<locals>.write_commaú=r&   z**)	ÚlenÚargsÚdefaultsÚziprJ   r`   Úvarargr!   Úkwarg)rE   r?   rj   ÚpaddingÚargÚdefaultr8   )rE   ri   r9   Ú	signatureû   s    



zSourceGenerator.signaturec             C   s0   x*|j D ] }|  ¡  |  d¡ |  |¡ qW d S )Nú@)Zdecorator_listrd   r`   rJ   )rE   r?   Ú	decoratorr8   r8   r9   Ú
decorators  s    
zSourceGenerator.decoratorsc             C   sR   |   ¡  x.t|jƒD ] \}}|r*|  d¡ |  |¡ qW |  d¡ |  |j¡ d S )Nz, z = )rd   Ú	enumerateÚtargetsr`   rJ   rM   )rE   r?   ÚidxÚtargetr8   r8   r9   Úvisit_Assign  s    

zSourceGenerator.visit_Assignc             C   s<   |   ¡  |  |j¡ |  tt|jƒ d ¡ |  |j¡ d S )Nrk   )rd   rJ   r|   r`   ÚBINOP_SYMBOLSÚtypeÚoprM   )rE   r?   r8   r8   r9   Úvisit_AugAssign#  s    zSourceGenerator.visit_AugAssignc             C   sV   |   ¡  |  dd|j |jf ¡ x.t|jƒD ] \}}|rD|  d¡ |  |¡ q.W d S )Nzfrom %s%s import Ú.z, )rd   r`   ÚlevelÚmodulery   Únames)rE   r?   r{   rN   r8   r8   r9   Úvisit_ImportFrom)  s    
z SourceGenerator.visit_ImportFromc             C   s0   |   ¡  x"|jD ]}|  d¡ |  |¡ qW d S )Nzimport )rd   r…   r`   rJ   )rE   r?   rN   r8   r8   r9   Úvisit_Import1  s    
zSourceGenerator.visit_Importc             C   s   |   ¡  |  |¡ d S )N)rd   rH   )rE   r?   r8   r8   r9   Ú
visit_Expr7  s    zSourceGenerator.visit_Exprc             C   sT   | j dd |  |¡ |   ¡  |  d|j ¡ |  |j¡ |  d¡ |  |j¡ d S )Né   )rc   zdef %s(z):)rd   rx   r`   Únameru   rm   rf   )rE   r?   r8   r8   r9   Úvisit_FunctionDef;  s    

z!SourceGenerator.visit_FunctionDefc                s  g ‰ ‡ ‡fdd„}ˆj dd ˆ |¡ ˆ  ¡  ˆ d|j ¡ x|jD ]}|ƒ  ˆ |¡ qHW t|dƒrìx0|jD ]&}|ƒ  ˆ |jd ¡ ˆ |j	¡ qrW t
|dd ƒrÄ|ƒ  ˆ d	¡ ˆ |j¡ t
|d
d ƒrì|ƒ  ˆ d¡ ˆ |j¡ ˆ ˆ rødpúd¡ ˆ |j¡ d S )Nc                  s(   ˆ rˆ  d¡ nˆ  d¡ ˆ  d¡ d S )Nz, Tú()r`   rT   r8   )Ú	have_argsrE   r8   r9   Úparen_or_commaG  s    
z6SourceGenerator.visit_ClassDef.<locals>.paren_or_commaé   )rc   zclass %sÚkeywordsrk   Ústarargsr&   Úkwargsz**z):ú:)rd   rx   r`   rŠ   ÚbasesrJ   r<   r   rs   rM   r=   r‘   r’   rf   )rE   r?   rŽ   ÚbaseÚkeywordr8   )r   rE   r9   Úvisit_ClassDefD  s0    



zSourceGenerator.visit_ClassDefc             C   sº   |   ¡  |  d¡ |  |j¡ |  d¡ |  |j¡ x€|j}t|ƒdkr”t|d tƒr”|d }|   ¡  |  d¡ |  |j¡ |  d¡ |  |j¡ q6|   ¡  |  d¡ |  |¡ P q6W d S )Nzif r“   ra   r   zelif zelse:)	rd   r`   rJ   Útestrf   rg   rl   rK   r   )rE   r?   Zelse_r8   r8   r9   Úvisit_Ifg  s$    





zSourceGenerator.visit_Ifc             C   sL   |   ¡  |  d¡ |  |j¡ |  d¡ |  |j¡ |  d¡ |  |¡ d S )Nzfor z in r“   )rd   r`   rJ   r|   Úiterrh   )rE   r?   r8   r8   r9   Ú	visit_For|  s    


zSourceGenerator.visit_Forc             C   s6   |   ¡  |  d¡ |  |j¡ |  d¡ |  |¡ d S )Nzwhile r“   )rd   r`   rJ   r˜   rh   )rE   r?   r8   r8   r9   Úvisit_While…  s
    

zSourceGenerator.visit_Whilec             C   sX   |   ¡  |  d¡ |  |j¡ |jd k	r>|  d¡ |  |j¡ |  d¡ |  |j¡ d S )Nzwith z as r“   )rd   r`   rJ   Zcontext_exprZoptional_varsrf   )rE   r?   r8   r8   r9   Ú
visit_WithŒ  s    



zSourceGenerator.visit_Withc             C   s   |   ¡  |  d¡ d S )NÚpass)rd   r`   )rE   r?   r8   r8   r9   Ú
visit_Pass–  s    zSourceGenerator.visit_Passc             C   sz   |   ¡  |  d¡ d}|jd k	r:|  d¡ |  |j¡ d}x*|jD ] }|rT|  d¡ |  |¡ d}qBW |jsv|  d¡ d S )Nzprint Fz >> Tz, ú,)rd   r`   ÚdestrJ   ÚvaluesÚnl)rE   r?   ri   rM   r8   r8   r9   Úvisit_Printš  s    




zSourceGenerator.visit_Printc             C   sD   |   ¡  |  d¡ x,t|ƒD ] \}}|r2|  d¡ |  |¡ qW d S )Nzdel z, )rd   r`   ry   rJ   )rE   r?   r{   r|   r8   r8   r9   Úvisit_Delete«  s    

zSourceGenerator.visit_Deletec             C   s<   |   ¡  |  d¡ |  |j¡ x|jD ]}|  |¡ q&W d S )Nztry:)rd   r`   rf   ÚhandlersrJ   )rE   r?   Úhandlerr8   r8   r9   Úvisit_TryExcept³  s
    
zSourceGenerator.visit_TryExceptc             C   s@   |   ¡  |  d¡ |  |j¡ |   ¡  |  d¡ |  |j¡ d S )Nztry:zfinally:)rd   r`   rf   Z	finalbody)rE   r?   r8   r8   r9   Úvisit_TryFinallyº  s    

z SourceGenerator.visit_TryFinallyc             C   s"   |   ¡  |  dd |j¡ ¡ d S )Nzglobal z, )rd   r`   Újoinr…   )rE   r?   r8   r8   r9   Úvisit_GlobalÂ  s    zSourceGenerator.visit_Globalc             C   s"   |   ¡  |  dd |j¡ ¡ d S )Nz	nonlocal z, )rd   r`   rª   r…   )rE   r?   r8   r8   r9   Úvisit_NonlocalÆ  s    zSourceGenerator.visit_Nonlocalc             C   s"   |   ¡  |  d¡ |  |j¡ d S )Nzreturn )rd   r`   rJ   rM   )rE   r?   r8   r8   r9   Úvisit_ReturnÊ  s    
zSourceGenerator.visit_Returnc             C   s   |   ¡  |  d¡ d S )NÚbreak)rd   r`   )rE   r?   r8   r8   r9   Úvisit_BreakÏ  s    zSourceGenerator.visit_Breakc             C   s   |   ¡  |  d¡ d S )NÚcontinue)rd   r`   )rE   r?   r8   r8   r9   Úvisit_ContinueÓ  s    zSourceGenerator.visit_Continuec             C   sÂ   |   ¡  |  d¡ t|dƒr^|jd k	r^|  d¡ |  |j¡ |jd k	r¾|  d¡ |  |j¡ n`t|dƒr¾|jd k	r¾|  |j¡ |jd k	rž|  d¡ |  |j¡ |jd k	r¾|  d¡ |  |j¡ d S )NÚraiseÚexcú z from r   z, )	rd   r`   r<   r³   rJ   Úcauser   ÚinstZtback)rE   r?   r8   r8   r9   Úvisit_Raise×  s     







zSourceGenerator.visit_Raisec             C   s    |   |j¡ |  d|j ¡ d S )Nr‚   )rJ   rM   r`   Úattr)rE   r?   r8   r8   r9   Úvisit_Attributeì  s    zSourceGenerator.visit_Attributec                sØ   g ‰‡ ‡fdd„}ˆ   |j¡ ˆ  d¡ x|jD ]}|ƒ  ˆ   |¡ q0W x0|jD ]&}|ƒ  ˆ  |jd ¡ ˆ   |j¡ qPW t|dd ƒr¢|ƒ  ˆ  d¡ ˆ   |j¡ t|dd ƒrÊ|ƒ  ˆ  d¡ ˆ   |j	¡ ˆ  d	¡ d S )
Nc                  s   ˆrˆ   d¡ n
ˆ d¡ d S )Nz, T)r`   rT   r8   )rE   ri   r8   r9   rj   ó  s    z/SourceGenerator.visit_Call.<locals>.write_commarŒ   rk   r‘   r&   r’   z**ú))
rJ   Úfuncr`   rm   r   rs   rM   r=   r‘   r’   )rE   r?   rj   rs   r–   r8   )rE   ri   r9   Ú
visit_Callð  s(    


zSourceGenerator.visit_Callc             C   s   |   |j¡ d S )N)r`   Úid)rE   r?   r8   r8   r9   Ú
visit_Name  s    zSourceGenerator.visit_Namec             C   s   |   t|jƒ¡ d S )N)r`   ÚstrrM   )rE   r?   r8   r8   r9   Úvisit_NameConstant  s    z"SourceGenerator.visit_NameConstantc             C   s   |   |j¡ d S )N)r`   rs   )rE   r?   r8   r8   r9   Ú	visit_arg  s    zSourceGenerator.visit_argc             C   s   |   t|jƒ¡ d S )N)r`   ÚreprÚs)rE   r?   r8   r8   r9   Ú	visit_Str  s    zSourceGenerator.visit_Strc             C   s   |   t|jƒ¡ d S )N)r`   rÂ   rÃ   )rE   r?   r8   r8   r9   Úvisit_Bytes  s    zSourceGenerator.visit_Bytesc             C   s   |   t|jƒ¡ d S )N)r`   rÂ   rc   )rE   r?   r8   r8   r9   Ú	visit_Num  s    zSourceGenerator.visit_Numc             C   s   |   t|jƒ¡ d S )N)r`   rÂ   rM   )rE   r?   r8   r8   r9   Úvisit_Constant  s    zSourceGenerator.visit_Constantc             C   sT   |   d¡ d}x.t|jƒD ] \}}|r0|   d¡ |  |¡ qW |   |rJdpLd¡ d S )NrŒ   éÿÿÿÿz, rº   z,))r`   ry   ÚeltsrJ   )rE   r?   r{   rN   r8   r8   r9   Úvisit_Tuple"  s    

zSourceGenerator.visit_Tuplec                s   ‡ ‡fdd„}|S )Nc                sH   |   ˆ ¡ x.t|jƒD ] \}}|r,|   d¡ |  |¡ qW |   ˆ¡ d S )Nz, )r`   ry   rÉ   rJ   )rE   r?   r{   rN   )ÚleftÚrightr8   r9   rJ   ,  s    

z-SourceGenerator.sequence_visit.<locals>.visitr8   )rË   rÌ   rJ   r8   )rË   rÌ   r9   Úsequence_visit+  s    zSourceGenerator.sequence_visitú[ú]Ú{Ú}c             C   sh   |   d¡ xNtt|j|jƒƒD ]8\}\}}|r8|   d¡ |  |¡ |   d¡ |  |¡ qW |   d¡ d S )NrÐ   z, z: rÑ   )r`   ry   ro   Úkeysr¢   rJ   )rE   r?   r{   ÚkeyrM   r8   r8   r9   Ú
visit_Dict:  s    
 


zSourceGenerator.visit_Dictc             C   sH   |   d¡ |  |j¡ |   dtt|jƒ  ¡ |  |j¡ |   d¡ d S )NrŒ   z %s rº   )r`   rJ   rË   r~   r   r€   rÌ   )rE   r?   r8   r8   r9   Úvisit_BinOpD  s
    
zSourceGenerator.visit_BinOpc             C   sV   |   d¡ x<t|jƒD ].\}}|r:|   dtt|jƒ  ¡ |  |¡ qW |   d¡ d S )NrŒ   z %s rº   )r`   ry   r¢   ÚBOOLOP_SYMBOLSr   r€   rJ   )rE   r?   r{   rM   r8   r8   r9   Úvisit_BoolOpK  s    
zSourceGenerator.visit_BoolOpc             C   s`   |   d¡ |  |j¡ x:t|j|jƒD ](\}}|   dtt|ƒ  ¡ |  |¡ q&W |   d¡ d S )NrŒ   z %s rº   )r`   rJ   rË   ro   ÚopsZcomparatorsÚCMPOP_SYMBOLSr   )rE   r?   r€   rÌ   r8   r8   r9   Úvisit_CompareS  s    
zSourceGenerator.visit_Comparec             C   sN   |   d¡ tt|jƒ }|   |¡ |dkr4|   d¡ |  |j¡ |   d¡ d S )NrŒ   r1   r´   rº   )r`   ÚUNARYOP_SYMBOLSr   r€   rJ   Zoperand)rE   r?   r€   r8   r8   r9   Úvisit_UnaryOp[  s    


zSourceGenerator.visit_UnaryOpc             C   s0   |   |j¡ |  d¡ |   |j¡ |  d¡ d S )NrÎ   rÏ   )rJ   rM   r`   Úslice)rE   r?   r8   r8   r9   Úvisit_Subscriptd  s    
zSourceGenerator.visit_Subscriptc             C   sr   |j d k	r|  |j ¡ |  d¡ |jd k	r6|  |j¡ |jd k	rn|  d¡ t|jtƒrb|jjdksn|  |j¡ d S )Nr“   ÚNone)ÚlowerrJ   r`   ÚupperÚsteprK   r   r½   )rE   r?   r8   r8   r9   Úvisit_Slicej  s    




zSourceGenerator.visit_Slicec             C   s0   x*|j D ] \}}|r|  d¡ |  |¡ qW d S )Nz, )Zdimsr`   rJ   )rE   r?   r{   rN   r8   r8   r9   Úvisit_ExtSliceu  s    
zSourceGenerator.visit_ExtSlicec             C   s   |   d¡ |  |j¡ d S )Nzyield )r`   rJ   rM   )rE   r?   r8   r8   r9   Úvisit_Yield{  s    
zSourceGenerator.visit_Yieldc             C   s0   |   d¡ |  |j¡ |   d¡ |  |j¡ d S )Nzlambda z: )r`   ru   rm   rJ   rf   )rE   r?   r8   r8   r9   Úvisit_Lambda  s    

zSourceGenerator.visit_Lambdac             C   s   |   d¡ d S )NÚEllipsis)r`   )rE   r?   r8   r8   r9   Úvisit_Ellipsis…  s    zSourceGenerator.visit_Ellipsisc                s   ‡ ‡fdd„}|S )Nc                s>   |   ˆ ¡ |  |j¡ x|jD ]}|  |¡ qW |   ˆ¡ d S )N)r`   rJ   ÚeltÚ
generators)rE   r?   Úcomprehension)rË   rÌ   r8   r9   rJ   ‰  s
    
z.SourceGenerator.generator_visit.<locals>.visitr8   )rË   rÌ   rJ   r8   )rË   rÌ   r9   Úgenerator_visitˆ  s    zSourceGenerator.generator_visitrŒ   rº   c             C   sT   |   d¡ |  |j¡ |   d¡ |  |j¡ x|jD ]}|  |¡ q4W |   d¡ d S )NrÐ   z: rÑ   )r`   rJ   rÓ   rM   rê   )rE   r?   rë   r8   r8   r9   Úvisit_DictComp—  s    

zSourceGenerator.visit_DictCompc             C   s<   |   |j¡ |  d¡ |   |j¡ |  d¡ |   |j¡ d S )Nz if z else )rJ   rf   r`   r˜   rg   )rE   r?   r8   r8   r9   Úvisit_IfExp   s
    

zSourceGenerator.visit_IfExpc             C   s   |   d¡ |  |j¡ d S )Nr&   )r`   rJ   rM   )rE   r?   r8   r8   r9   Úvisit_Starred§  s    
zSourceGenerator.visit_Starredc             C   s$   |   d¡ |  |j¡ |   d¡ d S )Nú`)r`   rJ   rM   )rE   r?   r8   r8   r9   Ú
visit_Repr«  s    
zSourceGenerator.visit_Reprc             C   s*   |   |j¡ |jd k	r&|   d|j ¡ d S )Nz as )r`   rŠ   Zasname)rE   r?   r8   r8   r9   Úvisit_alias³  s    
zSourceGenerator.visit_aliasc             C   sZ   |   d¡ |  |j¡ |   d¡ |  |j¡ |jrVx"|jD ]}|   d¡ |  |¡ q:W d S )Nz for z in z if )r`   rJ   r|   rš   Zifs)rE   r?   Zif_r8   r8   r9   Úvisit_comprehension¸  s    


z#SourceGenerator.visit_comprehensionc             C   sl   |   ¡  |  d¡ |jd k	rR|  d¡ |  |j¡ |jd k	rR|  d¡ |  |j¡ |  d¡ |  |j¡ d S )NÚexceptr´   z as r“   )rd   r`   r   rJ   rŠ   rf   )rE   r?   r8   r8   r9   Úvisit_excepthandlerÂ  s    





z#SourceGenerator.visit_excepthandlerN)ra   )DrD   rO   rP   rQ   r]   r`   rd   rf   rh   ru   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Í   Z
visit_ListZ	visit_SetrÔ   rÕ   r×   rÚ   rÜ   rÞ   rã   rä   rå   ræ   rè   rì   Zvisit_ListCompZvisit_GeneratorExpZvisit_SetComprí   rî   rï   rñ   rò   ró   rõ   r8   r8   r8   r9   rX   Ô   s†   
		#	
	


	



	
rX   N)r2   r3   )/rQ   Ú_astr   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    Zmako.compatr!   rÖ   r~   rÙ   rÛ   ZALL_SYMBOLSÚupdater:   rA   ÚobjectrB   rR   rX   r8   r8   r8   r9   Ú<module>   s‚   




-<