grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a XC?hÀÛã@sôdZddlZddlTddlmZmZddlmZmZd`ddd œd d „Z d d „Z daddœdd„Z dd„Z dd„Z dbdd„Zdd„Zdd„Zdcdd„Zdd „Zd!d"„Zdd#œd$d%„Zd&d'„ZGd(d)„d)eƒZGd*d+„d+eƒZeed,ƒ�s d-d.„Zd/d0„Zeeeƒe_eeeƒe_Gd1d2„d2e ƒZ!d3d4„Z"Gd5d6„d6ee!d7�Z#Gd8d9„d9ee!d7�Z$Gd:d;„d;ee!d7�Z%Gdd?„d?ee!d7�Z'e#e(e)e*fe$e+fe%e,fe&e dƒe-fe'e d@ƒfiZ.e#e-fiZ/e-d=e dƒd=e(d6e)d6e*d6e+d9e,d;e d@ƒd?iZ0GdAdB„dBe1ƒZ2GdCdD„dDe2ƒZ3GdEdF„dFe2ƒZ4ee5dGƒ�sFdHdI„Z6dJdK„Z7ee6e7ƒe5_8GdLdM„dMe9ƒZ:GdNdO„dOe;ƒZdTe?ej@jAdƒZBGdUdV„dVeƒZCdWZDdXZEgeD¢eE¢RZFGdYdZ„dZeƒZGd[d\„ZHd]d^„ZIeJd_k�rðeIƒdS)daH 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. éN)Ú*)ÚcontextmanagerÚ nullcontext)ÚIntEnumÚautoú ÚexecF)Ú type_commentsÚfeature_versioncCsRt}|r|tO}t|tƒr4|\}}|dks.J‚|}n |dur@d}t|||||d�S)z½ Parse the source into an AST node. Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). Pass type_comments=True to get back type comments where the syntax allows. éNéÿÿÿÿ)Ú_feature_version)Z PyCF_ONLY_ASTZPyCF_TYPE_COMMENTSÚ isinstanceÚtupleÚcompile)ÚsourceÚfilenameÚmoder r ÚflagsÚmajorÚminor©rú(/opt/alt/python39/lib64/python3.9/ast.pyÚparse!s   ÿrcs`t|tƒrt|dd�}t|tƒr&|j}dd„‰‡fdd„‰‡fdd„‰‡‡‡‡fd d „‰ˆ|ƒS) aT Evaluate an expression node or a string containing only 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. Caution: A complex expression can overflow the C stack and cause a crash. Úeval©rcSstd|›�ƒ‚dS)Nzmalformed node or string: )Ú ValueError©ÚnoderrrÚ_raise_malformed_nodeCsz+literal_eval.._raise_malformed_nodecs,t|tƒrt|jƒtttfvr&ˆ|ƒ|jS©N)rÚConstantÚtypeÚvalueÚintÚfloatÚcomplexr)rrrÚ _convert_numEsz"literal_eval.._convert_numcsDt|tƒr._convert_signed_numcsZt|tƒr|jSt|tƒr*ttˆ|jƒƒSt|tƒrDttˆ|jƒƒSt|t ƒr^t tˆ|jƒƒSt|t ƒr¢t|j t ƒr¢|j jdkr¢|j|jkr˜gkr¢nnt ƒSt|tƒræt|jƒt|jƒkrȈ|ƒtttˆ|jƒtˆ|jƒƒƒSt|tƒ�rRt|jttfƒ�rRˆ|jƒ}ˆ|jƒ}t|ttfƒ�rRt|tƒ�rRt|jtƒ�rJ||S||Sˆ|ƒS)NÚset) rr!r#ÚTuplerÚmapÚeltsÚListÚlistÚSetr-ZCallÚfuncÚNameÚidÚargsÚkeywordsÚDictÚlenÚkeysÚvaluesÚdictÚzipZBinOpr(ÚAddÚSubÚleftÚrightr$r%r&)rrArB©Ú_convertr'r,rrrrDQs<     ÿÿÿ   ÿ  zliteral_eval.._convert)rÚstrrZ ExpressionÚbody)Znode_or_stringrrCrÚ literal_eval6s     rGT)ÚindentcsTd‡‡‡‡fdd„ ‰t|tƒs.td|jjƒ‚ˆdurHtˆtƒsHdˆ‰ˆ|ƒdS)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. If indent is a non-negative integer or string, then the tree will be pretty-printed with that indent level. None (the default) selects the single line representation. rc süˆdur*ˆd7‰dˆˆ}dˆˆ}nd}d}t|tƒ�r´t|ƒ}g}d}ˆ}|jD]„}zt||ƒ} Wnty„d}YqXYn0| dur¤t||dƒdur¤d}qXˆ| ˆƒ\} } |o¸| }|rÒ| d|| f¡qX| | ¡qXˆ�rh|j�rh|jD]t}zt||ƒ} Wnt�yYqòYn0| du�r§óz(dump.._format..)rÚASTr"Ú_fieldsÚgetattrÚAttributeErrorÚappendÚ _attributesr:Ú __class__Ú__name__Újoinr2Úrepr) rrQÚprefixÚsepÚclsr7Z allsimpler8Únamer#Úsimple©rPÚannotate_fieldsÚinclude_attributesrH)rQrrPzsX          &zdump.._formatzexpected AST, got %rNú )r)rrTÚ TypeErrorrZr[rE)rrdrerHrrcrÚdumpns 0 rhcCsVdD]L}||jvr||jvrt||dƒ}|dusDt||ƒr| d¡rt|||ƒq|S)z¬ Copy source location (`lineno`, `col_offset`, `end_lineno`, and `end_col_offset` attributes) from *old_node* to *new_node* if possible, and return *new_node*. )ÚlinenoÚ col_offsetÚ end_linenoÚend_col_offsetNZend_)rYrVÚhasattrÚ startswithÚsetattr)Únew_nodeZold_nodeÚattrr#rrrÚ copy_location±s ÿÿrrcs ‡fdd„‰ˆ|ddddƒ|S)a{ When you compile a node tree with compile(), the compiler expects lineno and col_offset attributes for every node that supports them. This is rather tedious to fill in for generated nodes, so this helper adds these attributes recursively where not already set, by setting them to the values of the parent node. It works recursively starting at *node*. cs¶d|jvr"t|dƒs||_n|j}d|jvrJt|ddƒdurD||_n|j}d|jvrlt|dƒsf||_n|j}d|jvr”t|ddƒdurŽ||_n|j}t|ƒD]}ˆ|||||ƒqœdS)Nrirkrjrl)rYrmrirVrkrjrlÚiter_child_nodes)rrirjrkrlÚchild©Ú_fixrrrvÊs$       z#fix_missing_locations.._fixrIrrrrrurÚfix_missing_locationsÂs rwrIcCsVt|ƒD]H}d|jvr(t|ddƒ||_d|jvrt|ddƒ}dur|||_q|S)z´ Increment the line number and end 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. rirrkN)ÚwalkrYrVrirk)rÚnrtrkrrrÚincrement_linenoås  ÿþ rzc cs8|jD],}z|t||ƒfVWqty0Yq0qdS)zs Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields`` that is present on *node*. N)rUrVrW)rÚfieldrrrÚ iter_fieldsös   r|ccsLt|ƒD]>\}}t|tƒr"|Vqt|tƒr|D]}t|tƒr0|Vq0qdS)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)r|rrTr2)rrar{Úitemrrrrss   rscCs–t|ttttfƒs"td|jjƒ‚|jr8t|jdt ƒs|jdus|jdurWdS|jd}|jd}|j}|j}WntyRYdS0t|ƒ}||kr||| ¡||… ¡S|ržt|| ¡d|… ¡ƒ}nd}||| ¡|d… ¡} || ¡d|… ¡} ||d|…}|  d| ¡|  | ¡d  |¡S)aBGet source code segment of the *source* that generated *node*. If some location information (`lineno`, `end_lineno`, `col_offset`, or `end_col_offset`) is missing, return None. If *padded* is `True`, the first line of a multi-line statement will be padded with spaces to match its original position. NrIrKr) rkrlrirjrWrŒÚencodeÚdecoderŽÚinsertrXr\) rrr�rirkrjrlrŠZpaddingÚfirstZlastrrrÚget_source_segmentNs*       r”ccs<ddlm}||gƒ}|r8| ¡}| t|ƒ¡|VqdS)zå Recursively yield all descendant nodes in the tree starting at *node* (including *node* itself), in no specified order. This is useful if you only want to modify nodes in place and don't care about the context. r)ÚdequeN)Ú collectionsr•ÚpopleftÚextendrs)rr•Ztodorrrrxss   rxc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú NodeVisitora< A node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the `visit` method. This class is meant to be subclassed, with the subclass adding visitor methods. 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 `visit` method. If no visitor function exists for a node (return value `None`) the `generic_visit` visitor is used instead. Don't use the `NodeVisitor` if you want to apply changes to nodes during traversing. For this a special visitor exists (`NodeTransformer`) that allows modifications. cCs"d|jj}t|||jƒ}||ƒS)z Visit a node.Úvisit_)rZr[rVÚ generic_visit)ÚselfrÚmethodÚvisitorrrrÚvisit•s zNodeVisitor.visitcCsTt|ƒD]F\}}t|tƒr:|D]}t|tƒr| |¡qqt|tƒr| |¡qdS)z9Called if no explicit visitor function exists for a node.N)r|rr2rTrŸ)rœrr{r#r}rrrr››s   zNodeVisitor.generic_visitc Cs |j}t t|ƒ¡}|dur@t ¡D]\}}t||ƒr$|}q@q$|dur–d|}zt||ƒ}WntypYn&0ddl}|  |›d�t d¡||ƒS|  |¡S)Nršrz" is deprecated; add visit_Constanté) r#Ú_const_node_type_namesÚgetr"ÚitemsrrVrWÚwarningsÚwarnÚDeprecationWarningr›) rœrr#Z type_namer`rar�ržr¤rrrÚvisit_Constant¥s&   ÿzNodeVisitor.visit_ConstantN)r[Ú __module__Ú __qualname__Ú__doc__rŸr›r§rrrrr™�s r™c@seZdZdZdd„ZdS)ÚNodeTransformeraC A :class:`NodeVisitor` subclass that walks the abstract syntax tree and allows modification of nodes. The `NodeTransformer` will walk the AST and use the return value of the visitor methods to replace or remove the old node. If the return value of the visitor method is ``None``, the node will be removed from its location, otherwise it is replaced with the return value. The return value may be the original node in which case no replacement takes place. Here is an example transformer that rewrites all occurrences of name lookups (``foo``) to ``data['foo']``:: class RewriteName(NodeTransformer): def visit_Name(self, node): return Subscript( value=Name(id='data', ctx=Load()), slice=Constant(value=node.id), ctx=node.ctx ) Keep in mind that if the node you're operating on has child nodes you must either transform the child nodes yourself or call the :meth:`generic_visit` method for the node first. For nodes that were part of a collection of statements (that applies to all statement nodes), the visitor may also return a list of nodes rather than just a single node. Usually you use the transformer like this:: node = YourTransformer().visit(node) cCs°t|ƒD]¢\}}t|tƒrvg}|D]D}t|tƒr\| |¡}|durFq"nt|tƒs\| |¡q"| |¡q"||dd…<qt|tƒr| |¡}|duržt||ƒqt|||ƒq|Sr ) r|rr2rTrŸr˜rXÚdelattrro)rœrr{Ú old_valueZ new_valuesr#rprrrr›ßs&         zNodeTransformer.generic_visitN)r[r¨r©rªr›rrrrr«»s#r«rycCs|jS)zDeprecated. Use value instead.©r#©rœrrrÚ_getterûsr°cCs ||_dSr r®©rœr#rrrÚ_setterÿsr²c@seZdZdd„Zdd„ZdS)Ú_ABCcGs d|_dS)Nz3Deprecated AST node class. Use ast.Constant instead)rª)r`r7rrrÚ__init__sz _ABC.__init__cCsdt|tƒsdS|tvrXz |j}Wnty4YdS0t|t|ƒoVt|t |d¡ƒ St ||¡S)NFr) rr!Ú _const_typesr#rWÚ_const_types_notr¢r"Ú__instancecheck__)r`Úinstr#rrrr· s   þz_ABC.__instancecheck__N)r[r¨r©r´r·rrrrr³sr³cOsp|D]<}||jvrq|j |¡}|t|ƒkrt|j›d|›�ƒ‚q|tvrXt|i|¤ŽStj|g|¢Ri|¤ŽS)Nz" got multiple values for argument )rUÚindexr:rgr[rµr!Ú__new__)r`r7ÚkwargsÚkeyÚposrrrÚ_news   r¾c@seZdZdZeZdS)ÚNum)ryN©r[r¨r©rUr¾rºrrrrr¿%sr¿)Ú metaclassc@seZdZdZeZdS)rƒ©r„NrÀrrrrrƒ)srƒc@seZdZdZeZdS)ÚBytesrÂNrÀrrrrrÃ-srÃc@seZdZeZdS)Ú NameConstantN)r[r¨r©r¾rºrrrrrÄ1srÄc@seZdZdZdd„ZdS)ÚEllipsisrcOs6|turtdg|¢Ri|¤ŽStj|g|¢Ri|¤ŽS)N.)rÅr!rº)r`r7r»rrrrº7szEllipsis.__new__N)r[r¨r©rUrºrrrrrÅ4srÅ.c@seZdZdZdS)ÚslicezDeprecated AST node class.N©r[r¨r©rªrrrrrÆRsrÆc@seZdZdZdd„ZdS)ÚIndexz@Deprecated AST node class. Use the index value directly instead.cKs|Sr r)r`r#r»rrrrºWsz Index.__new__N©r[r¨r©rªrºrrrrrÈUsrÈc@seZdZdZddd„ZdS)ÚExtSlicez1Deprecated AST node class. Use ast.Tuple instead.rcKstt|ƒtƒfi|¤ŽSr )r.r2ZLoad)r`Údimsr»rrrrº\szExtSlice.__new__N)rrÉrrrrrÊZsrÊrËcCs|jS)zDeprecated. Use elts instead.©r0r¯rrrÚ _dims_getterdsrÍcCs ||_dSr rÌr±rrrÚ _dims_setterhsrÎc@seZdZdZdS)ÚSuiteú/Deprecated AST node class. Unused in Python 3.NrÇrrrrrÏmsrÏc@seZdZdZdS)ÚAugLoadrÐNrÇrrrrrÑpsrÑc@seZdZdZdS)ÚAugStorerÐNrÇrrrrrÒssrÒc@seZdZdZdS)ÚParamrÐNrÇrrrrrÓvsrÓZ1ec@s‚eZdZdZeƒZeƒZeƒZeƒZeƒZ eƒZ eƒZ eƒZ e Z eƒZeƒZeƒZeƒZeƒZeƒZeƒZeƒZeƒZdd„ZdS)Ú _Precedencez5Precedence table that originated from python grammar.cCs,z| |d¡WSty&|YS0dS©NrI)rZrr¯rrrÚnext•s z_Precedence.nextN)r[r¨r©rªrÚTUPLEÚYIELDÚTESTÚORÚANDÚNOTÚCMPÚEXPRÚBORÚBXORÚBANDÚSHIFTÚARITHÚTERMÚFACTORÚPOWERÚAWAITÚATOMrÖrrrrrÔ~s(rÔ)ú'ú")z"""z'''csÈeZdZdZddœdd„Zdd„Zdd „Zd d „Zdàd d„Zdd„Z dd„Z e dd„ƒZ e ddœdd„ƒZe dd„ƒZdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Z‡fd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Zd;d<„Z d=d>„Z!d?d@„Z"dAdB„Z#dCdD„Z$dEdF„Z%dGdH„Z&dIdJ„Z'dKdL„Z(dMdN„Z)dOdP„Z*dQdR„Z+dSdT„Z,dUdV„Z-dWdX„Z.dYdZ„Z/d[d\„Z0d]d^„Z1d_d`„Z2dadb„Z3dcdd„Z4dedf„Z5dgdh„Z6didj„Z7dkdl„Z8dmdn„Z9dodp„Z:e;ddqœdrds„Zdydz„Z?d{d|„Z@d}d~„ZAdd€„ZBd�d‚„ZCdƒd„„ZDd…d†„ZEd‡dˆ„ZFd‰dŠ„ZGd‹dŒ„ZHd�dŽ„ZId�d�„ZJd‘d’„ZKd“d”„ZLd•d–„ZMd—d˜„ZNd™dš„ZOd›dœ„ZPd�dždŸd d¡œZQeRjSeRjTeRjTeRjTd¢œZUd£d¤„ZVdŸd d¥d¦d§d¨d©dªd«d¬d­d®d¯d°œ ZWeRjXeRjXeRjYeRjYeRjYeRjYeRjZeRjZeRj[eRj\eRj]eRjYeRj^d±œ Z_e`d²ƒZad³d´„Zbdµd¶d·d¸d¹dºd»d¼d½d¾d¿œ ZcdÀdÁ„ZddÂdÃdÄœZeeRjfeRjgdÅœZhdÆdÇ„ZidÈdÉ„ZjdÊdË„ZkdÌdÍ„ZldÎdÏ„ZmdÐdÑ„ZndÒdÓ„ZodÔdÕ„ZpdÖdׄZqdØdÙ„ZrdÚdÛ„ZsdÜdÝ„ZtdÞdß„Zu‡ZvS)áÚ _Unparserz�Methods in this class recursively traverse an AST and output source code for the abstract syntax; original formatting is disregarded.F©Ú_avoid_backslashescCs(g|_g|_i|_i|_d|_||_dS)Nr)Ú_sourceÚ_bufferÚ _precedencesÚ _type_ignoresÚ_indentrí)rœrírrrr´¥s z_Unparser.__init__cCsHt|ƒ}z|t|ƒƒWnty*Yn0|D]}|ƒ||ƒq0dS)z7Call f on each item in seq, calling inter() in between.N)ÚiterrÖÚ StopIteration)rœZinterÚfÚseqrOrrrÚ interleave­s z_Unparser.interleavecs>t|ƒdkr$||dƒˆ d¡nˆ ‡fdd„||¡dS)z§Traverse and separate the given *items* with a comma and append it to the buffer. If *items* is a single item sequence, a trailing comma will be added.rIrú,cs ˆ d¡S©NrL©Úwriterr¯rrÚÁrSz&_Unparser.items_view..N)r:rûr÷)rœZ traverserr£rr¯rÚ items_view¹s   z_Unparser.items_viewcCs|jr| d¡dS)z8Adds a newline if it isn't the start of generated sourcerJN)rîrûr¯rrrÚ maybe_newlineÃsz_Unparser.maybe_newlinerKcCs | ¡| d|j|¡dS)zXIndent a piece of text and append it, according to the current indentation levelz N)rþrûrò©rœr†rrrÚfillÈsz_Unparser.fillcCs|j |¡dS)zAppend a piece of textN)rîrXrÿrrrrûÎsz_Unparser.writecCs|j |¡dSr )rïrXrÿrrrÚ buffer_writerÒsz_Unparser.buffer_writercCsd |j¡}|j ¡|S)NrK)r\rïÚclearr±rrrÚbufferÕs  z_Unparser.bufferN©Úextraccs>| d¡|r| |¡|jd7_dV|jd8_dS)aA context manager for preparing the source for blocks. It adds the character':', increases the indentation on enter and decreases the indentation on exit. If *extra* is given, it will be directly appended after the colon character. ú:rIN)rûrò)rœrrrrÚblockÛs   z_Unparser.blockccs| |¡dV| |¡dS)z‡A context manager for preparing the source for expressions. It adds *start* to the buffer and enters, after exit it adds *end*.Nrú)rœÚstartÚendrrrÚdelimités z_Unparser.delimitcCs|r| ||¡StƒSdSr )r r)rœrr Ú conditionrrrÚ delimit_ifòs z_Unparser.delimit_ifcCs| dd| |¡|k¡S)z,Shortcut to adding precedence related parensú(ú))r Úget_precedence)rœÚ precedencerrrrÚrequire_parensøsz_Unparser.require_parenscCs|j |tj¡Sr )rðr¢rÔrÙ©rœrrrrrüsz_Unparser.get_precedencecGs|D]}||j|<qdSr )rð)rœrZnodesrrrrÚset_precedenceÿsz_Unparser.set_precedencecCs`t|ttttfƒr t|jƒdkr$dS|jd}t|tƒs| |¡}r.| |¡| |jdd…¡n | |j¡dSrÕ)rÚ_write_docstringrrF)rœrZ docstringrrrÚ"_write_docstring_and_traverse_body&s z,_Unparser._write_docstring_and_traverse_bodycCs*dd„|jDƒ|_| |¡|j ¡dS)NcSsi|]}|jd|j›�“qS)Úignore)riÚtag)rNrrrrÚ .sÿz*_Unparser.visit_Module..)Ú type_ignoresrñrrrrrrÚ visit_Module-s þ z_Unparser.visit_Modulecs`ˆ dd¡�*ˆ ‡fdd„ˆj|j¡Wdƒn1s<0Yˆ d¡ˆ |j¡dS)Nr rcs ˆ d¡Srùrúrr¯rrrü8rSz._Unparser.visit_FunctionType..ú -> )r r÷rÚargtypesrûÚreturnsrrr¯rÚvisit_FunctionType5s ÿ" z_Unparser.visit_FunctionTypecCs(| ¡| tj|j¡| |j¡dSr )rrrÔrØr#rrrrrÚ visit_Expr>sz_Unparser.visit_ExprcCsh| tj|¡�F| tj|j|j¡| |j¡| d¡| |j¡Wdƒn1sZ0YdS)Nz := ) rrÔr×rrèÚtargetr#rrûrrrrÚvisit_NamedExprCs   z_Unparser.visit_NamedExprcs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzimport cs ˆ d¡Srùrúrr¯rrrüLrSz(_Unparser.visit_Import..)rr÷rÚnamesrrr¯rÚ visit_ImportJs z_Unparser.visit_ImportcsTˆ d¡ˆ d|j¡|jr,ˆ |j¡ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzfrom Ú.z import cs ˆ d¡Srùrúrr¯rrrüTrSz,_Unparser.visit_ImportFrom..)rrûrQÚmoduler÷rr(rrr¯rÚvisit_ImportFromNs    z_Unparser.visit_ImportFromcCsP| ¡|jD]}| |¡| d¡q| |j¡| |¡}rL| |¡dS)Nú = )rÚtargetsrrûr#r)rœrr&rrrrÚ visit_AssignVs    z_Unparser.visit_AssigncCsB| ¡| |j¡| d|j|jjjd¡| |j¡dS)Nrfz= ) rrr&rûÚbinopr(rZr[r#rrrrÚvisit_AugAssign_s z_Unparser.visit_AugAssigncCsˆ| ¡| dd|j o"t|jtƒ¡�| |j¡Wdƒn1sH0Y| d¡| |j¡|j r„| d¡| |j ¡dS)Nr rú: r-) rr rbrr&r5rrûÚ annotationr#rrrrÚvisit_AnnAssignes *   z_Unparser.visit_AnnAssigncCs*| d¡|jr&| d¡| |j¡dS)NÚreturnrf)rr#rûrrrrrÚ visit_Returnos  z_Unparser.visit_ReturncCs| d¡dS)NÚpass©rrrrrÚ visit_Passusz_Unparser.visit_PasscCs| d¡dS)NÚbreakr8rrrrÚ visit_Breakxsz_Unparser.visit_BreakcCs| d¡dS)NÚcontinuer8rrrrÚvisit_Continue{sz_Unparser.visit_Continuecs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzdel cs ˆ d¡Srùrúrr¯rrrü€rSz(_Unparser.visit_Delete..)rr÷rr.rrr¯rÚ visit_Delete~s z_Unparser.visit_DeletecCs6| d¡| |j¡|jr2| d¡| |j¡dS)Nzassert rL)rrÚtestÚmsgrûrrrrÚ visit_Assert‚s    z_Unparser.visit_Assertcs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzglobal cs ˆ d¡Srùrúrr¯rrrü‹rSz(_Unparser.visit_Global..©rr÷rûr(rrr¯rÚ visit_Global‰s z_Unparser.visit_Globalcs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nz nonlocal cs ˆ d¡Srùrúrr¯rrrü�rSz*_Unparser.visit_Nonlocal..rBrrr¯rÚvisit_Nonlocal�s z_Unparser.visit_NonlocalcCsh| tj|¡�F| d¡|jrF| d¡| tj|j¡| |j¡Wdƒn1sZ0YdS)NÚawaitrf)rrÔrçrûr#rrèrrrrrÚ visit_Await‘s   z_Unparser.visit_AwaitcCsh| tj|¡�F| d¡|jrF| d¡| tj|j¡| |j¡Wdƒn1sZ0YdS)NÚyieldrf)rrÔrØrûr#rrèrrrrrÚ visit_Yield™s   z_Unparser.visit_YieldcCsf| tj|¡�D| d¡|js(tdƒ‚| tj|j¡| |j¡Wdƒn1sX0YdS)Nz yield from z-Node can't be used without a value attribute.) rrÔrØrûr#rrrèrrrrrÚvisit_YieldFrom¡s  z_Unparser.visit_YieldFromcCsX| d¡|js"|jrtdƒ‚dS| d¡| |j¡|jrT| d¡| |j¡dS)NÚraisez*Node can't use cause without an exception.rfz from )rÚexcÚcauserrûrrrrrÚ visit_Raise©s    z_Unparser.visit_RaisecCsà| d¡| ¡�| |j¡Wdƒn1s40Y|jD]}| |¡qD|jr˜| d¡| ¡�| |j¡Wdƒn1sŽ0Y|jrÜ| d¡| ¡�| |j¡Wdƒn1sÒ0YdS)NÚtryÚelseÚfinally)rrrrFÚhandlersÚorelseÚ finalbody)rœrZexrrrÚ visit_Tryµs  *    *  z_Unparser.visit_TrycCsz| d¡|jr&| d¡| |j¡|jrB| d¡| |j¡| ¡�| |j¡Wdƒn1sl0YdS)NÚexceptrfú as )rr"rûrrarrFrrrrÚvisit_ExceptHandlerÄs      z_Unparser.visit_ExceptHandlercCsþ| ¡|jD]}| d¡| |¡q| d|j¡|jdd|jpJ|jd��hd}|jD]"}|rp| d¡nd}| |¡q\|jD]"}|rš| d¡nd}| |¡q†Wdƒn1s¾0Y|  ¡�|  |¡Wdƒn1sð0YdS) Nú@zclass r r)r FrLT) rþÚdecorator_listrrrar Úbasesr8rûrr)rœrÚdecoÚcommaÚerrrÚvisit_ClassDefÏs&        * z_Unparser.visit_ClassDefcCs| |d¡dS)NÚdef©Ú_function_helperrrrrÚvisit_FunctionDefçsz_Unparser.visit_FunctionDefcCs| |d¡dS)Nz async defr`rrrrÚvisit_AsyncFunctionDefêsz _Unparser.visit_AsyncFunctionDefcCsÔ| ¡|jD]}| d¡| |¡q|d|j}| |¡| dd¡�| |j¡Wdƒn1sn0Y|jr”| d¡| |j¡|j |  |¡d��|  |¡Wdƒn1sÆ0YdS)NrXrfr rr!r) rþrYrrrar r7r#rûrrr)rœrZ fill_suffixr[Zdef_strrrrraís    *  z_Unparser._function_helpercCs| d|¡dS)Nzfor ©Ú _for_helperrrrrÚ visit_Forüsz_Unparser.visit_ForcCs| d|¡dS)Nz async for rdrrrrÚvisit_AsyncForÿsz_Unparser.visit_AsyncForcCs²| |¡| |j¡| d¡| |j¡|j| |¡d��| |j¡Wdƒn1s`0Y|jr®| d¡| ¡�| |j¡Wdƒn1s¤0YdS)Nú in rrO) rrr&rûrórrrFrR)rœrrrrrres    *  z_Unparser._for_helpercCs| d¡| |j¡| ¡�| |j¡Wdƒn1s@0Y|jrÄt|jƒdkrÄt|jdtƒrÄ|jd}| d¡| |j¡| ¡�| |j¡WdƒqJ1s¸0YqJ|j�r | d¡| ¡�| |j¡Wdƒn1�s0YdS)Nzif rIrzelif rO) rrr?rrFrRr:rZIfrrrrÚvisit_Ifs   *$    ,  z_Unparser.visit_IfcCs’| d¡| |j¡| ¡�| |j¡Wdƒn1s@0Y|jrŽ| d¡| ¡�| |j¡Wdƒn1s„0YdS)Nzwhile rO)rrr?rrFrRrrrrÚ visit_While s   *  z_Unparser.visit_Whilecsfˆ d¡ˆ ‡fdd„ˆj|j¡ˆjˆ |¡d��ˆ |j¡Wdƒn1sX0YdS)Nzwith cs ˆ d¡Srùrúrr¯rrrü,rSz&_Unparser.visit_With..r©rr÷rr£rrrFrrr¯rÚ visit_With*s z_Unparser.visit_Withcsfˆ d¡ˆ ‡fdd„ˆj|j¡ˆjˆ |¡d��ˆ |j¡Wdƒn1sX0YdS)Nz async with cs ˆ d¡Srùrúrr¯rrrü2rSz+_Unparser.visit_AsyncWith..rrkrrr¯rÚvisit_AsyncWith0s z_Unparser.visit_AsyncWith©Ú quote_typesÚescape_special_whitespacecsâ‡fdd„}d t|ˆƒ¡‰|}dˆvr6dd„|Dƒ}‡fdd„|Dƒ}|s‚tˆƒ‰t‡fdd „|Dƒˆd ƒ}ˆd d …|gfSˆrÚ|j‡fd d„d�|d d ˆd krÚt|d ƒdksÂJ‚ˆdd …dˆd ‰ˆ|fS)z‹Helper for writing string literals, minimizing escapes. Returns the tuple (string literal to write, possible quote types). cs4ˆs|dvr|S|dks | ¡s0| d¡ d¡S|S)Nz ú\Zunicode_escapeÚascii)Ú isprintabler�r‘)r‹)rprrÚ escape_char<s  z2_Unparser._str_literal_helper..escape_charrKrJcSsg|]}|tvr|‘qSr)Ú _MULTI_QUOTES©rNÚqrrrÚ IrSz1_Unparser._str_literal_helper..csg|]}|ˆvr|‘qSrrrv©Úescaped_stringrrrxJrSc3s|]}ˆd|vr|VqdSrMrrv)ÚstringrrrRPrSz0_Unparser._str_literal_helper..rrIr cs|dˆdkS)Nrr r)rwryrrrüTrSz/_Unparser._str_literal_helper..)r¼r Nrq)r\r/r]rÖÚsortr:)rœr{rorprtZpossible_quotesZquoter)rprzr{rÚ_str_literal_helper6s  z_Unparser._str_literal_helper©rocCs4|j||d�\}}|d}| |›|›|›�¡dS)zKWrite string literal value with a best effort attempt to avoid backslashes.r~rN)r}rû)rœr{roÚ quote_typerrrÚ_write_str_avoiding_backslashes\sz)_Unparser._write_str_avoiding_backslashesc CsÔ| d¡|jr.| ||j¡| |j¡dSg}|jD]:}t|dt|ƒj ƒ}|||jƒ|  |jt |t ƒf¡q8g}t }|D]&\}}|j|||d�\}}|  |¡q€d |¡}|d}| |›|›|›�¡dS)NrõÚ _fstring_rnrKr)rûríÚ_fstring_JoinedStrrr€rr<rVr"r[rXrr!Ú _ALL_QUOTESr}r\) rœrrr#ÚmethZ new_bufferroZ is_constantrrrrÚvisit_JoinedStrbs*     þ   z_Unparser.visit_JoinedStrcCs(| d¡| ||j¡| |j¡dS)Nrõ)rûÚ_fstring_FormattedValuerr€rrrrrÚvisit_FormattedValue�s z_Unparser.visit_FormattedValuecCs.|jD]"}t|dt|ƒjƒ}|||ƒqdS)Nr�)r<rVr"r[)rœrrûr#r„rrrr‚†s z_Unparser._fstring_JoinedStrcCs6t|jtƒstdƒ‚|j dd¡ dd¡}||ƒdS)Nz.Constants inside JoinedStr should be a string.Ú{z{{Ú}z}})rr#rErÚreplace)rœrrûr#rrrÚ_fstring_Constant‹s z_Unparser._fstring_ConstantcCsÎ|dƒt|ƒdd�}| tj ¡|j¡| |j¡}| d¡rH|dƒd|vrXtdƒ‚||ƒ|j dkr’t |j ƒ}|dvr„td ƒ‚|d |›�ƒ|j rÂ|d ƒt |d t|j ƒj ƒ}||j |ƒ|d ƒdS)NrˆTrìrfrqz5Unable to avoid backslash in f-string expression partr ZsrazUnknown f-string conversion.ú!rr�r‰)r"rrÔrÙrÖr#rŸrnrÚ conversionÚchrÚ format_specrVr[)rœrrûÚunparserÚexprr�r„rrrr†‘s&     z!_Unparser._fstring_FormattedValuecCs| |j¡dSr )rûr6rrrrÚ visit_Name¦sz_Unparser.visit_NamecCs0| ¡|jdkr| d¡|j|jtd�dS)NÚur~)rÚkindrûr€r#rurrrrr©s  z_Unparser._write_docstringc Csjt|ttfƒr<| t|ƒ dt¡ ddt›dt›d�¡¡n*|jrXt|tƒrX|  |¡n| t|ƒ¡dS)NÚinfÚnanr ú-r) rr%r&rûr]rŠÚ_INFSTRrírEr€r±rrrÚ_write_constant¯sÿþÿ z_Unparser._write_constantcCs„|j}t|tƒrL| dd¡�| |j|¡Wdƒq€1s@0Yn4|dur`| d¡n |jdkrt| d¡| |j¡dS)Nr r.ú...r“)r#rrr rýr™rûr”)rœrr#rrrr§½s .   z_Unparser.visit_ConstantcsJˆ dd¡�*ˆ ‡fdd„ˆj|j¡Wdƒn1s<0YdS)Nú[ú]cs ˆ d¡Srùrúrr¯rrrüËrSz&_Unparser.visit_List..)r r÷rr0rrr¯rÚ visit_ListÉsz_Unparser.visit_ListcCsR| dd¡�2| |j¡|jD]}| |¡q Wdƒn1sD0YdS)Nr›rœ©r rÚeltÚ generators©rœrÚgenrrrÚvisit_ListCompÍs  z_Unparser.visit_ListCompcCsR| dd¡�2| |j¡|jD]}| |¡q Wdƒn1sD0YdS©Nr rržr¡rrrÚvisit_GeneratorExpÓs  z_Unparser.visit_GeneratorExpcCsR| dd¡�2| |j¡|jD]}| |¡q Wdƒn1sD0YdS)Nrˆr‰ržr¡rrrÚ visit_SetCompÙs  z_Unparser.visit_SetCompcCsh| dd¡�H| |j¡| d¡| |j¡|jD]}| |¡q6Wdƒn1sZ0YdS)Nrˆr‰r2)r rr¼rûr#r r¡rrrÚvisit_DictCompßs     z_Unparser.visit_DictCompcCs�|jr| d¡n | d¡| tj|j¡| |j¡| d¡|jtj ¡|j g|j ¢RŽ| |j ¡|j D]}| d¡| |¡qrdS)Nz async for z for rhú if ) Úis_asyncrûrrÔr×r&rrÙrÖróÚifs)rœrZ if_clauserrrÚvisit_comprehensionçs       z_Unparser.visit_comprehensioncCs’| tj|¡�p| tj ¡|j|j¡| |j¡| d¡| |j¡| d¡| tj|j ¡| |j ¡Wdƒn1s„0YdS)Nr¨z else ) rrÔrÙrrÖrFr?rrûrRrrrrÚ visit_IfExpõs    z_Unparser.visit_IfExpcs\|jrNˆ dd¡�*ˆ ‡fdd„ˆj|j¡WdƒqX1sB0Yn ˆ d¡dS)Nrˆr‰cs ˆ d¡Srùrúrr¯rrrürSz%_Unparser.visit_Set..z{*()})r0r r÷rrûrrr¯rÚ visit_Setÿs:z_Unparser.visit_Setcsj‡fdd„‰‡‡fdd„}ˆ dd¡�0ˆ ‡fdd„|t|j|jƒ¡Wdƒn1s\0YdS) Ncs"ˆ |¡ˆ d¡ˆ |¡dS©Nr2)rrû)ÚkÚvr¯rrÚwrite_key_value_pair s  z2_Unparser.visit_Dict..write_key_value_paircsB|\}}|dur4ˆ d¡ˆ tj|¡ˆ |¡n ˆ||ƒdS)Nú**)rûrrÔrÞr)r}r¯r°©rœr±rrÚ write_items   z(_Unparser.visit_Dict..write_itemrˆr‰cs ˆ d¡Srùrúrr¯rrrürSz&_Unparser.visit_Dict..)r r÷r>r;r<)rœrr´rr³rÚ visit_Dicts   ÿz_Unparser.visit_DictcCs@| dd¡� | |j|j¡Wdƒn1s20YdSr¤)r rýrr0rrrrÚ visit_Tuplesz_Unparser.visit_Tupleú~Únotú+r—)ZInvertZNotr)r*)r¸r·r¹r—cCs‚|j|jjj}|j|}| ||¡�H| |¡|tjurF| d¡|  ||j ¡|  |j ¡Wdƒn1st0YdS©Nrf) Úunopr(rZr[Úunop_precedencerrûrÔrårr+r)rœrÚoperatorÚoperator_precedencerrrÚ visit_UnaryOp*s    z_Unparser.visit_UnaryOprrXú/ú%ú<<ú>>ú|ú^ú&ú//r²) r?r@ZMultZMatMultZDivZModZLShiftZRShiftZBitOrZBitXorZBitAndZFloorDivZPow) r¹r—rrXrÀrÁrÂrÃrÄrÅrÆrÇr²)r²cCs´|j|jjj}|j|}| ||¡�z||jvr@| ¡}|}n |}| ¡}| ||j ¡|  |j ¡|  d|›d�¡| ||j ¡|  |j ¡Wdƒn1s¦0YdSrº) r0r(rZr[Úbinop_precedencerÚ binop_rassocrÖrrArrûrB)rœrr½r¾Zleft_precedenceZright_precedencerrrÚ visit_BinOpWs   z_Unparser.visit_BinOpz==z!=úz>=Úiszis notÚinznot in) ZEqZNotEqZLtZLtEZGtZGtEZIsZIsNotZInZNotIncCsš| tj|¡�x|jtj ¡|jg|j¢RŽ| |j¡t|j |jƒD].\}}|  d|j |j j d¡| |¡qHWdƒn1sŒ0YdSrº)rrÔrÝrrÖrAÚ comparatorsrr>ÚopsrûÚcmpopsrZr[)rœrÚor]rrrÚ visit_Compareus  z_Unparser.visit_CompareÚandÚor)ZAndZOr)rÔrÕcs~ˆj|jjj}ˆj|‰‡‡fdd„}ˆ ˆ|¡�6d|›d�‰ˆ ‡‡fdd„||j¡Wdƒn1sp0YdS)Ncs"ˆ ¡‰ˆ ˆ|¡ˆ |¡dSr )rÖrrr)r¾rœrrÚincreasing_level_traverse„s z9_Unparser.visit_BoolOp..increasing_level_traverserfcs ˆ ˆ¡Sr rúr)r„rœrrrüŒrSz(_Unparser.visit_BoolOp..)Úboolopsr(rZr[Úboolop_precedencerr÷r<)rœrr½rÖr)r¾r„rœrÚ visit_BoolOp€s   z_Unparser.visit_BoolOpcCsZ| tj|j¡| |j¡t|jtƒr@t|jjtƒr@| d¡| d¡| |j ¡dS)Nrfr*) rrÔrèr#rrr!r$rûrqrrrrÚvisit_AttributeŽs    z_Unparser.visit_AttributecCs¤| tj|j¡| |j¡| dd¡�hd}|jD]"}|rH| d¡nd}| |¡q4|jD]"}|rr| d¡nd}| |¡q^Wdƒn1s–0YdS)Nr rFrLT) rrÔrèr4rr r7rûr8)rœrr\r]rrrÚ visit_Call™s      z_Unparser.visit_CallcCs~dd„}| tj|j¡| |j¡| dd¡�:||jƒrP| |j|jj¡n | |j¡Wdƒn1sp0YdS)NcSs&t|tƒo$|jo$tdd„|jDƒƒ S)Ncss|]}t|tƒVqdSr )rZStarred)rNrŸrrrrR³rSzE_Unparser.visit_Subscript..is_simple_tuple..)rr.r0Úany)Z slice_valuerrrÚis_simple_tuple¬s  ÿýz2_Unparser.visit_Subscript..is_simple_tupler›rœ) rrÔrèr#rr rÆrýr0)rœrrÝrrrÚvisit_Subscript«s   z_Unparser.visit_SubscriptcCs*| d¡| tj|j¡| |j¡dS)Nr)rûrrÔrÞr#rrrrrÚ visit_Starred¾s z_Unparser.visit_StarredcCs| d¡dS)NršrúrrrrÚvisit_EllipsisÃsz_Unparser.visit_EllipsiscCsN|jr| |j¡| d¡|jr.| |j¡|jrJ| d¡| |j¡dS)Nr)ÚlowerrrûÚupperÚsteprrrrÚ visit_SliceÆs    z_Unparser.visit_SlicecCs,| |j¡|jr(| d¡| |j¡dSr®)rûÚargr3rrrrrÚ visit_argÐs  z_Unparser.visit_argc Cs¢d}|j|j}dgt|ƒt|jƒ|j}tt||ƒdƒD]^\}}|\}}|rXd}n | d¡| |¡|r„| d¡| |¡|t|jƒkr>| d¡q>|jsª|j rü|r´d}n | d¡| d¡|jrü| |jj ¡|jj rü| d¡| |jj ¡|j �rLt|j |j ƒD]8\}}| d¡| |¡|�r| d¡| |¡�q|j �rž|�r`d}n | d¡| d |j j ¡|j j �rž| d¡| |j j ¡dS) NTrIFrLú=z, /rr2r²)Ú posonlyargsr7r:ÚdefaultsÚ enumerater>rûrÚvarargÚ kwonlyargsrår3Ú kw_defaultsÚkwarg) rœrr“Zall_argsrér¹ÚelementsÚaÚdrrrÚvisit_argumentsÖsN                z_Unparser.visit_argumentscCs<|jdur| d¡n| |j¡| d¡| |j¡dS)Nr²rç)rårûrr#rrrrÚ visit_keyword s     z_Unparser.visit_keywordcCsn| tj|¡�L| d¡| |j¡| d¡| tj|j¡| |j¡Wdƒn1s`0YdS)Nzlambda r2)rrÔrÙrûrr7rrFrrrrÚ visit_Lambdas    z_Unparser.visit_LambdacCs&| |j¡|jr"| d|j¡dS©NrV)rûraÚasnamerrrrÚ visit_aliass z_Unparser.visit_aliascCs,| |j¡|jr(| d¡| |j¡dSrõ)rÚ context_exprÚ optional_varsrûrrrrÚvisit_withitems  z_Unparser.visit_withitem)rK)wr[r¨r©rªr´r÷rýrþrrûrÚpropertyrrrr r rrrrrrrŸrr r$r%r'r)r,r/r1r4r6r9r;r=r>rArCrDrFrHrIrMrTrWr^rbrcrarfrgrerirjrlrmrƒr}r€r…r‡r‚r‹r†r’rr™r§r�r£r¥r¦r§r«r¬r­rµr¶r»rÔrÜrår¼r¿r0rãrärârßràrárærÈÚ frozensetrÉrÊrÑrÓr×rÛrÚrØrÙrÚrÛrÞrßràräræròrórôr÷rúÚ __classcell__rrrrrë s              ÿ &   ü óóö    3rëcCstƒ}| |¡Sr )rërŸ)Zast_objr�rrrÚunparse$srþcCsäddl}|jdd�}|jd|jdd�ddd d �|jd d d ddd�|jddddd�|jddddd�|jddtddd�| ¡}|j�}| ¡}Wdƒn1s¨0Yt||jj |j |j d �}t t ||j|jd!�ƒdS)"Nrz python -m ast)ÚprogÚinfileÚrbrú?r—z$the file to parse; defaults to stdin)r"ÚnargsÚdefaultÚhelpz-mz--moder)rZsinglerZ func_typez(specify what kind of code must be parsed)rÚchoicesrz--no-type-commentsTZ store_falsez)don't add information about type comments)rÚactionrz-az--include-attributesÚ store_truez:include attributes such as line numbers and column offsets)rrz-iz--indentr z'indentation of nodes (number of spaces))r"rr)r )rerH)ÚargparseÚArgumentParserÚ add_argumentZFileTyper$Ú parse_argsrÚreadrrarZno_type_commentsÚprintrhrerH)r Úparserr7rrZtreerrrÚmain)s0 þ þ ÿ ÿ ÿ&rÚ__main__)rr)TF)rI)T)KrªÚsysZ_astÚ contextlibrrÚenumrrrrGrhrrrwrzr|rsr‡rŒrŽr”rxÚobjectr™r«rmr!r°r²rûryr„r"r³r¾r¿rƒrÃrÄrÅr$r%r&rEÚbytesÚboolrµr¶r¡rTrÆrÈrÊr.rÍrÎrËÚmodrÏZ expr_contextrÑrÒrÓr]Ú float_infoÚ max_10_expr˜rÔZ_SINGLE_QUOTESrurƒrërþrr[rrrrÚsœÿ 8C#    %:<       ûÿø