Vfb dZddlZddlmZej rddlZGddejZ GddZ Gd d e Z y) zVAPI for traversing the AST nodes. Implemented by the compiler and meta introspection. N)Nodec`eZdZdedej dej dej fdZy) VisitCallablenodeargskwargsreturncyN)selfrrr s 0/usr/lib/python3/dist-packages/jinja2/visitor.py__call__zVisitCallable.__call__ s N)__name__ __module__ __qualname__rtAnyrr rrrr s/  aee quu  rrceZdZdZdeddfdZdedejdejdejfdZdedejdejdejfd Z y ) 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. rr zt.Optional[VisitCallable]cHt|dt|jdS)zReturn 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. visit_N)getattrtyper)rrs r get_visitorzNodeVisitor.get_visitors% tvd4j&9&9%:;TBBrrr cl|j|}| ||g|i|S|j|g|i|S)z Visit a node.)r generic_visit)rrrr fs rvisitzNodeVisitor.visit#sI   T " =T+D+F+ +!t!!$8888rcZ|jD]}|j|g|i|y)z9Called if no explicit visitor function exists for a node.N)iter_child_nodesr!)rrrr child_nodes rrzNodeVisitor.generic_visit,s2//1 4J DJJz 3D 3F 3 4rN) rrr__doc__rrrrr!rr rrrrsx CC)DC9$9quu99!%%94$4quu44!%%4rrc eZdZdZdedej dej defdZdedej dej dejefdZ y) NodeTransformeraWalks 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. rrr r c|jD]\}}t|trkg}|D]^}t|tr;|j|g|i|}|,t|ts|j |N|j |`||ddt|ts|j|g|i|}| t||t||||Sr ) iter_fields isinstancelistrr!extendappenddelattrsetattr) rrrr field old_value new_valuesvaluenew_nodes rrzNodeTransformer.generic_visit=s $ 0 0 2 3 E9)T* &-E!%. * 5 B4 B6 B =$!+E4!8&--e4$%%e,- * ! It,%4::iA$A&A#D%(D%2% 3& rcX|j|g|i|}t|ts|gS|S)z{As transformers may return lists in some places this method can be used to enforce a list as return value. )r!r*r+)rrrr rvs r visit_listzNodeTransformer.visit_listSs4TZZ .t .v ."d#4K rN) rrrr%rrrrListr7r rrr'r'2sa$quu$, t AEE QUU qvvd| rr') r%typingrnodesr TYPE_CHECKINGtyping_extensionsteProtocolrrr'r rrr?sC??"  44D*k*r