grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B h9!ò]Ë*ã@sˆdZddlTd!dd„Zdd„Zd"d d „Zd d„Zdd„Zd#dd„Zdd„Zdd„Z d$dd„Z dd„Z Gdd„de ƒZ Gdd„de ƒZd S)%aH ast ~~~ The `ast` module helps Python applications to process trees of the Python abstract syntax grammar. The abstract syntax itself might change with each Python release; this module helps to find out programmatically what the current grammar looks like and allows modifications of it. An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as a flag to the `compile()` builtin function or by using the `parse()` function from this module. The result will be a tree of objects whose classes all inherit from `ast.AST`. A modified abstract syntax tree can be compiled into a Python code object using the built-in `compile()` function. Additionally various helper functions are provided that make working with the trees simpler. The main intention of the helper functions and this module in general is to provide an easy to use interface for libraries that work tightly with the python syntax (template engines for example). :copyright: Copyright 2008 by Armin Ronacher. :license: Python License. é)Ú*ú ÚexeccCst|||tƒS)zn Parse the source into an AST node. Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). )ÚcompileZ PyCF_ONLY_AST)ÚsourceÚfilenameÚmode©r ú(/opt/alt/python37/lib64/python3.7/ast.pyÚparsesr csRt|tƒrt|dd�}t|tƒr&|j}dd„‰‡fdd„‰‡‡‡fdd„‰ˆ|ƒS) a Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. Úeval)rcSsHt|tƒr$t|jtttfƒr4|jSnt|tƒr4|jStdt |ƒƒ‚dS)Nzmalformed node or string: ) Ú isinstanceÚConstantÚvalueÚintÚfloatÚcomplexÚNumÚnÚ ValueErrorÚrepr)Únoder r r Ú _convert_num1s   z"literal_eval.._convert_numcsDt|tƒr._convert_signed_numcs.t|tƒr|jSt|ttfƒr$|jSt|tƒr4|jSt|tƒrNt t ˆ|j ƒƒSt|t ƒrht t ˆ|j ƒƒSt|tƒr‚tt ˆ|j ƒƒSt|tƒrªttt ˆ|jƒt ˆ|jƒƒƒSt|tƒrº|jSt|tƒ�r&t|jttfƒ�r&ˆ|jƒ}ˆ|jƒ}t|ttfƒ�r&t|tƒ�r&t|jtƒ�r||S||Sˆ|ƒS)N)r rrÚStrZBytesÚsrrZTupleÚtupleÚmapZeltsZListÚlistÚSetÚsetZDictÚdictÚzipÚkeysÚvaluesZ NameConstantZBinOprZAddZSubÚleftÚrightrrr)rr'r()Ú_convertrrr r r)@s2         zliteral_eval.._convert)r Ústrr Z ExpressionÚbody)Znode_or_stringr )r)rrr Ú literal_eval&s    r,TFcs2‡‡‡fdd„‰t|tƒs*td|jjƒ‚ˆ|ƒS)aÝ Return a formatted dump of the tree in node. This is mainly useful for debugging purposes. If annotate_fields is true (by default), the returned string will show the names and the values for fields. If annotate_fields is false, the result string will be more compact by omitting unambiguous field names. Attributes such as line numbers and column offsets are not dumped by default. If this is wanted, include_attributes can be set to true. c s t|tƒrÚg}ˆ}x`|jD]V}yt||ƒ}Wntk rDd}YqX|rb| d|ˆ|ƒf¡q| ˆ|ƒ¡qWˆrÄ|jrÄxD|jD]:}y | d|ˆt||ƒƒf¡Wq†tk r¾Yq†Xq†Wd|jjd  |¡fSt|t ƒ�rdd  ‡fdd„|Dƒ¡St |ƒS)NTz%s=%sz%s(%s)z, z[%s]c3s|]}ˆ|ƒVqdS)Nr )Ú.0Úx)Ú_formatr r ú ~sz(dump.._format..) r ÚASTÚ_fieldsÚgetattrÚAttributeErrorÚappendÚ _attributesÚ __class__Ú__name__Újoinr r)rÚargsÚkeywordsÚfieldrÚa)r/Úannotate_fieldsÚinclude_attributesr r r/hs*        zdump.._formatzexpected AST, got %r)r r1Ú TypeErrorr7r8)rr>r?r )r/r>r?r Údump^s  rAcCsBx||_n|j}xt|ƒD]}ˆ|||ƒqNWdS)NrBrC)r6rDrBrCÚiter_child_nodes)rrBrCÚchild)Ú_fixr r rK™s    z#fix_missing_locations.._fixérr )rr )rKr Úfix_missing_locations‘s rMrLcCs2x,t|ƒD] }d|jkr t|ddƒ||_q W|S)zœ Increment the line number of each node in the tree starting at *node* by *n*. This is useful to "move code" to a different location in a file. rBr)Úwalkr6r3rB)rrrJr r r Úincrement_linenoªs rOc cs>x8|jD].}y|t||ƒfVWqtk r4YqXqWdS)zs Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields`` that is present on *node*. N)r2r3r4)rr<r r r Ú iter_fieldsµs  rPccsTxNt|ƒD]B\}}t|tƒr$|Vq t|tƒr x|D]}t|tƒr4|Vq4Wq WdS)z‰ Yield all direct child nodes of *node*, that is, all fields that are nodes and all items of fields that are lists of nodes. N)rPr r1r )rÚnamer<Úitemr r r rIÁs    rIcCs–t|ttttfƒs"td|jjƒ‚|jr8t|jdt ƒss 8 '    %