U aG‘\ô ã@s4dZddlmZGdd„deƒZGdd„deƒZdS)zœ jinja2.visitor ~~~~~~~~~~~~~~ This module implements a visitor for the nodes. :copyright: (c) 2017 by the Jinja Team. :license: BSD. é)ÚNodec@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú NodeVisitoraWalks 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. cCsd|jj}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. Zvisit_N)Ú __class__Ú__name__Úgetattr)ÚselfÚnodeÚmethod©r ú0/usr/lib/python3/dist-packages/jinja2/visitor.pyÚ get_visitors zNodeVisitor.get_visitorcOs4| |¡}|dk r"||f|ž|ŽS|j|f|ž|ŽS)z Visit a node.N)r Ú generic_visit)rrÚargsÚkwargsÚfr r r Úvisit"s zNodeVisitor.visitcOs$| ¡D]}|j|f|ž|ŽqdS)z9Called if no explicit visitor function exists for a node.N)Ziter_child_nodesr)rrrrr r r r )s zNodeVisitor.generic_visitN)rÚ __module__Ú __qualname__Ú__doc__r rr r r r r rs rc@s eZdZdZdd„Zdd„ZdS)Ú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. c OsÀ| ¡D]²\}}t|tƒr~g}|D]L}t|tƒrd|j|f|ž|Ž}|dkrNq"nt|tƒsd| |¡q"| |¡q"||dd…<qt|tƒr|j|f|ž|Ž}|dkr®t||ƒqt|||ƒq|S)N) Z iter_fieldsÚ isinstanceÚlistrrÚextendÚappendÚdelattrÚsetattr) rrrrZfieldÚ old_valueZ new_valuesÚvalueZnew_noder r r r :s&       zNodeTransformer.generic_visitcOs&|j|f|ž|Ž}t|tƒs"|g}|S)z{As transformers may return lists in some places this method can be used to enforce a list as return value. )rrr)rrrrÚrvr r r Ú visit_listPs zNodeTransformer.visit_listN)rrrrr rr r r r r/s rN)rZ jinja2.nodesrÚobjectrrr r r r Ús !