ó ,ņ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’’’’(tNodet NodeVisitorcBs)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.pyt get_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"s cOs.x'|jƒD]}|j|||Žq WdS(s9Called if no explicit visitor function exists for a node.N(titer_child_nodesR(RRR R ((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 Os x|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( t iter_fieldst isinstancetlistRRRtextendtappendtdelattrtsetattr( RRR R 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(RRR R trv((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyt visit_listPs (RRRR R!(((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyR/s  N(Rt jinja2.nodesRtobjectRR(((s2/usr/lib/python2.7/site-packages/jinja2/visitor.pyt s!