a €šçdsÛã@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!d7Z#Gd8d9„d9ee!d7Z$Gd:d;„d;ee!d7Z%Gdd?„d?ee!d7Z'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_krð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|||||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éÿÿÿÿ)Ú_feature_version)Ú PyCF_ONLY_ASTÚPyCF_TYPE_COMMENTSÚ isinstanceÚtupleÚcompile)ÚsourceÚfilenameÚmoder r ÚflagsÚmajorÚminor©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_nodeAsz+literal_eval.._raise_malformed_nodecs,t|tƒrt|jƒtttfvr&ˆ|ƒ|jS©N)rÚConstantÚtypeÚvalueÚintÚfloatÚcomplexr)r!rrÚ _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) rr#r%ÚTuplerÚmapÚeltsÚListÚlistÚSetr0ÚCallÚfuncÚNameÚidÚargsÚkeywordsÚDictÚlenÚkeysÚvaluesÚdictÚzipÚBinOpr+ÚAddÚSubÚleftÚrightr&r'r()r rFrG©Ú_convertr)r/r!rrrIOs<     ÿÿÿ   ÿ  zliteral_eval.._convert)rÚstrrÚ ExpressionÚbody)Únode_or_stringrrHrÚ literal_eval6s     rNT)Ú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Ú _attributesr>Ú __class__Ú__name__Újoinr5Úrepr) r rXÚprefixÚsepÚclsr;Ú allsimpler<Únamer%Úsimple©rWÚannotate_fieldsÚinclude_attributesrO)rXrrWxsX          &zdump.._formatzexpected AST, got %rNú )r)rr[Ú TypeErrorrarbrJ)r rlrmrOrrkrÚdumpls 0 rpcCsVdD]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_offsetNÚend_)r`r]ÚhasattrÚ startswithÚsetattr)Únew_nodeÚold_nodeÚattrr%rrrÚ copy_location¯s ÿÿr|cs ‡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)Nrqrsrrrt)r`rvrqr]rsrrrtÚiter_child_nodes)r rqrrrsrtÚchild©Ú_fixrrr€Ès$       z#fix_missing_locations.._fixrPrrrrrrÚfix_missing_locationsÀs rrPcCsVt|ƒ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. rqrrsN)Úwalkr`r]rqrs)r Únr~rsrrrÚincrement_linenoãs  ÿþ r„c cs8|jD],}z|t||ƒfVWqty0Yq0qdS)zs Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields`` that is present on *node*. N)r\r]r^)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†rr[r5)r rir…Úitemrrrr}s   r}cCs–t|ttttfƒs"td|jjƒ‚|jr8t|jdt ƒsr_)rÚidxÚlinesÚ next_lineÚcrrrÚ_splitlines_no_ff(s     r™cCs,d}|D]}|dvr||7}q|d7}q|S)z6Replace all chars except '\f\t' in a line with spaces.rRz rnr)rÚresultr˜rrrÚ_pad_whitespaceAs   r›)Úpaddedc Csz>|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. NrPrRr) rsrtrqrrr^r™ÚencodeÚdecoder›Úinsertr_rc) rr rœrqrsrrrtr–ÚpaddingÚfirstÚlastrrrÚget_source_segmentLs*       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Úextendr})r r¤Útodorrrr‚qs   r‚c@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_)rarbr]Ú 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†rr5r[r¯)r¬r r…r%r‡rrrr«™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_Constanté) r%Ú_const_node_type_namesÚgetr$Úitemsrr]r^ÚwarningsÚwarnÚDeprecationWarningr«) r¬r r%Ú type_namergrir­r®r´rrrÚvisit_Constant£s&   ÿzNodeVisitor.visit_ConstantN)rbÚ __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†rr5r[r¯r§r_Údelattrrx)r¬r r…Ú old_valueÚ new_valuesr%ryrrrr«Ýs&         zNodeTransformer.generic_visitN)rbr¹rºr»r«rrrrr¼¹s#r¼rƒcCs|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»)rgr;rrrÚ__init__sz _ABC.__init__cCsdt|tƒsdS|tvrXz |j}Wnty4YdS0t|t|ƒoVt|t |d¡ƒ St ||¡S)NFr) rr#Ú _const_typesr%r^Ú_const_types_notr²r$Ú__instancecheck__)rgÚinstr%rrrrÉs   þz_ABC.__instancecheck__N)rbr¹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 )r\Úindexr>rorbrÇr#Ú__new__)rgr;ÚkwargsÚkeyÚposrrrÚ_news   rÐc@seZdZdZeZdS)ÚNum)rƒN©rbr¹rºr\rÐrÌrrrrrÑ#srÑ)Ú metaclassc@seZdZdZeZdS)r©rŽNrÒrrrrr'src@seZdZdZeZdS)ÚBytesrÔNrÒrrrrrÕ+srÕc@seZdZeZdS)Ú NameConstantN)rbr¹rºrÐrÌrrrrrÖ/srÖc@seZdZdZdd„ZdS)ÚEllipsisrcOs6|turtdg|¢Ri|¤ŽStj|g|¢Ri|¤ŽS)N.)r×r#rÌ)rgr;rÍrrrrÌ5szEllipsis.__new__N)rbr¹rºr\rÌrrrrr×2sr×.c@seZdZdZdS)ÚslicezDeprecated AST node class.N©rbr¹rºr»rrrrrØPsrØc@seZdZdZdd„ZdS)ÚIndexz@Deprecated AST node class. Use the index value directly instead.cKs|Sr"r)rgr%rÍrrrrÌUsz Index.__new__N©rbr¹rºr»rÌrrrrrÚSsrÚc@seZdZdZddd„ZdS)ÚExtSlicez1Deprecated AST node class. Use ast.Tuple instead.rcKstt|ƒtƒfi|¤ŽSr")r1r5ÚLoad)rgÚdimsrÍrrrrÌZszExtSlice.__new__N)rrÛrrrrrÜXsrÜrÞcCs|jS)zDeprecated. Use elts instead.©r3rÁrrrÚ _dims_getterbsràcCs ||_dSr"rßrÃrrrÚ _dims_setterfsrác@seZdZdZdS)ÚSuiteú/Deprecated AST node class. Unused in Python 3.NrÙrrrrrâksrâc@seZdZdZdS)ÚAugLoadrãNrÙrrrrränsräc@seZdZdZdS)ÚAugStorerãNrÙrrrrråqsråc@seZdZdZdS)ÚParamrãNrÙrrrrrætsræÚ1ec@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©NrP)rarrÁrrrÚnext“s z_Precedence.nextN)rbr¹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€„ZBdd‚„ZCdƒd„„ZDd…d†„ZEd‡dˆ„ZFd‰dŠ„ZGd‹dŒ„ZHddŽ„ZIdd„ZJd‘d’„ZKd“d”„ZLd•d–„ZMd—d˜„ZNd™dš„ZOd›dœ„ZPddž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)áÚ _UnparserzMethods 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¬rrrrrÆ£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¬ÚinterÚfÚseqrVrrrÚ 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.rPrú,cs ˆ d¡S©NrS©ÚwriterrÁrrÚ¿rZz&_Unparser.items_view..N)r>rr )r¬Ú traverserr³rrÁrÚ items_view·s   z_Unparser.items_viewcCs|jr| d¡dS)z8Adds a newline if it isn't the start of generated sourcerQN)rrrÁrrrÚ maybe_newlineÁsz_Unparser.maybe_newlinerRcCs | ¡| d|j|¡dS)zXIndent a piece of text and append it, according to the current indentation levelz N)rrr©r¬r’rrrÚfillÆsz_Unparser.fillcCs|j |¡dS)zAppend a piece of textN)rr_rrrrrÌsz_Unparser.writecCs|j |¡dSr")rr_rrrrÚ buffer_writerÐsz_Unparser.buffer_writercCsd |j¡}|j ¡|S)NrR)rcrÚ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. ú:rPN)rr)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¬Ú precedencer rrrÚrequire_parensösz_Unparser.require_parenscCs|j |tj¡Sr")rr²rèrí©r¬r rrrr%úsz_Unparser.get_precedencecGs|D]}||j|<qdSr")r)r¬r&Únodesr rrrÚset_precedenceýsz_Unparser.set_precedencecCs`t|ttttfƒr t|jƒdkr$dS|jd}t|tƒsrLrŒr%r#rJr(rrrÚget_raw_docstrings ÿ þ  z_Unparser.get_raw_docstringcCs*|j |j¡p|j}|dur&d|›SdS)Nz # type: )rr²rqÚ type_comment)r¬r ÚcommentrrrÚget_type_commentsz_Unparser.get_type_commentcs0t|tƒr |D]}| |¡qn tƒ |¡dSr")rr5ÚtraverseÚsuperr¯)r¬r r‡©rarrr/s z_Unparser.traversecCsg|_| |¡d |j¡S)z‚Outputs a source code string that, if converted back to an ast (using ast.parse) will generate an AST equivalent to *node*rR)rr/rcr(rrrr¯s z_Unparser.visitcCs>| |¡}r.| |¡| |jdd…¡n | |j¡dSré)r+Ú_write_docstringr/rL)r¬r Ú docstringrrrÚ"_write_docstring_and_traverse_body$s z,_Unparser._write_docstring_and_traverse_bodycCs*dd„|jDƒ|_| |¡|j ¡dS)NcSsi|]}|jd|j›“qS)Úignore)rqÚtag)rUr5rrrÚ ,sÿz*_Unparser.visit_Module..)Ú type_ignoresrr4rr(rrrÚ visit_Module+s þ z_Unparser.visit_Modulecs`ˆ dd¡*ˆ ‡fdd„ˆj|j¡Wdƒn1s<0Yˆ d¡ˆ |j¡dS)Nr#r$cs ˆ d¡SrrrrÁrrr6rZz._Unparser.visit_FunctionType..ú -> )r r r/ÚargtypesrÚreturnsr(rrÁrÚvisit_FunctionType3s ÿ" z_Unparser.visit_FunctionTypecCs(| ¡| tj|j¡| |j¡dSr")rr*rèrìr%r/r(rrrÚ visit_Expr<sz_Unparser.visit_ExprcCsh| tj|¡F| tj|j|j¡| |j¡| d¡| |j¡Wdƒn1sZ0YdS)Nz := ) r'rèrër*rüÚtargetr%r/rr(rrrÚvisit_NamedExprAs   z_Unparser.visit_NamedExprcs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzimport cs ˆ d¡SrrrrÁrrrJrZz(_Unparser.visit_Import..)rr r/Únamesr(rrÁrÚ visit_ImportHs z_Unparser.visit_ImportcsTˆ d¡ˆ d|j¡|jr,ˆ |j¡ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzfrom Ú.z import cs ˆ d¡SrrrrÁrrrRrZz,_Unparser.visit_ImportFrom..)rrrXÚmoduler r/rAr(rrÁrÚvisit_ImportFromLs    z_Unparser.visit_ImportFromcCsP| ¡|jD]}| |¡| d¡q| |j¡| |¡}rL| |¡dS)Nú = )rÚtargetsr/rr%r.)r¬r r?r,rrrÚ visit_AssignTs    z_Unparser.visit_AssigncCsB| ¡| |j¡| d|j|jjjd¡| |j¡dS)Nrnz= ) rr/r?rÚbinopr+rarbr%r(rrrÚvisit_AugAssign]s z_Unparser.visit_AugAssigncCsˆ| ¡| dd|j o"t|jtƒ¡| |j¡Wdƒn1sH0Y| d¡| |j¡|j r„| d¡| |j ¡dS)Nr#r$ú: rF) rr"rjrr?r9r/rÚ annotationr%r(rrrÚvisit_AnnAssigncs *   z_Unparser.visit_AnnAssigncCs*| d¡|jr&| d¡| |j¡dS)NÚreturnrn)rr%rr/r(rrrÚ visit_Returnms  z_Unparser.visit_ReturncCs| d¡dS)NÚpass©rr(rrrÚ visit_Passssz_Unparser.visit_PasscCs| d¡dS)NÚbreakrQr(rrrÚ visit_Breakvsz_Unparser.visit_BreakcCs| d¡dS)NÚcontinuerQr(rrrÚvisit_Continueysz_Unparser.visit_Continuecs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzdel cs ˆ d¡SrrrrÁrrr~rZz(_Unparser.visit_Delete..)rr r/rGr(rrÁrÚ visit_Delete|s z_Unparser.visit_DeletecCs6| d¡| |j¡|jr2| d¡| |j¡dS)Nzassert rS)rr/ÚtestÚmsgrr(rrrÚ visit_Assert€s    z_Unparser.visit_Assertcs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nzglobal cs ˆ d¡SrrrrÁrrr‰rZz(_Unparser.visit_Global..©rr rrAr(rrÁrÚ visit_Global‡s z_Unparser.visit_Globalcs(ˆ d¡ˆ ‡fdd„ˆj|j¡dS)Nz nonlocal cs ˆ d¡SrrrrÁrrrrZz*_Unparser.visit_Nonlocal..r[r(rrÁrÚvisit_Nonlocal‹s z_Unparser.visit_NonlocalcCsh| tj|¡F| d¡|jrF| d¡| tj|j¡| |j¡Wdƒn1sZ0YdS)NÚawaitrn)r'rèrûrr%r*rür/r(rrrÚ visit_Awaits   z_Unparser.visit_AwaitcCsh| tj|¡F| d¡|jrF| d¡| tj|j¡| |j¡Wdƒn1sZ0YdS)NÚyieldrn)r'rèrìrr%r*rür/r(rrrÚ 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.) r'rèrìrr%rr*rür/r(rrrÚ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.rnz from )rÚexcÚcauserrr/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)NÚtryÚelseÚfinally)rrr/rLÚhandlersÚorelseÚ finalbody)r¬r ÚexrrrÚ visit_Try³s  *    *  z_Unparser.visit_TrycCsz| d¡|jr&| d¡| |j¡|jrB| d¡| |j¡| ¡| |j¡Wdƒn1sl0YdS)NÚexceptrnú as )rr$rr/rirrLr(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!FrST) rÚdecorator_listrr/rir"Úbasesr<rrr4)r¬r ÚdecoÚcommaÚerrrÚvisit_ClassDefÍs&        * z_Unparser.visit_ClassDefcCs| |d¡dS)NÚdef©Ú_function_helperr(rrrÚvisit_FunctionDefåsz_Unparser.visit_FunctionDefcCs| |d¡dS)Nz async defrzr(rrrÚvisit_AsyncFunctionDefèsz _Unparser.visit_AsyncFunctionDefcCsÔ| ¡|jD]}| d¡| |¡q|d|j}| |¡| dd¡| |j¡Wdƒn1sn0Y|jr”| d¡| |j¡|j |  |¡d|  |¡Wdƒn1sÆ0YdS)Nrrrnr#r$r:r) rrsrr/rir r;r<rrr.r4)r¬r Ú fill_suffixruÚdef_strrrrr{ës    *  z_Unparser._function_helpercCs| d|¡dS)Nzfor ©Ú _for_helperr(rrrÚ visit_Forúsz_Unparser.visit_ForcCs| d|¡dS)Nz async for r€r(rrrÚvisit_AsyncForýsz_Unparser.visit_AsyncForcCs²| |¡| |j¡| d¡| |j¡|j| |¡d| |j¡Wdƒn1s`0Y|jr®| d¡| ¡| |j¡Wdƒn1s¤0YdS)Nú in rrh) rr/r?rrrr.rLrk)r¬rr rrrrs    *  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 rPrzelif rh) rr/rXrrLrkr>rÚIfr(rrrÚvisit_If s   *$    ,  z_Unparser.visit_IfcCs’| d¡| |j¡| ¡| |j¡Wdƒn1s@0Y|jrŽ| d¡| ¡| |j¡Wdƒn1s„0YdS)Nzwhile rh)rr/rXrrLrkr(rrrÚ visit_Whiles   *  z_Unparser.visit_Whilecsfˆ d¡ˆ ‡fdd„ˆj|j¡ˆjˆ |¡dˆ |j¡Wdƒn1sX0YdS)Nzwith cs ˆ d¡SrrrrÁrrr*rZz&_Unparser.visit_With..r©rr r/r³rr.rLr(rrÁrÚ visit_With(s z_Unparser.visit_Withcsfˆ d¡ˆ ‡fdd„ˆj|j¡ˆjˆ |¡dˆ |j¡Wdƒn1sX0YdS)Nz async with cs ˆ d¡SrrrrÁrrr0rZz+_Unparser.visit_AsyncWith..rrˆr(rrÁrÚvisit_AsyncWith.s 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 ú\Úunicode_escapeÚascii)Ú isprintablerrž)r˜)rrrÚ escape_char:s  z2_Unparser._str_literal_helper..escape_charrRrQcSsg|]}|tvr|‘qSr)Ú _MULTI_QUOTES©rUÚqrrrÚ GrZz1_Unparser._str_literal_helper..csg|]}|ˆvr|‘qSrrr”©Úescaped_stringrrr–HrZc3s|]}ˆd|vr|VqdSrTrr”)ÚstringrrrYNrZz0_Unparser._str_literal_helper..rrPr cs|dˆdkS)Nrr r)r•r—rrrRrZz/_Unparser._str_literal_helper..)rÎr NrŽ)rcr2rdrêÚsortr>)r¬r™rŒrr’Úpossible_quotesÚquoter)rr˜r™rÚ_str_literal_helper4s  z_Unparser._str_literal_helper©rŒcCs4|j||d\}}|d}| |›|›|›¡dS)zKWrite string literal value with a best effort attempt to avoid backslashes.ržrN)rr)r¬r™rŒÚ quote_typerrrÚ_write_str_avoiding_backslashesZsz)_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_r‹rRr)rrÚ_fstring_JoinedStrrr rr@r]r$rbr_rr#Ú _ALL_QUOTESrrc) r¬r rr%ÚmethÚ new_bufferrŒÚ is_constantrŸrrrÚvisit_JoinedStr`s*     þ   z_Unparser.visit_JoinedStrcCs(| d¡| ||j¡| |j¡dS)Nr )rÚ_fstring_FormattedValuerr rr(rrrÚvisit_FormattedValues z_Unparser.visit_FormattedValuecCs.|jD]"}t|dt|ƒjƒ}|||ƒqdS)Nr¡)r@r]r$rb)r¬r rr%r¤rrrr¢„s z_Unparser._fstring_JoinedStrcCs6t|jtƒstdƒ‚|j dd¡ dd¡}||ƒdS)Nz.Constants inside JoinedStr should be a string.Ú{z{{Ú}z}})rr%rJrÚreplace)r¬r rr%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ªTrrnrŽz5Unable to avoid backslash in f-string expression partr ÚsrazUnknown f-string conversion.ú!rr¡r«)r$r*rèrírêr%r¯rwrÚ conversionÚchrÚ format_specr]rb)r¬r rÚunparserÚexprr°r¤rrrr¨s&     z!_Unparser._fstring_FormattedValuecCs| |j¡dSr")rr:r(rrrÚ visit_Name¤sz_Unparser.visit_NamecCs0| ¡|jdkr| d¡|j|jtddS)NÚurž)rÚkindrr r%r“r(rrrr2§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(rrdr¬Ú_INFSTRrrJr 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 rr¼rr·)r¬r r%rrrr¸»s .   z_Unparser.visit_ConstantcsJˆ dd¡*ˆ ‡fdd„ˆj|j¡Wdƒn1s<0YdS)Nú[ú]cs ˆ d¡SrrrrÁrrrÉrZz&_Unparser.visit_List..)r r r/r3r(rrÁ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#r$rÁ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«rK)r r/rÎrr%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 r„ú if ) Úis_asyncrr*rèrër?r/rírêrÚifs)r¬r Ú 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 ) r'rèrír*rêrLrXr/rrkr(rrrÚ visit_IfExpós    z_Unparser.visit_IfExpcs\|jrNˆ dd¡*ˆ ‡fdd„ˆj|j¡WdƒqX1sB0Yn ˆ d¡dS)Nrªr«cs ˆ d¡SrrrrÁrrrrZz%_Unparser.visit_Set..z{*()})r3r r r/rr(rrÁrÚ visit_Setýs:z_Unparser.visit_Setcsj‡fdd„‰‡‡fdd„}ˆ dd¡0ˆ ‡fdd„|t|j|jƒ¡Wdƒn1s\0YdS) Ncs"ˆ |¡ˆ d¡ˆ |¡dS©NrK)r/r)ÚkÚvrÁrrÚwrite_key_value_pairs  z2_Unparser.visit_Dict..write_key_value_paircsB|\}}|dur4ˆ d¡ˆ tj|¡ˆ |¡n ˆ||ƒdS)Nú**)rr*rèròr/)r‡rÓrÔ©r¬rÕrrÚ write_item s   z(_Unparser.visit_Dict..write_itemrªr«cs ˆ d¡SrrrrÁrrrrZz&_Unparser.visit_Dict..)r r rBr?r@)r¬r rØrr×rÚ visit_Dicts   ÿz_Unparser.visit_DictcCs@| dd¡ | |j|j¡Wdƒn1s20YdSrÇ)r rr/r3r(rrrÚ visit_Tuplesz_Unparser.visit_Tupleú~Únotú+rº)ÚInvertÚNotr,r-)rÜrÛrÝrºcCs‚|j|jjj}|j|}| ||¡H| |¡|tjurF| d¡|  ||j ¡|  |j ¡Wdƒn1st0YdS©Nrn) Úunopr+rarbÚunop_precedencer'rrèrùr*r.r/)r¬r ÚoperatorÚoperator_precedencerrrÚ visit_UnaryOp(s    z_Unparser.visit_UnaryOprrrú/ú%ú<<ú>>ú|ú^ú&ú//rÖ) rDrEÚMultÚMatMultÚDivÚModÚLShiftÚRShiftÚBitOrÚBitXorÚBitAndÚFloorDivÚPow) rÝrºrrrræ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à) rIr+rarbÚbinop_precedencer'Ú binop_rassocrêr*rFr/rrG)r¬r rãräÚleft_precedenceÚright_precedencerrrÚ visit_BinOpUs   z_Unparser.visit_BinOpz==z!=úz>=Úiszis notÚinznot in) ÚEqÚNotEqÚLtÚLtEÚGtÚGtEÚIsÚIsNotÚInÚNotIncCsš| tj|¡x|jtj ¡|jg|j¢RŽ| |j¡t|j |jƒD].\}}|  d|j |j j d¡| |¡qHWdƒn1sŒ0YdSrà)r'rèrñr*rêrFÚ comparatorsr/rBÚopsrÚcmpopsrarb)r¬r ÚorwrrrÚ visit_Comparess  z_Unparser.visit_CompareÚandÚor)ÚAndÚOr)rrcs~ˆj|jjj}ˆj|‰‡‡fdd„}ˆ ˆ|¡6d|›d‰ˆ ‡‡fdd„||j¡Wdƒn1sp0YdS)Ncs"ˆ ¡‰ˆ ˆ|¡ˆ |¡dSr")rêr*r/r)rär¬rrÚincreasing_level_traverse‚s z9_Unparser.visit_BoolOp..increasing_level_traverserncs ˆ ˆ¡Sr"rr)rŽr¬rrrŠrZz(_Unparser.visit_BoolOp..)Úboolopsr+rarbÚboolop_precedencer'r r@)r¬r rãrr)rärŽr¬rÚ visit_BoolOp~s   z_Unparser.visit_BoolOpcCsZ| tj|j¡| |j¡t|jtƒr@t|jjtƒr@| d¡| d¡| |j ¡dS)NrnrC) r*rèrür%r/rr#r&rr{r(rrrÚ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#r$FrST) r*rèrür8r/r r;rr<)r¬r rvrwrrrÚ 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")rÚStarred)rUrÂrrrrY±rZzE_Unparser.visit_Subscript..is_simple_tuple..)rr1r3Úany)Ú slice_valuerrrÚis_simple_tupleªs  ÿýz2_Unparser.visit_Subscript..is_simple_tupler¾r¿) r*rèrür%r/r rØrr3)r¬r rrrrÚvisit_Subscript©s   z_Unparser.visit_SubscriptcCs*| d¡| tj|j¡| |j¡dS)Nr)rr*rèròr%r/r(rrrÚ visit_Starred¼s z_Unparser.visit_StarredcCs| d¡dS)Nr½rr(rrrÚvisit_EllipsisÁsz_Unparser.visit_EllipsiscCsN|jr| |j¡| d¡|jr.| |j¡|jrJ| d¡| |j¡dS)Nr)Úlowerr/rÚupperÚstepr(rrrÚ visit_SliceÄs    z_Unparser.visit_SlicecCs,| |j¡|jr(| d¡| |j¡dSrÒ)rÚargrLr/r(rrrÚ 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) NTrPFrSú=z, /rrKrÖ)Ú posonlyargsr;r>ÚdefaultsÚ enumeraterBrr/ÚvarargÚ kwonlyargsr&rLÚ kw_defaultsÚkwarg) r¬r r¡Úall_argsr*rËÚelementsÚaÚdrrrÚvisit_argumentsÔsN                z_Unparser.visit_argumentscCs<|jdur| d¡n| |j¡| d¡| |j¡dS)NrÖr()r&rr/r%r(rrrÚ visit_keywords     z_Unparser.visit_keywordcCsn| tj|¡L| d¡| |j¡| d¡| tj|j¡| |j¡Wdƒn1s`0YdS)Nzlambda rK)r'rèrírr/r;r*rLr(rrrÚ visit_Lambdas    z_Unparser.visit_LambdacCs&| |j¡|jr"| d|j¡dS©Nrp)rriÚasnamer(rrrÚ visit_aliass z_Unparser.visit_aliascCs,| |j¡|jr(| d¡| |j¡dSr7)r/Ú context_exprÚ optional_varsrr(rrrÚvisit_withitems  z_Unparser.visit_withitem)rR)wrbr¹rºr»rÆr rrrrrÚpropertyrrrr r"r'r%r*r+r.r/r¯r4r9r=r>r@rBrErHrJrMrOrRrTrVrWrZr\r]r_rarbrfrnrqrxr|r}r{r‚rƒrr†r‡r‰rŠr£rr r§r©r¢r­r¨rµr2r¼r¸rÀrÆrÈrÉrÊrÏrÐrÑrÙrÚrárèrðrùrârårIr÷rørörórôrõrúrùÚ frozensetrúrýrrrrïrîrrrrrr r!r%r'r4r5r6r9r<Ú __classcell__rrr1rrÿžs              ÿ &   ü óóö    3rÿcCstƒ}| |¡Sr")rÿr¯)Úast_objr³rrrÚunparse"srAcCsä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)ÚprogÚinfileÚrbrú?rºz$the file to parse; defaults to stdin)r$ÚnargsÚdefaultÚhelpz-mz--moder)rÚsinglerÚ func_typez(specify what kind of code must be parsed)rGÚchoicesrHz--no-type-commentsTÚ store_falsez)don't add information about type comments)rGÚactionrHz-az--include-attributesÚ store_truez:include attributes such as line numbers and column offsets)rMrHz-iz--indentr z'indentation of nodes (number of spaces))r$rGrH)r )rmrO)ÚargparseÚArgumentParserÚ add_argumentÚFileTyper&Ú parse_argsrCÚreadrrirÚno_type_commentsÚprintrprmrO)rOÚparserr;rCrÚtreerrrÚmain's0 þ þ ÿ ÿ ÿ&rYÚ__main__)rr)TF)rP)T)Kr»ÚsysÚ_astÚ contextlibrrÚenumrrrrNrpr|rr„r†r}r“r™r›r£r‚Úobjectr©r¼rvr#rÂrÄr=rƒrŽr$rÅrÐrÑrrÕrÖr×r&r'r(rJÚbytesÚboolrÇrÈr±r[rØrÚrÜr1ràrárÞÚmodrâÚ expr_contexträrårærdÚ float_infoÚ max_10_expr»rèÚ_SINGLE_QUOTESr“r£rÿrArYrbrrrrÚsœÿ 6C#    %:<       ûÿø