U a @sZdZddlZddlmZejr8ddlZGdddejZ GdddZ Gd d d e Z dS) zVAPI for traversing the AST nodes. Implemented by the compiler and meta introspection. N)Nodec@s&eZdZeejejejdddZdS) VisitCallablenodeargskwargsreturncOsdSNselfrrrr r OC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-8gbwd15f\jinja2\visitor.py__call__ szVisitCallable.__call__N)__name__ __module__ __qualname__rtAnyrr r r rr src@sTeZdZdZeddddZeejejejdddZeejejejdd d Z d S) 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. zt.Optional[VisitCallable])rr cCst|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. Zvisit_N)getattrtyper)r rr r r get_visitorszNodeVisitor.get_visitorrcOs4||}|dk r"||f||S|j|f||S)z Visit a node.N)r generic_visit)r rrrfr r rvisit#s zNodeVisitor.visitcOs$|D]}|j|f||qdS)z9Called if no explicit visitor function exists for a node.N)Ziter_child_nodesrr r r rr,s zNodeVisitor.generic_visitN) rrr__doc__rrrrrrr r r rrs  rc@sFeZdZdZeejejedddZeejejejedddZ dS)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. rc Os|D]\}}t|tr~g}|D]L}t|trd|j|f||}|dkrNq"nt|tsd||q"||q"||dd<qt|tr|j|f||}|dkrt||qt|||q|Sr ) iter_fields isinstancelistrrextendappenddelattrsetattr) r rrrfield old_valueZ new_valuesvalueZnew_noder r rr=s&       zNodeTransformer.generic_visitcOs&|j|f||}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. )rrr )r rrrrvr r r visit_listSs zNodeTransformer.visit_listN) rrrrrrrrListr)r r r rr2s r) rtypingrZnodesr TYPE_CHECKINGZtyping_extensionsteProtocolrrrr r r rs "