a ZÚß^¤Êc@sÆdZddlZddlTddlmZmZddlmZmZd\ddd œd d „Z d d „Z d]ddœdd„Z dd„Z dd„Z d^dd„Zdd„Zdd„Zd_dd„Zdd „Zd!d"„Zdd#œd$d%„Zd&d'„ZGd(d)„d)eƒZGd*d+„d+eƒZd,d-„Zd.d/„Zeeeƒe_eeeƒe_Gd0d1„d1eƒZ d2d3„Z!Gd4d5„d5ee d6Z"Gd7d8„d8ee d6Z#Gd9d:„d:ee d6Z$Gd;d<„d„d>ee d6Z&e"e'e(e)fe#e*fe$e+fe%edƒe,fe&ed?ƒfiZ-e"e,fiZ.e,diZ/Gd@dA„dAe0ƒZ1GdBdC„dCe1ƒZ2GdDdE„dEe1ƒZ3dFdG„Z4dHdI„Z5ee4e5ƒe6_7GdJdK„dKe8ƒZ9GdLdM„dMe:ƒZ;GdNdO„dOe:ƒZej?j@dƒZAGdSdT„dTeƒZBGdUdV„dVeƒZCdWdX„ZDdYdZ„ZEeFd[krÂeEƒdS)`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. éN)Ú*)ÚcontextmanagerÚ nullcontext)ÚIntEnumÚautoú ÚexecF)Ú type_commentsÚfeature_versioncCsRt}|r|tO}t|tƒr4|\}}|dks.J‚|}n |dur@d}t|||||dS)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éÿÿÿÿ)Z_feature_version)Z PyCF_ONLY_ASTZPyCF_TYPE_COMMENTSÚ isinstanceÚtupleZcompile)ÚsourceZfilenameÚmoderr ZflagsZmajorZminor©rú/usr/lib64/python3.9/ast.pyÚparse!s   ÿrcs`t|tƒrt|dd}t|tƒr&|j}dd„‰‡fdd„‰‡fdd„‰‡‡‡‡fd d „‰ˆ|ƒ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©rcSstd|›ƒ‚dS)Nzmalformed node or string: )Ú ValueError©ÚnoderrrÚ_raise_malformed_nodeAóz+literal_eval.._raise_malformed_nodecs,t|tƒrt|jƒtttfvr&ˆ|ƒ|jS©N)r ÚConstantÚtypeÚvalueÚintÚfloatÚcomplexr)rrrÚ _convert_numCsz"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) r rrÚTupler ÚmapÚeltsZListÚlistZSetr'ZCallÚfuncÚNameÚidÚargsÚkeywordsZDictÚlenÚkeysÚvaluesZdictÚzipZBinOpr"ÚAddÚSubÚleftÚrightrrr )rr7r8©Ú_convertr!r&rrrr:Os<     ÿÿÿ   ÿ  zliteral_eval.._convert)r ÚstrrZ ExpressionÚbody)Znode_or_stringrr9rÚ literal_eval6s     r=T)Ú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|jrh|jD]t}zt||ƒ} WntyYqòYn0| dur¥óz(dump.._format..)r ÚASTrÚ_fieldsÚgetattrÚAttributeErrorÚappendÚ _attributesr1Ú __class__Ú__name__Újoinr+Úrepr) rrFZprefixZsepÚclsr/Z allsimpler0ÚnamerÚsimple©rEÚannotate_fieldsÚinclude_attributesr>)rFrrExsX          &zdump.._formatzexpected AST, got %rNú )r)r rIÚ TypeErrorrOrPr;)rrWrXr>rrVrÚdumpls 0 r[cCsBdD]8}||jvr||jvrt||dƒ}|durt|||ƒ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_offsetN)rNrKÚsetattr)Únew_nodeZold_nodeÚattrrrrrÚ copy_location¯s  rccs ‡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)Nr\r^r]r_)rNZhasattrr\rKr^r]r_Úiter_child_nodes)rr\r]r^r_Úchild©Ú_fixrrrgÄs$       z#fix_missing_locations.._fixr?rrrrrfrÚfix_missing_locations¼s rhr?cCsJt|ƒD]<}d|jvr(t|ddƒ||_d|jvrt|ddƒ||_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. r\rr^)ÚwalkrNrKr\r^)rÚnrerrrÚincrement_linenoßs    rkc cs8|jD],}z|t||ƒfVWqty0Yq0qdS)zs Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields`` that is present on *node*. N)rJrKrL)rÚfieldrrrÚ iter_fieldsís   rmccsLt|ƒ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)rmr rIr+)rrTrlÚitemrrrrdùs   rdcCs–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. Nr?rAr) r^r_r\r]rLr{ÚencodeÚdecoder|ZinsertrMrQ) rrr}r\r^r]r_ryZpaddingÚfirstZlastrrrÚget_source_segmentEs*       rccs<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)Z collectionsr‚ZpopleftÚextendrd)rr‚Ztodorrrrijs   ric@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_)rOrPrKÚ 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)rmr r+rIrŠ)r‡rrlrrnrrrr†’s   zNodeVisitor.generic_visitc Cs |j}t t|ƒ¡}|dur@t ¡D]\}}t||ƒr$|}q@q$|dur–d|}zt||ƒ}WntypYn&0ddl}|  |›dt d¡||ƒS|  |¡S)Nr…rz" is deprecated; add visit_Constanti) rÚ_const_node_type_namesÚgetrÚitemsr rKrLÚwarningsZwarnZDeprecationWarningr†) r‡rrZ type_namerSrTrˆr‰rŽrrrÚvisit_Constantœs&   ÿzNodeVisitor.visit_ConstantN)rPÚ __module__Ú __qualname__Ú__doc__rŠr†rrrrrr„xs r„c@óeZdZdZdd„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) rmr r+rIrŠrƒrMZdelattrr`)r‡rrlZ old_valueZ new_valuesrrarrrr†Ös&         zNodeTransformer.generic_visitN)rPrr‘r’r†rrrrr”²s#r”cCó|jS)zDeprecated. Use value instead.©r©r‡rrrÚ_getterðór˜cCó ||_dSrr–©r‡rrrrÚ_setterôrrœc@seZdZdd„Zdd„ZdS)Ú_ABCcGs d|_dS)Nz3Deprecated AST node class. Use ast.Constant instead)r’)rSr/rrrÚ__init__ürz _ABC.__init__cCsdt|tƒsdS|tvrXz |j}Wnty4YdS0t|t|ƒoVt|t |d¡ƒ St ||¡S)NFr) r rÚ _const_typesrrLÚ_const_types_notrŒrÚ__instancecheck__)rSZinstrrrrr¡ÿs   þz_ABC.__instancecheck__N)rPrr‘ržr¡rrrrrúsrcOsp|D]<}||jvrq|j |¡}|t|ƒkrt|j›d|›ƒ‚q|tvrXt|i|¤ŽStj|g|¢Ri|¤ŽS)Nz" got multiple values for argument )rJÚindexr1rZrPrŸrÚ__new__)rSr/ÚkwargsÚkeyZposrrrÚ_news   r¦c@óeZdZdZeZdS)ÚNum)rjN©rPrr‘rJr¦r£rrrrr¨ór¨)Z metaclassc@r§)rt©ruNr©rrrrrtrªrtc@r§)ÚBytesr«Nr©rrrrr¬"rªr¬c@seZdZeZdS)Ú NameConstantN)rPrr‘r¦r£rrrrr­&ór­c@r“)ÚEllipsisrcOs6|turtdg|¢Ri|¤ŽStj|g|¢Ri|¤ŽS)N.)r¯rr£)rSr/r¤rrrr£,szEllipsis.__new__N)rPrr‘rJr£rrrrr¯)sr¯.c@óeZdZdZdS)ÚslicezDeprecated AST node class.N©rPrr‘r’rrrrr±Gr®r±c@r“)ÚIndexz@Deprecated AST node class. Use the index value directly instead.cKs|Srr)rSrr¤rrrr£Lrz Index.__new__N©rPrr‘r’r£rrrrr³Jrªr³c@seZdZdZddd„ZdS)ÚExtSlicez1Deprecated AST node class. Use ast.Tuple instead.rcKstt|ƒtƒfi|¤ŽSr)r(r+ZLoad)rSÚdimsr¤rrrr£QrzExtSlice.__new__N)rr´rrrrrµOrªrµcCr•)zDeprecated. Use elts instead.©r*r—rrrÚ _dims_getterTr™r¸cCršrr·r›rrrÚ _dims_setterXrr¹c@r°)ÚSuiteú/Deprecated AST node class. Unused in Python 3.Nr²rrrrrº]r®rºc@r°)ÚAugLoadr»Nr²rrrrr¼`r®r¼c@r°)ÚAugStorer»Nr²rrrrr½cr®r½c@r°)ÚParamr»Nr²rrrrr¾fr®r¾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©Nr?)rOrr—rrrÚnext…s z_Precedence.nextN)rPrr‘r’rÚTUPLEÚYIELDÚTESTÚORÚANDÚNOTÚCMPÚEXPRÚBORÚBXORÚBANDÚSHIFTÚARITHÚTERMÚFACTORÚPOWERÚAWAITÚATOMrÁrrrrr¿ns(r¿cs¤eZdZdZdd„Zdd„Zdd„Zdd „ZdØd d „Zd d„Z dd„Z e dd„ƒZ e ddœdd„ƒZe dd„ƒZdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Z‡fd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Z d;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„Z0d[d\„Z1d]d^„Z2d_d`„Z3dadb„Z4dcdd„Z5dedf„Z6dgdh„Z7didj„Z8dkdl„Z9dmdn„Z:dodp„Z;dqdr„Zdwdx„Z?dydz„Z@d{d|„ZAd}d~„ZBdd€„ZCdd‚„ZDdƒd„„ZEd…d†„ZFd‡dˆ„ZGd‰dŠ„ZHd‹dŒ„ZIddŽ„ZJdd„ZKd‘d’„ZLd“d”„ZMd•d–d—d˜d™œZNeOjPeOjQeOjQeOjQdšœZRd›dœ„ZSd—d˜ddždŸd d¡d¢d£d¤d¥d¦d§d¨œ ZTeOjUeOjUeOjVeOjVeOjVeOjVeOjWeOjWeOjXeOjYeOjZeOjVeOj[d©œ Z\e]dªƒZ^d«d¬„Z_d­d®d¯d°d±d²d³d´dµd¶d·œ Z`d¸d¹„Zadºd»d¼œZbeOjceOjdd½œZed¾d¿„ZfdÀdÁ„ZgdÂdÄZhdÄdÅ„ZidÆdÇ„ZjdÈdÉ„ZkdÊdË„ZldÌdÍ„ZmdÎdÏ„ZndÐdÑ„ZodÒdÓ„ZpdÔdÕ„ZqdÖdׄZr‡ZsS)ÙÚ _UnparserzMethods in this class recursively traverse an AST and output source code for the abstract syntax; original formatting is disregarded.cCs"g|_g|_i|_i|_d|_dS)Nr)Ú_sourceÚ_bufferÚ _precedencesÚ _type_ignoresÚ_indentr—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ÁZ StopIteration)r‡ZinterÚfZseqrDrrrÚ 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.r?rz,có ˆ d¡S©NrB©Úwriterr—rrÚ«rHz&_Unparser.items_view..N)r1ràrÜ)r‡Z traverserrrr—rÚ items_view£s   z_Unparser.items_viewcCs|jr| d¡dS)z8Adds a newline if it isn't the start of generated sourcer@N)rÕràr—rrrÚ maybe_newline­sz_Unparser.maybe_newlinerAcCs | ¡| d|j|¡dS)zXIndent a piece of text and append it, according to the current indentation levelz N)rãràrÙ©r‡rwrrrÚfill²sz_Unparser.fillcCs|j |¡dS)zAppend a piece of textN)rÕrMrärrrrà¸r™z_Unparser.writecCs|j |¡dSr)rÖrMrärrrÚ buffer_writer¼rz_Unparser.buffer_writercCsd |j¡}|j ¡|S)NrA)rQrÖÚ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. ú:r?N)ràrÙ)r‡rêrrrÚ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‡rírîÚ 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âr™z_Unparser.require_parenscCs|j |tj¡Sr)r×rŒr¿rÄ©r‡rrrrrôærz_Unparser.get_precedencecGs|D]}||j|<qdSr)r×)r‡rõZnodesrrrrÚset_precedenceész_Unparser.set_precedencecCs`t|ttttfƒr t|jƒdkr$dS|jd}t|tƒs| |¡}r.| |¡| |jdd…¡n | |j¡dSrÀ)rùÚ_write_docstringrür<)r‡rZ docstringrrrÚ"_write_docstring_and_traverse_bodys z,_Unparser._write_docstring_and_traverse_bodycCs*dd„|jDƒ|_| |¡|j ¡dS)NcSsi|]}|jd|j›“qS)Úignore)r\Ztag)rCrrrrZ sÿz*_Unparser.visit_Module..)Z type_ignoresrØrÿrçr÷rrrÚ visit_Modules þ z_Unparser.visit_Modulecs`ˆ dd¡*ˆ ‡fdd„ˆj|j¡Wdƒn1s<0Yˆ d¡ˆ |j¡dS)NròrócrÝrÞrßrr—rrrá"rHz._Unparser.visit_FunctionType..ú -> )rïrÜrüZargtypesràÚreturnsr÷rr—rÚvisit_FunctionTypes ÿ" z_Unparser.visit_FunctionTypecCs(| ¡| tj|j¡| |j¡dSr)rårør¿rÃrrür÷rrrÚ visit_Expr(sz_Unparser.visit_ExprcCsh| tj|¡F| tj|j|j¡| |j¡| d¡| |j¡Wdƒn1sZ0YdS)Nz := ) rör¿rÂrørÓÚtargetrrüràr÷rrrÚvisit_NamedExpr-s   z_Unparser.visit_NamedExprcó(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzimport crÝrÞrßrr—rrrá6rHz(_Unparser.visit_Import..)rårÜrüÚnamesr÷rr—rÚ visit_Import4ó z_Unparser.visit_ImportcsTˆ d¡ˆ d|j¡|jr,ˆ |j¡ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzfrom Ú.z import crÝrÞrßrr—rrrá>rHz,_Unparser.visit_ImportFrom..)råràrFZmodulerÜrür r÷rr—rÚvisit_ImportFrom8s    z_Unparser.visit_ImportFromcCsP| ¡|jD]}| |¡| d¡q| |j¡| |¡}rL| |¡dS)Nú = )råÚtargetsrüràrrû)r‡rrrúrrrÚ visit_Assign@s    z_Unparser.visit_AssigncCsB| ¡| |j¡| d|j|jjjd¡| |j¡dS)NrYz= ) rårürràÚbinopr"rOrPrr÷rrrÚvisit_AugAssignIs z_Unparser.visit_AugAssigncCsˆ| ¡| dd|j o"t|jtƒ¡| |j¡Wdƒn1sH0Y| d¡| |j¡|j r„| d¡| |j ¡dS)Nròróú: r) rårñrUr rr-rüràÚ annotationrr÷rrrÚvisit_AnnAssignOs *   z_Unparser.visit_AnnAssigncCs*| d¡|jr&| d¡| |j¡dS)NZreturnrY)rårràrür÷rrrÚ visit_ReturnYs  z_Unparser.visit_ReturncCó| d¡dS)NZpass©rår÷rrrÚ visit_Pass_rz_Unparser.visit_PasscCr)NZbreakrr÷rrrÚ visit_Breakbrz_Unparser.visit_BreakcCr)NZcontinuerr÷rrrÚvisit_Continueerz_Unparser.visit_Continuecr)Nzdel crÝrÞrßrr—rrrájrHz(_Unparser.visit_Delete..)rårÜrürr÷rr—rÚ visit_Deletehr z_Unparser.visit_DeletecCs6| d¡| |j¡|jr2| d¡| |j¡dS)Nzassert rB)rårüÚtestZmsgràr÷rrrÚ visit_Assertls    z_Unparser.visit_Assertcr)Nzglobal crÝrÞrßrr—rrráurHz(_Unparser.visit_Global..©rårÜràr r÷rr—rÚ visit_Globalsr z_Unparser.visit_Globalcr)Nz nonlocal crÝrÞrßrr—rrráyrHz*_Unparser.visit_Nonlocal..rr÷rr—rÚvisit_Nonlocalwr z_Unparser.visit_NonlocalcCóh| tj|¡F| d¡|jrF| d¡| tj|j¡| |j¡Wdƒn1sZ0YdS)NZawaitrY)rör¿rÒràrrørÓrür÷rrrÚ visit_Await{ó   z_Unparser.visit_AwaitcCr")NZyieldrY)rör¿rÃràrrørÓrür÷rrrÚ visit_Yieldƒr$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.) rör¿rÃràrrrørÓrür÷rrrÚvisit_YieldFrom‹s  z_Unparser.visit_YieldFromcCsX| d¡|js"|jrtdƒ‚dS| d¡| |j¡|jrT| d¡| |j¡dS)NZraisez*Node can't use cause without an exception.rYz from )råZexcZcauserràrür÷rrrÚ 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)NZtryÚelseZfinally)rårìrür<ZhandlersÚorelseZ finalbody)r‡rZexrrrÚ visit_TryŸs  *    *  z_Unparser.visit_TrycCsz| d¡|jr&| d¡| |j¡|jrB| d¡| |j¡| ¡| |j¡Wdƒn1sl0YdS)NZexceptrYú as )rårràrürTrìr<r÷rrrÚvisit_ExceptHandler®s      z_Unparser.visit_ExceptHandlercCsþ| ¡|jD]}| d¡| |¡q| d|j¡|jdd|jpJ|jdhd}|jD]"}|rp| d¡nd}| |¡q\|jD]"}|rš| d¡nd}| |¡q†Wdƒn1s¾0Y|  ¡|  |¡Wdƒn1sð0YdS) Nú@zclass ròró)rðFrBT) rãÚdecorator_listrårürTrñZbasesr0ràrìrÿ)r‡rÚdecoÚcommaÚerrrÚvisit_ClassDef¹s&        * z_Unparser.visit_ClassDefcCó| |d¡dS)NZdef©Ú_function_helperr÷rrrÚvisit_FunctionDefÑrz_Unparser.visit_FunctionDefcCr3)Nz async defr4r÷rrrÚvisit_AsyncFunctionDefÔrz _Unparser.visit_AsyncFunctionDefcCsÔ| ¡|jD]}| d¡| |¡q|d|j}| |¡| dd¡| |j¡Wdƒn1sn0Y|jr”| d¡| |j¡|j |  |¡d|  |¡Wdƒn1sÆ0YdS)Nr-rYròrórré) rãr.rårürTrïr/rràrìrûrÿ)r‡rZ fill_suffixr/Zdef_strrrrr5×s    *  z_Unparser._function_helpercCó| d|¡dS)Nzfor ©Ú _for_helperr÷rrrÚ visit_Forærz_Unparser.visit_ForcCr8)Nz async for r9r÷rrrÚvisit_AsyncForérz_Unparser.visit_AsyncForcCs²| |¡| |j¡| d¡| |j¡|j| |¡d| |j¡Wdƒn1s`0Y|jr®| d¡| ¡| |j¡Wdƒn1s¤0YdS)Nú in rér() rårürràrÚrìrûr<r))r‡rårrrrr:ìs    *  z_Unparser._for_helpercCs| d¡| |j¡| ¡| |j¡Wdƒn1s@0Y|jrÄt|jƒdkrÄt|jdtƒrÄ|jd}| d¡| |j¡| ¡| |j¡WdƒqJ1s¸0YqJ|jr | d¡| ¡| |j¡Wdƒn1s0YdS)Nzif r?rzelif r() rårürrìr<r)r1r ZIfr÷rrrÚvisit_Iføs   *$    ,  z_Unparser.visit_IfcCs’| d¡| |j¡| ¡| |j¡Wdƒn1s@0Y|jrŽ| d¡| ¡| |j¡Wdƒn1s„0YdS)Nzwhile r()rårürrìr<r)r÷rrrÚ visit_While s   *  z_Unparser.visit_Whilecófˆ d¡ˆ ‡fdd„ˆj|j¡ˆjˆ |¡dˆ |j¡Wdƒn1sX0YdS)Nzwith crÝrÞrßrr—rrrárHz&_Unparser.visit_With..ré©rårÜrürrìrûr<r÷rr—rÚ visit_Withó z_Unparser.visit_Withcr@)Nz async with crÝrÞrßrr—rrrárHz+_Unparser.visit_AsyncWith..rérAr÷rr—rÚvisit_AsyncWithrCz_Unparser.visit_AsyncWithcCó,| d¡| ||j¡| t|jƒ¡dS©NrÛ)ràÚ_fstring_JoinedStrrærRrèr÷rrrÚvisit_JoinedStr ó z_Unparser.visit_JoinedStrcCrErF)ràÚ_fstring_FormattedValuerærRrèr÷rrrÚvisit_FormattedValue%rIz_Unparser.visit_FormattedValuecCs.|jD]"}t|dt|ƒjƒ}|||ƒqdS)NÚ _fstring_)r3rKrrP)r‡rràrÚmethrrrrG*s z_Unparser._fstring_JoinedStrcCs6t|jtƒstdƒ‚|j dd¡ dd¡}||ƒdS)Nz.Constants inside JoinedStr should be a string.Ú{z{{Ú}z}})r rr;rÚreplace)r‡rràrrrrÚ_fstring_Constant/s z_Unparser._fstring_ConstantcCsº|dƒt|ƒƒ}| tj ¡|j¡| |j¡}| d¡rD|dƒ||ƒ|jdkr~t |jƒ}|dvrpt dƒ‚|d|›ƒ|j r®|dƒt |dt|j ƒj ƒ}||j |ƒ|d ƒdS) NrNrYr ZsrazUnknown f-string conversion.z!rërLrO)rrør¿rÄrÁrrŠZ startswithÚ conversionZchrrZ format_specrKrP)r‡rràÚunparserZexprrRrMrrrrJ5s"      z!_Unparser._fstring_FormattedValuecCs| |j¡dSr)ràr.r÷rrrÚ visit_NameHrz_Unparser.visit_NamecCszdd„}| ¡|jdkr$| d¡|j}|rdd t||ƒ¡}|ddkrX| ddd¡}| dd ¡}| d|›d¡dS) NcSs|dvr |S| d¡ d¡S)N)r@z Zunicode_escapeZascii)r~r)rzrrrÚesc_charLsz,_Unparser._write_docstring..esc_charÚurAr z"z\"z"""z""\")råÚkindràrrQr)rP)r‡rrUrrrrrþKs     z_Unparser._write_docstringcCs8t|ttfƒr&| t|ƒ dt¡¡n| t|ƒ¡dS)NZinf)r rr ràrRrPÚ_INFSTRr›rrrÚ_write_constantcsz_Unparser._write_constantcCs„|j}t|tƒrL| dd¡| |j|¡Wdƒq€1s@0Yn4|dur`| d¡n |jdkrt| d¡| |j¡dS)Nròró.ú...rV)rr r rïrârYràrW)r‡rrrrrrjs .   z_Unparser.visit_ConstantcsJˆ dd¡*ˆ ‡fdd„ˆj|j¡Wdƒn1s<0YdS)Nú[ú]crÝrÞrßrr—rrráxrHz&_Unparser.visit_List..)rïrÜrür*r÷rr—rÚ visit_Listvóz_Unparser.visit_ListcCóR| dd¡2| |j¡|jD]}| |¡q Wdƒn1sD0YdS)Nr[r\©rïrüÚeltÚ generators©r‡rZgenrrrÚvisit_ListCompzó  z_Unparser.visit_ListCompcCr_©Nròrór`rcrrrÚvisit_GeneratorExp€rez_Unparser.visit_GeneratorExpcCr_)NrNrOr`rcrrrÚ visit_SetComp†rez_Unparser.visit_SetCompcCsh| dd¡H| |j¡| d¡| |j¡|jD]}| |¡q6Wdƒn1sZ0YdS)NrNrOr)rïrür¥ràrrbrcrrrÚ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 r=ú if ) Zis_asyncràrør¿rÂrrürÄrÁrÚZifs)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)Nrjz else ) rör¿rÄrørÁr<rrüràr)r÷rrrÚ visit_IfExp¢s    z_Unparser.visit_IfExpcsX|jstdƒ‚ˆ dd¡*ˆ ‡fdd„ˆj|j¡Wdƒn1sJ0YdS)Nz&Set node should have at least one itemrNrOcrÝrÞrßrr—rrrá°rHz%_Unparser.visit_Set..)r*rrïrÜrür÷rr—rÚ visit_Set¬sz_Unparser.visit_Setcsj‡fdd„‰‡‡fdd„}ˆ dd¡0ˆ ‡fdd„|t|j|jƒ¡Wdƒn1s\0YdS) Ncs"ˆ |¡ˆ d¡ˆ |¡dS©Nr)rürà)ÚkÚvr—rrÚwrite_key_value_pair³s  z2_Unparser.visit_Dict..write_key_value_paircsB|\}}|dur4ˆ d¡ˆ tj|¡ˆ |¡n ˆ||ƒdS)Nú**)ràrør¿rÉrü)rnrorp©r‡rqrrÚ write_item¸s   z(_Unparser.visit_Dict..write_itemrNrOcrÝrÞrßrr—rrráÅrHz&_Unparser.visit_Dict..)rïrÜr4r2r3)r‡rrtrrsrÚ visit_Dict²s   ÿz_Unparser.visit_DictcCs@| dd¡ | |j|j¡Wdƒn1s20YdSrf)rïrârür*r÷rrrÚ visit_TupleÈr^z_Unparser.visit_Tupleú~Únotú+ú-)ZInvertZNotr#r$)rxrwryrzcCs‚|j|jjj}|j|}| ||¡H| |¡|tjurF| d¡|  ||j ¡|  |j ¡Wdƒn1st0YdS©NrY) Úunopr"rOrPÚunop_precedenceröràr¿rÐrør%rü)r‡rÚoperatorÚoperator_precedencerrrÚ visit_UnaryOpÔs    z_Unparser.visit_UnaryOprr-ú/ú%ú<<ú>>ú|ú^ú&ú//rr) r5r6ZMultZMatMultZDivZModZLShiftZRShiftZBitOrZBitXorZBitAndZFloorDivZPow) ryrzrr-rr‚rƒr„r…r†r‡rˆrr)rrcCs´|j|jjj}|j|}| ||¡z||jvr@| ¡}|}n |}| ¡}| ||j ¡|  |j ¡|  d|›d¡| ||j ¡|  |j ¡Wdƒn1s¦0YdSr{) rr"rOrPÚbinop_precedenceröÚ binop_rassocrÁrør7rüràr8)r‡rr~rZleft_precedenceZright_precedencerrrÚ visit_BinOps   z_Unparser.visit_BinOpz==z!=zz>=Ziszis notZinznot in) ZEqZNotEqZLtZLtEZGtZGtEZIsZIsNotZInZNotIncCsš| tj|¡x|jtj ¡|jg|j¢RŽ| |j¡t|j |jƒD].\}}|  d|j |j j d¡| |¡qHWdƒn1sŒ0YdSr{)rör¿rÈrørÁr7Z comparatorsrür4ZopsràÚcmpopsrOrP)r‡rZor1rrrÚ visit_Compares  z_Unparser.visit_CompareÚandÚor)ZAndZOr)rŽrcs~ˆj|jjj}ˆj|‰‡‡fdd„}ˆ ˆ|¡6d|›d‰ˆ ‡‡fdd„||j¡Wdƒn1sp0YdS)Ncs"ˆ ¡‰ˆ ˆ|¡ˆ |¡dSr)rÁrørür)rr‡rrÚincreasing_level_traverse.s z9_Unparser.visit_BoolOp..increasing_level_traverserYcs ˆ ˆ¡Srrßr)rur‡rrrá6rHz(_Unparser.visit_BoolOp..)Úboolopsr"rOrPÚboolop_precedencerörÜr3)r‡rr~rr)rrur‡rÚ visit_BoolOp*s   z_Unparser.visit_BoolOpcCsZ| tj|j¡| |j¡t|jtƒr@t|jjtƒr@| d¡| d¡| |j ¡dS)NrYr ) rør¿rÓrrür rrràrbr÷rrrÚvisit_Attribute8s    z_Unparser.visit_AttributecCs¤| tj|j¡| |j¡| dd¡hd}|jD]"}|rH| d¡nd}| |¡q4|jD]"}|rr| d¡nd}| |¡q^Wdƒn1s–0YdS)NròróFrBT) rør¿rÓr,rürïr/ràr0)r‡rr0r1rrrÚ visit_CallCs      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)r ZStarred)rCrarrrrG]rHzE_Unparser.visit_Subscript..is_simple_tuple..)r r(r*Zany)Z slice_valuerrrÚis_simple_tupleVs  ÿýz2_Unparser.visit_Subscript..is_simple_tupler[r\) rør¿rÓrrürïr±râr*)r‡rr–rrrÚvisit_SubscriptUs   z_Unparser.visit_SubscriptcCs*| d¡| tj|j¡| |j¡dS)Nr)ràrør¿rÉrrür÷rrrÚ visit_Starredhs z_Unparser.visit_StarredcCr)NrZrßr÷rrrÚvisit_Ellipsismrz_Unparser.visit_EllipsiscCsN|jr| |j¡| d¡|jr.| |j¡|jrJ| d¡| |j¡dS)Nrë)ZlowerrüràZupperZstepr÷rrrÚ visit_Sliceps    z_Unparser.visit_SlicecCs,| |j¡|jr(| d¡| |j¡dSrn)ràÚargrrür÷rrrÚ visit_argzó  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) NTr?FrBú=z, /rrrr)Z posonlyargsr/r1ÚdefaultsZ enumerater4ràrüZvarargZ kwonlyargsr›rZ kw_defaultsZkwarg) r‡rr€Zall_argsrŸr¢ZelementsZaZdrrrÚvisit_arguments€sN                z_Unparser.visit_argumentscCs<|jdur| d¡n| |j¡| d¡| |j¡dS)Nrrrž)r›ràrürr÷rrrÚ visit_keyword³s     z_Unparser.visit_keywordcCsn| tj|¡L| d¡| |j¡| d¡| tj|j¡| |j¡Wdƒn1s`0YdS)Nzlambda r)rör¿rÄràrür/rør<r÷rrrÚ visit_Lambda»s    z_Unparser.visit_LambdacCs&| |j¡|jr"| d|j¡dS©Nr+)ràrTZasnamer÷rrrÚ visit_aliasÃs z_Unparser.visit_aliascCs,| |j¡|jr(| d¡| |j¡dSr£)rüZ context_exprZ optional_varsràr÷rrrÚvisit_withitemÈrz_Unparser.visit_withitem)rA)trPrr‘r’ržrÜrârãråràræÚpropertyrèrrìrïrñrörôrørùrûrürŠrÿrrrrr r rrrrrrrrrr r!r#r%r&r'r*r,r2r6r7r5r;r<r:r>r?rBrDrHrKrGrQrJrTrþrYrr]rdrgrhrirkrlrmrurvr|r¿rÇrÐr}r€rrÎrÏrÍrÊrËrÌrÑr‰Z frozensetrŠr‹rŒrr‘rÆrÅr’r“r”r•r—r˜r™ršrœr r¡r¢r¤r¥Z __classcell__rrrýrrÔ‹s                ü óóö    3rÔcCstƒ}| |¡Sr)rÔrŠ)Zast_objrSrrrÚunparseÎsr§cCsäddl}|jdd}|jd|jddddd 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)ZprogÚinfileZrbrz?rzz$the file to parse; defaults to stdin)rZnargsÚdefaultÚhelpz-mz--moder)rZsinglerZ func_typez(specify what kind of code must be parsed)r©Zchoicesrªz--no-type-commentsTZ store_falsez)don't add information about type comments)r©Úactionrªz-az--include-attributesZ store_truez:include attributes such as line numbers and column offsets)r«rªz-iz--indentr z'indentation of nodes (number of spaces))rr©rª)r)rXr>)ÚargparseZArgumentParserZ add_argumentZFileTyperZ parse_argsr¨ZreadrrTrZno_type_commentsZprintr[rXr>)r¬Zparserr/r¨rZtreerrrÚmainÓs0 þ þ ÿ ÿ ÿ&r­Z__main__)rr)TF)r?)T)Gr’ZsysZ_astZ contextlibrrZenumrrrr=r[rcrhrkrmrdrxr{r|rriZobjectr„r”r˜rœr¦rrjrurrr¦r¨rtr¬r­r¯rrr r;ZbytesZboolrŸr r‹rIr±r³rµr¸r¹r(r¶ZmodrºZ expr_contextr¼r½r¾rRZ float_infoZ max_10_exprXr¿rÔr§r­rPrrrrZsÿ 6C #    %:>      ûÿø  I