�
,��Qc@sFdZddlmZdefd��YZdefd��YZdS(s�
jinja2.visitor
~~~~~~~~~~~~~~
This module implements a visitor for the nodes.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD.
i����(tNodetNodeVisitorcBs)eZdZd�Zd�Zd�ZRS(sWalks 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.
cCs d|jj}t||d�S(s�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.
tvisit_N(t __class__t__name__tgetattrtNone(tselftnodetmethod((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pytget_visitorscOs>|j|�}|dk r+||||�S|j|||�S(s
Visit a node.N(R
Rt
generic_visit(RRtargstkwargstf((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pytvisit"scOs.x'|j�D]}|j|||�q
WdS(s9Called if no explicit visitor function exists for a node.N(titer_child_nodesR(RRRR
((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyR)s(Rt
__module__t__doc__R
RR(((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyRs
tNodeTransformercBs eZdZd�Zd�ZRS(s�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.
c Osx|j�D]�\}}t|t�r�g}xv|D]n}t|t�r�|j|||�}|dkrqq5q�t|t�s�|j|�q5q�n|j|�q5W||(q
t|t�r
|j|||�}|dkr�t||�qt |||�q
q
W|S(N(
titer_fieldst
isinstancetlistRRRtextendtappendtdelattrtsetattr( RRRR
tfieldt old_valuet
new_valuestvaluetnew_node((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyR:s&
cOs4|j|||�}t|t�s0|g}n|S(s{As transformers may return lists in some places this method
can be used to enforce a list as return value.
(RRR(RRRR
trv((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyt
visit_listPs(RRRRR!(((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyR/s N(Rtjinja2.nodesRtobjectRR(((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyt<module>
s! |