????
Your IP : 3.141.244.160
o
�?Og���@s�dZddlZddlTddlmZmZddlmZmZd`ddd �d
d�Z dd
�Z
dadd�dd�Zdd�Zdd�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%Gd<d=�d=ee!d7�Z&Gd>d?�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��s"dHdI�Z6dJdK�Z7ee6e7�e5_8GdLdM�dMe9�Z:GdNdO�dOe;�Z<GdPdQ�dQe;�Z=GdRdS�dSe;�Z>dTe?ej@jAd�ZBGdUdV�dVe�ZCdWZDdXZEgeD�eE�RZFGdYdZ�dZe�ZGd[d\�ZHd]d^�ZIeJd_k�ryeI�dSdS)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� <unknown>�execF)�
type_comments�feature_versioncCsRt}|r|tO}t|t�r|\}}|dksJ�|}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/python310/lib64/python3.10/ast.py�parse!s
�rcsft|t�rt|�d�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.
z �eval�rcSs4d}t|dd�}r|d|��7}t|d|����)Nzmalformed node or string�linenoz on line �: )�getattr�
ValueError)�node�msg�lnorrr�_raise_malformed_nodeCsz+literal_eval.<locals>._raise_malformed_nodecs,t|t�rt|j�tttfvr�|�|jS�N)r�Constant�type�value�int�float�complex�r )r#rr�_convert_numHsz"literal_eval.<locals>._convert_numcsDt|t�rt|jttf�r�|j�}t|jt�r|
S|S�|�Sr$)rZUnaryOp�op�UAdd�USub�operand)r r0)r,rr�_convert_signed_numLs
z)literal_eval.<locals>._convert_signed_numcsLt|t�r|jSt|t�rtt�|j��St|t�r"tt�|j��St|t �r/t
t�|j��St|t�rOt|jt
�rO|jjdkrO|j|jkrNgkrOt
�St|t�rqt|j�t|j�krb�|�ttt�|j�t�|j���St|t�r�t|jttf�r��|j�}�|j�}t|ttf�r�t|t�r�t|jt�r�||S||S�|�S)N�set) rr%r'�Tupler�map�eltsZList�list�Setr2ZCall�func�Name�id�args�keywordsZDict�len�keys�values�dict�zipZBinOpr-�Add�Sub�left�rightr(r)r*)r rDrE��_convertr,r1r#rrrGTs4
"�
�
zliteral_eval.<locals>._convert)r�strr�lstripZ
Expression�body)Znode_or_stringrrFr�literal_eval6s
rKT)�indentcsTd����fdd� �t|t�std|jj���dur$t�t�s$d���|�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}Yq+w| durOt||d�durOd}q+�| ��\} }
|oY|
}|rf|�d|| f�q+|�| �q+�r�|jr�|jD]4}zt||�} Wn ty�Yqtw| dur�t||d�dur�qt�| ��\} }
|o�|
}|�d|| f�qt|r�t|�d kr�d
|j j
d�|�f|fSd|j j
||�|�fdfSt|t�r�|s�d
Sd||���fdd�|D��fdfSt
|�dfS)N��
z,
��, T.z%s=%srz%s(%s)z%s(%s%s)F)z[]Tz[%s%s]c3s�|]
}�|��dVqdS�rNr)�.0�x)�_format�levelrr� <genexpr>�s�z(dump.<locals>._format.<locals>.<genexpr>)r�ASTr&�_fieldsr�AttributeError�append�_attributesr=� __class__�__name__�joinr6�repr)r rU�prefix�sep�clsr;Z allsimpler<�namer'�simple�rT�annotate_fields�include_attributesrL)rUrrT}s\
�
�
&zdump.<locals>._formatzexpected AST, got %rN� )r)rrW� TypeErrorr\r]rH)r rfrgrLrrer�dumpqs
0rjcCsVdD]&}||jvr(||jvr(t||d�}|dus"t||�r(|�d�r(t|||�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*.
)r�
col_offset�
end_lineno�end_col_offsetNZend_)r[r�hasattr�
startswith�setattr)�new_nodeZold_node�attrr'rrr�
copy_location�s���rscs �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|jvrt|d�s||_n|j}d|jvr%t|dd�dur"||_n|j}d|jvr6t|d�s3||_n|j}d|jvrJt|dd�durG||_n|j}t|�D]
}�|||||�qNdS)Nrrlrkrm)r[rnrrrlrkrm�iter_child_nodes)r rrkrlrm�child��_fixrrrw�s&
�z#fix_missing_locations.<locals>._fixrMrrr+rrvr�fix_missing_locations�srxrMcCstt|�D]3}t|t�rt|dd�||_qd|jvr#t|dd�||_d|jvr7t|dd�}dur7|||_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.
rrrlN)�walkrZ
TypeIgnorerrr[rl)r �nrurlrrr�increment_lineno�s
�r{c cs8�|jD]}z
|t||�fVWqtyYqwdS)zs
Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields``
that is present on *node*.
N)rXrrY)r �fieldrrr�iter_fields�s�
��r}ccsN�t|�D]\}}t|t�r|Vqt|t�r$|D]
}t|t�r#|VqqdS)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}rrWr6)r rcr|�itemrrrrts�
��rtcCs�t|ttttf�std|jj��|jrt|jdt �sdS|jdj
}t|t�r-|j}nt|t
�r<t|j
t�r<|j
}ndS|rIddl}|�|�}|S)aC
Return the docstring for the given node or None if no docstring can
be found. If the node provided does not have docstrings a TypeError
will be raised.
If *clean* is `True`, all tabs are expanded to spaces and any whitespace
that can be uniformly removed from the second line onwards is removed.
z%r can't have docstringsrN)r�AsyncFunctionDef�FunctionDef�ClassDef�Modulerir\r]rJ�Exprr'�Str�sr%rH�inspectZcleandoc)r Zclean�textr�rrr�
get_docstrings
r�cCs�d}g}d}|t|�krA||}||7}|d7}|dkr0|t|�kr0||dkr0|d7}|d7}|dvr;|�|�d}|t|�ks|rH|�|�|S)z}Split a string into lines ignoring form feed and other chars.
This mimics how the Python parser splits source code.
rrOrM�
rNz
)r=rZ)r�idx�linesZ next_line�crrr�_splitlines_no_ff3s"
�
r�cCs,d}|D]}|dvr||7}q|d7}q|S)z6Replace all chars except '\f\t' in a line with spaces.rOz rhr)r�resultr�rrr�_pad_whitespaceLs
r�)�paddedcCsz|jdus|jdurWdS|jd}|jd}|j}|j}Wn
ty)YdSwt|�}||kr>||��||���S|rOt||��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.
NrMrOr)rlrmrrkrYr��encode�decoder��insertrZr^)rr r�rrlrkrmr�Zpadding�firstZlastrrr�get_source_segmentWs,
�
r�ccsD�ddlm}||g�}|r |��}|�t|��|V|sdSdS)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�extendrt)r r�Ztodorrrry|s�
�ryc@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_)r\r]r�
generic_visit)�selfr �method�visitorrrr�visit�szNodeVisitor.visitcCsTt|�D]#\}}t|t�r|D]}t|t�r|�|�qqt|t�r'|�|�qdS)z9Called if no explicit visitor function exists for a node.N)r}rr6rWr�)r�r r|r'r~rrrr��s
��
��zNodeVisitor.generic_visitc Cs�|j}t�t|��}|dur t��D]
\}}t||�r|}nq|durKd|}zt||�}Wn ty8Ynwddl}|� |�d�t
d�||�S|�|�S)Nr�rz" is deprecated; add visit_Constant�)r'�_const_node_type_names�getr&�itemsrrrY�warnings�warn�DeprecationWarningr�) r�r r'Z type_namerbrcr�r�r�rrr�visit_Constant�s*
���
zNodeVisitor.visit_ConstantN)r]�
__module__�__qualname__�__doc__r�r�r�rrrrr��s
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]P\}}t|t�r:g}|D]!}t|t�r-|�|�}|dur"qt|t�s-|�|�q|�|�q||dd�<qt|t�rT|�|�}|durNt||�qt|||�q|Sr$) r}rr6rWr�r�rZ�delattrrp)r�r r|� old_valueZ
new_valuesr'rqrrrr��s(
�zNodeTransformer.generic_visitN)r]r�r�r�r�rrrrr��s#r�rzcC�|jS)zDeprecated. Use value instead.�r'�r�rrr�_getter�r�cC�
||_dSr$r��r�r'rrr�_setter�
r�c@seZdZdd�Zdd�ZdS)�_ABCcGs
d|_dS)Nz3Deprecated AST node class. Use ast.Constant instead)r�)rbr;rrr�__init__r�z
_ABC.__init__cCsdt|t�sdS|tvr,z|j}Wn
tyYdSwt|t|�o+t|t�|d��St�||�S)NFr) rr%�_const_typesr'rY�_const_types_notr�r&�__instancecheck__)rb�instr'rrrr�s
��z_ABC.__instancecheck__N)r]r�r�r�r�rrrrr�sr�cOsp|D]}||jvr
q|j�|�}|t|�kr t|j�d|����q|tvr,t|i|��Stj|g|�Ri|��S)Nz" got multiple values for argument )rX�indexr=rir]r�r%�__new__)rbr;�kwargs�key�posrrr�_new"s
�r�c@�eZdZdZeZdS)�Num)rzN�r]r�r�rXr�r�rrrrr�.�r�)� metaclassc@r�)r��r�Nr�rrrrr�2r�r�c@r�)�Bytesr�Nr�rrrrr�6r�r�c@seZdZeZdS)�NameConstantN)r]r�r�r�r�rrrrr�:�r�c@r�)�EllipsisrcOs6|turtdg|�Ri|��Stj|g|�Ri|��S)N.)r�r%r�)rbr;r�rrrr�@szEllipsis.__new__N)r]r�r�rXr�rrrrr�=sr�.c@�eZdZdZdS)�slicezDeprecated AST node class.N�r]r�r�r�rrrrr�[r�r�c@r�)�Indexz@Deprecated AST node class. Use the index value directly instead.cKs|Sr$r)rbr'r�rrrr�`sz
Index.__new__N�r]r�r�r�r�rrrrr�^sr�c@seZdZdZddd�ZdS)�ExtSlicez1Deprecated AST node class. Use ast.Tuple instead.rcKstt|�t�fi|��Sr$)r3r6ZLoad)rb�dimsr�rrrr�eszExtSlice.__new__N)rr�rrrrr�csr�r�cCr�)zDeprecated. Use elts instead.�r5r�rrr�_dims_gettermr�r�cCr�r$r�r�rrr�_dims_setterqr�r�c@r�)�Suite�/Deprecated AST node class. Unused in Python 3.Nr�rrrrr�vr�r�c@r�)�AugLoadr�Nr�rrrrr�yr�r�c@r�)�AugStorer�Nr�rrrrr�|r�r�c@r�)�Paramr�Nr�rrrrr�r�r�Z1ec@s�eZdZdZe�Ze�Ze�Ze�Ze�Z e�Z
e�Ze�ZeZ
e�Ze�Ze�Ze�Ze�Ze�Ze�Ze�Ze�Zdd�ZdS)�_Precedencez5Precedence table that originated from python grammar.cCs(z|�|d�WSty|YSw�NrM)r\rr�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'''cseZdZdZdd�dd�Zdd�Zdd �Zd
d�Zd�d
d�Zdd�Z dd�Z
edd��Ze
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�Z<e;dt�dudv�Z=dwdx�Z>dydz�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�dDŽZid�dɄZjd�d˄Zkd�d̈́Zld�dτZmd�dфZnd�dӄZod�dՄZpd�dׄZqd�dلZrd�dۄZsd�d݄Ztd�d߄Zud�d�Zvd�d�Zwd�d�Zxd�d�Zyd�d�Zzd�d�Z{d�d�Z|d�d�Z}d�d�Z~d�d�Z�Z�S)�� _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__cCsJt|�}z|t|��Wn
tyYdSw|D] }|�||�qdS)z7Call f on each item in seq, calling inter() in between.N)�iterr��
StopIteration)r�Zinter�f�seqrSrrr�
interleave�s�
�z_Unparser.interleavecs@t|�dkr||d���d�dS���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.rMr�,c�
��d�S�NrP��writerr�rr�<lambda>��
z&_Unparser.items_view.<locals>.<lambda>N)r=rr)r�Z traverserr�rr�r�
items_view�sz_Unparser.items_viewcCs|jr
|�d�dSdS)z8Adds a newline if it isn't the start of generated sourcerNN)r�rr�rrr�
maybe_newline�s�z_Unparser.maybe_newlinerOcCs |��|�d|j|�dS)zXIndent a piece of text and append it, according to the current
indentation levelz N)r
rr��r�r�rrr�fill�sz_Unparser.fillcCs|j�|�dS)zAppend a piece of textN)r�rZrrrrr�sz_Unparser.writecCs|j�|�dSr$)r�rZrrrr�
buffer_writer��z_Unparser.buffer_writercCsd�|j�}|j��|S)NrO)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.
�:rMN)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�Sr$)rr)r�rr� conditionrrr�
delimit_if�sz_Unparser.delimit_ifcCs|�dd|�|�|k�S)z,Shortcut to adding precedence related parens�(�))r�get_precedence)r��
precedencer rrr�require_parenssz_Unparser.require_parenscCs|j�|tj�Sr$)r�r�r�r��r�r rrrrrz_Unparser.get_precedencecGs|D]}||j|<qdSr$)r�)r�rZnodesr rrr�set_precedences�z_Unparser.set_precedencecCsdt|ttttf�rt|j�dkrdS|jd}t|t�sdS|j}t|t �r.t|jt
�r0|SdSdS)z�If a docstring node is found in the body of the *node* parameter,
return that docstring node, None otherwise.
Logic mirrored from ``_PyAST_GetDocString``.rMNr)rrr�r�r�r=rJr�r'r%rHrrrr�get_raw_docstrings�
�z_Unparser.get_raw_docstringcCs*|j�|j�p |j}|durd|��SdS)Nz # type: )r�r�r�type_comment)r�r Zcommentrrr�get_type_comments
�z_Unparser.get_type_commentcs2t|t�r|D]}|�|�qdSt��|�dSr$)rr6�traverse�superr�)r�r r~�r\rrr$!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*rO)r�r$r^rrrrr�+s
z_Unparser.visitcCs@|�|�}r|�|�|�|jdd��dS|�|j�dSr�)r!�_write_docstringr$rJ)r�r Z docstringrrr�"_write_docstring_and_traverse_body2s
z,_Unparser._write_docstring_and_traverse_bodycCs*dd�|jD�|_|�|�|j��dS)NcSsi|]
}|jd|j���qS)�ignore)r�tag)rRr)rrr�
<dictcomp>:s��z*_Unparser.visit_Module.<locals>.<dictcomp>)�type_ignoresr�r(rrrrr�visit_Module9s
�
z_Unparser.visit_Modulecs`��dd�����fdd��j|j�Wd�n1swY��d���|j�dS)Nrrcrrrrr�rrrDrz._Unparser.visit_FunctionType.<locals>.<lambda>� -> )rrr$�argtypesr�returnsrrr�r�visit_FunctionTypeAs��
z_Unparser.visit_FunctionTypecCs(|��|�tj|j�|�|j�dSr$)rr r�r�r'r$rrrr�
visit_ExprJsz_Unparser.visit_ExprcCsj|�tj|��$|�tj|j|j�|�|j�|�d�|�|j�Wd�dS1s.wYdS)Nz := ) rr�r�r r��targetr'r$rrrrr�visit_NamedExprOs
"�z_Unparser.visit_NamedExprc�(��d����fdd��j|j�dS)Nzimport crrrrr�rrrXrz(_Unparser.visit_Import.<locals>.<lambda>)rrr$�namesrrr�r�visit_ImportV�
z_Unparser.visit_ImportcsX��d���d|jpd�|jr��|j���d����fdd��j|j�dS)Nzfrom �.rz import crrrrr�rrr`rz,_Unparser.visit_ImportFrom.<locals>.<lambda>)rrrU�modulerr$r6rrr�r�visit_ImportFromZs
z_Unparser.visit_ImportFromcCsT|��|jD]}|�|�|�d�q|�|j�|�|�}r(|�|�dSdS)N� = )r�targetsr$rr'r#)r�r r3r"rrr�visit_Assignbs
�z_Unparser.visit_AssigncCsB|��|�|j�|�d|j|jjjd�|�|j�dS)Nrhz= ) rr$r3r�binopr-r\r]r'rrrr�visit_AugAssignksz_Unparser.visit_AugAssigncCs�|��|�dd|jot|jt���|�|j�Wd�n1s$wY|�d�|�|j�|j rD|�d�|�|j �dSdS)Nrrrr<)
rrrdrr3r9r$r�
annotationr'rrrr�visit_AnnAssignqs �
�z_Unparser.visit_AnnAssigncCs.|�d�|jr|�d�|�|j�dSdS)N�returnrh)rr'rr$rrrr�visit_Return{s
�z_Unparser.visit_ReturncC�|�d�dS)N�pass�rrrrr�
visit_Pass��z_Unparser.visit_PasscCrE)N�breakrGrrrr�visit_Break�rIz_Unparser.visit_BreakcCrE)N�continuerGrrrr�visit_Continue�rIz_Unparser.visit_Continuecr5)Nzdel crrrrr�rrr�rz(_Unparser.visit_Delete.<locals>.<lambda>)rrr$r=rrr�r�visit_Delete�r8z_Unparser.visit_DeletecCs:|�d�|�|j�|jr|�d�|�|j�dSdS)Nzassert rP)rr$�testr!rrrrr�visit_Assert�s
�z_Unparser.visit_Assertcr5)Nzglobal crrrrr�rrr�rz(_Unparser.visit_Global.<locals>.<lambda>�rrrr6rrr�r�visit_Global�r8z_Unparser.visit_Globalcr5)Nz nonlocal crrrrr�rrr�rz*_Unparser.visit_Nonlocal.<locals>.<lambda>rQrrr�r�visit_Nonlocal�r8z_Unparser.visit_NonlocalcC�z|�tj|��,|�d�|jr+|�d�|�tj|j�|�|j�Wd�dSWd�dS1s6wYdS)N�awaitrh)rr�r�rr'r r�r$rrrr�visit_Await��
�"�z_Unparser.visit_AwaitcCrT)N�yieldrh)rr�r�rr'r r�r$rrrr�visit_Yield�rWz_Unparser.visit_YieldcCsh|�tj|��#|�d�|jstd��|�tj|j�|�|j�Wd�dS1s-wYdS)Nzyield from z-Node can't be used without a value attribute.) rr�r�rr'rr r�r$rrrr�visit_YieldFrom�s
"�z_Unparser.visit_YieldFromcCs\|�d�|js|jrtd��dS|�d�|�|j�|jr,|�d�|�|j�dSdS)N�raisez*Node can't use cause without an exception.rhz from )r�exc�causerrr$rrrr�visit_Raise�s
�z_Unparser.visit_RaisecCs�|�d�|���|�|j�Wd�n1swY|jD]}|�|�q"|jrL|�d�|���|�|j�Wd�n1sGwY|jrq|�d�|���|�|j�Wd�dS1sjwYdSdS)N�try�else�finally)rrr$rJ�handlers�orelse� finalbody)r�r Zexrrr� visit_Try�s"
�
�
"��z_Unparser.visit_TrycCs||�d�|jr|�d�|�|j�|jr!|�d�|�|j�|���|�|j�Wd�dS1s7wYdS)N�exceptrh� as )rr&rr$rcrrJrrrr�visit_ExceptHandler�s
"�z_Unparser.visit_ExceptHandlercCs|��|jD]}|�d�|�|�q|�d|j�|jdd|jp%|jd��4d}|jD]}|r8|�d�nd}|�|�q.|jD]}|rM|�d�nd}|�|�qCWd�n1s_wY|� ��|�
|�Wd�dS1sywYdS) N�@zclass rr)rFrPT)r
�decorator_listrr$rcr�basesr<rrr()r�r �deco�comma�errr�visit_ClassDef�s,
��
"�z_Unparser.visit_ClassDefcC�|�|d�dS)N�def��_function_helperrrrr�visit_FunctionDef�rz_Unparser.visit_FunctionDefcCrp)Nz async defrrrrrr�visit_AsyncFunctionDef�rz _Unparser.visit_AsyncFunctionDefcCs�|��|jD]}|�d�|�|�q|d|j}|�|�|�dd��|�|j�Wd�n1s7wY|jrJ|�d�|�|j�|j |�
|�d��|�|�Wd�dS1sdwYdS)Nrirhrrr.r)r
rjrr$rcrr;r0rrr#r()r�r Zfill_suffixrlZdef_strrrrrs�s
�
"�z_Unparser._function_helpercC�|�d|�dS)Nzfor ��_for_helperrrrr� visit_Forrz_Unparser.visit_ForcCrv)Nz
async for rwrrrr�visit_AsyncForrz_Unparser.visit_AsyncForcCs�|�|�|�|j�|�d�|�|j�|j|�|�d��|�|j�Wd�n1s0wY|jrZ|�d�|���|�|j�Wd�dS1sSwYdSdS)N� in rr`) rr$r3rr�rr#rJrc)r�rr rrrrxs
�
"��z_Unparser._for_helpercCs4|�d�|�|j�|���|�|j�Wd�n1s wY|jrst|j�dkrst|jdt�rs|jd}|�d�|�|j�|���|�|j�Wd�n1s\wY|jrst|j�dkrst|jdt�s7|jr�|�d�|���|�|j�Wd�dS1s�wYdSdS)Nzif rMrzelif r`) rr$rOrrJrcr=rZIfrrrr�visit_Ifs&
�$
�$�
"��z_Unparser.visit_IfcCs�|�d�|�|j�|���|�|j�Wd�n1s wY|jrJ|�d�|���|�|j�Wd�dS1sCwYdSdS)Nzwhile r`)rr$rOrrJrcrrrr�visit_While,s
�
"��z_Unparser.visit_Whilec�h��d����fdd��j|j��j��|�d����|j�Wd�dS1s-wYdS)Nzwith crrrrr�rrr8rz&_Unparser.visit_With.<locals>.<lambda>r�rrr$r�rr#rJrrr�r�
visit_With6�
"�z_Unparser.visit_Withcr~)Nzasync with crrrrr�rrr>rz+_Unparser.visit_AsyncWith.<locals>.<lambda>rrrrr�r�visit_AsyncWith<r�z_Unparser.visit_AsyncWith��quote_types�escape_special_whitespacecs��fdd�}d�t|����|}d�vrdd�|D�}�fdd�|D�}|sAt���t�fdd �|D��d
�}�dd�|gfS�rm|j�fd
d�d�|d
d
�dkrmt|d
�dksaJ��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|��s|�d��d�S|S)Nz
�\Zunicode_escape�ascii)�isprintabler�r�)r�)r�rr�escape_charHs
z2_Unparser._str_literal_helper.<locals>.escape_charrOrNcSsg|]}|tvr|�qSr)�
_MULTI_QUOTES�rR�qrrr�
<listcomp>U�z1_Unparser._str_literal_helper.<locals>.<listcomp>csg|]}|�vr|�qSrrr���escaped_stringrrr�Vr�c3s �|]}�d|vr|VqdSrQrr�)�stringrrrV\s�z0_Unparser._str_literal_helper.<locals>.<genexpr>rrMrcs|d�dkS)Nrrr)r�r�rrr`sz/_Unparser._str_literal_helper.<locals>.<lambda>)r�rNr�)r^r4r_r��sortr=)r�r�r�r�r�Zpossible_quotesZquoter)r�r�r�r�_str_literal_helperBs
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)r�r)r�r�r��
quote_typerrr�_write_str_avoiding_backslasheshsz)_Unparser._write_str_avoiding_backslashesc Cs�|�d�|jr|�||j�|�|j�dSg}|jD]}t|dt|�j �}|||j�|�
|jt|t�f�qg}t
}|D]\}}|j|||d�\}}|�
|�q@d�|�}|d}|�|�|�|���dS)Nr�� _fstring_r�rOr)rr��_fstring_JoinedStrr
r�rr?rr&r]rZrr%�_ALL_QUOTESr�r^) r�r rr'�methZ
new_bufferr�Zis_constantr�rrr�visit_JoinedStrns*
�
z_Unparser.visit_JoinedStrcCs(|�d�|�||j�|�|j�dS)Nr�)r�_fstring_FormattedValuer
r�rrrrr�visit_FormattedValue�s
z_Unparser.visit_FormattedValuecCs.|jD]}t|dt|�j�}|||�qdS)Nr�)r?rr&r])r�r rr'r�rrrr��s
�z_Unparser._fstring_JoinedStrcCs6t|jt�s
td��|j�dd��dd�}||�dS)Nz.Constants inside JoinedStr should be a string.�{z{{�}z}})rr'rHr�replace)r�r rr'rrr�_fstring_Constant�sz_Unparser._fstring_ConstantcCs�|d�t|�dd�}|�tj��|j�|�|j�}|�d�r$|d�d|vr,td��||�|j dkrIt
|j �}|dvrBtd ��|d
|���|jra|d�t|dt|j�j
�}||j|�|d
�dS)Nr�Tr�rhr�z5Unable to avoid backslash in f-string expression partrZsrazUnknown f-string conversion.�!rr�r�)r&r r�r�r�r'r�ror�
conversion�chr�format_specrr])r�r r�unparser�exprr�r�rrrr��s&
z!_Unparser._fstring_FormattedValuecC�|�|j�dSr$)rr:rrrr�
visit_Name�rz_Unparser.visit_NamecCs0|��|jdkr|�d�|j|jtd�dS)N�ur�)r�kindrr�r'r�rrrrr'�s
z_Unparser._write_docstringc
Csnt|ttf�r|�t|��dt��ddt�dt�d���dS|jr.t|t�r.|� |�dS|�t|��dS)N�inf�nanr�-r)
rr)r*rr_r��_INFSTRr�rHr�r�rrr�_write_constant�s�z_Unparser._write_constantcCs�|j}t|t�r(|�dd��|�|j|�Wd�dS1s!wYdS|dur3|�d�dS|jdkr=|�d�|�|j�dS)Nrr.�...r�)r'rrrr r�rr�)r�r r'rrrr��s
"�
z_Unparser.visit_Constantc�L��dd�����fdd��j|j�Wd�dS1swYdS)N�[�]crrrrr�rrr�rz&_Unparser.visit_List.<locals>.<lambda>)rrr$r5rrr�r�
visit_List�s"�z_Unparser.visit_ListcC�T|�dd��|�|j�|jD]}|�|�qWd�dS1s#wYdS)Nr�r��rr$�elt�
generators�r�r �genrrr�visit_ListComp��
�"�z_Unparser.visit_ListCompcCr��Nrrr�r�rrr�visit_GeneratorExp�r�z_Unparser.visit_GeneratorExpcCr�)Nr�r�r�r�rrr�
visit_SetComp�r�z_Unparser.visit_SetCompcCsj|�dd��%|�|j�|�d�|�|j�|jD]}|�|�qWd�dS1s.wYdS)Nr�r�r)rr$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�|�|�q9dS)Nz async for z for r{� if )�is_asyncrr r�r�r3r$r�r�r��ifs)r�r Z if_clauserrr�visit_comprehension�s
�z_Unparser.visit_comprehensioncCs�|�tj|��9|�tj��|j|j�|�|j�|�d�|�|j�|�d�|�tj|j �|�|j �Wd�dS1sCwYdS)Nr�z else )
rr�r�r r�rJrOr$rrcrrrr�visit_IfExps
"�z_Unparser.visit_IfExpcs`|jr)��dd�����fdd��j|j�Wd�dS1s"wYdS��d�dS)Nr�r�crrrrr�rrrrz%_Unparser.visit_Set.<locals>.<lambda>z{*()})r5rrr$rrrr�r� visit_Sets
"�z_Unparser.visit_Setcsl�fdd����fdd�}��dd�����fdd�|t|j|j��Wd�dS1s/wYdS) Ncs"��|���d���|�dS�Nr�r$r)�k�vr�rr�write_key_value_pairs
z2_Unparser.visit_Dict.<locals>.write_key_value_paircsD|\}}|dur��d���tj|���|�dS�||�dS)N�**)rr r�r�r$)r~r�r��r�r�rr�
write_items
z(_Unparser.visit_Dict.<locals>.write_itemr�r�crrrrr�rrr'rz&_Unparser.visit_Dict.<locals>.<lambda>)rrrAr>r?)r�r r�rr�r�
visit_Dicts�"�z_Unparser.visit_DictcCsB|�dd��|�|j|j�Wd�dS1swYdSr�)rr r$r5rrrr�visit_Tuple*s"�z_Unparser.visit_Tuple�~�not�+r�)ZInvertZNotr.r/)r�r�r�r�cCs�|j|jjj}|j|}|�||��%|�|�|tjur#|�d�|� ||j
�|�|j
�Wd�dS1s;wYdS�Nrh)�unopr-r\r]�unop_precedencerrr�r�r r0r$)r�r �operator�operator_precedencerrr�
visit_UnaryOp6s
"�z_Unparser.visit_UnaryOprri�/�%�<<�>>�|�^�&�//r�)
rBrCZMultZMatMultZDivZModZLShiftZRShiftZBitOrZBitXorZBitAndZFloorDivZPow)
r�r�rrir�r�r�r�r�r�r�r�r�)r�cCs�|j|jjj}|j|}|�||��>||jvr |��}|}n|}|��}|�||j �|�
|j �|�d|�d��|�||j�|�
|j�Wd�dS1sTwYdSr�)
r?r-r\r]�binop_precedencer�binop_rassocr�r rDr$rrE)r�r r�r�Zleft_precedenceZright_precedencerrr�visit_BinOpcs
"�z_Unparser.visit_BinOpz==z!=�<z<=�>z>=�iszis not�inznot in)
ZEqZNotEqZLtZLtEZGtZGtEZIsZIsNotZInZNotIncCs�|�tj|��=|jtj��|jg|j�R�|�|j�t|j |j�D]\}}|�
d|j|jj
d�|�|�q$Wd�dS1sGwYdSr�)rr�r�r r�rD�comparatorsr$rA�opsr�cmpopsr\r])r�r �ornrrr�
visit_Compare�s�"�z_Unparser.visit_Compare�and�or)ZAndZOr)r�r�cs��j|jjj}�j|���fdd�}���|��d|�d������fdd�||j�Wd�dS1s9wYdS)Ncs"�������|���|�dSr$)r�r r$r+)r�r�rr�increasing_level_traverse�sz9_Unparser.visit_BoolOp.<locals>.increasing_level_traverserhcs
����Sr$rr)r�r�rrr�rz(_Unparser.visit_BoolOp.<locals>.<lambda>)�boolopsr-r\r]�boolop_precedencerrr?)r�r r�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)Nrhr9)
r r�r�r'r$rr%r(rrrrrrr�visit_Attribute�s
z_Unparser.visit_AttributecCs�|�tj|j�|�|j�|�dd��5d}|jD]}|r$|�d�nd}|�|�q|jD]}|r9|�d�nd}|�|�q/Wd�dS1sLwYdS)NrrFrPT) r r�r�r8r$rr;rr<)r�r rmrnrrr�
visit_Call�s
�"�z_Unparser.visit_CallcCs�dd�}|�tj|j�|�|j�|�dd��&||j�r(|�|j|jj�n|�|j�Wd�dSWd�dS1sAwYdS)NcSs&t|t�o|jotdd�|jD��S)Ncss�|]}t|t�VqdSr$)rZStarred)rRr�rrrrV�s�zE_Unparser.visit_Subscript.<locals>.is_simple_tuple.<locals>.<genexpr>)rr3r5�any)Zslice_valuerrr�is_simple_tuple�s
��z2_Unparser.visit_Subscript.<locals>.is_simple_tupler�r�) r r�r�r'r$rr�r r5)r�r r�rrr�visit_Subscript�s
�"�z_Unparser.visit_SubscriptcCs*|�d�|�tj|j�|�|j�dS)Nr)rr r�r�r'r$rrrr�
visit_Starred�s
z_Unparser.visit_StarredcCrE)Nr�rrrrr�visit_Ellipsis�rIz_Unparser.visit_EllipsiscCsR|jr |�|j�|�d�|jr|�|j�|jr'|�d�|�|j�dSdS)Nr)�lowerr$r�upper�steprrrr�visit_Slice�s
�z_Unparser.visit_SlicecCsZ|�d�|�|j�|���|jD]}|�|�qWd�dS1s&wYdS)Nzmatch )rr$�subjectr�cases)r�r �caserrr�visit_Match�s
�"�z_Unparser.visit_MatchcCs0|�|j�|jr|�d�|�|j�dSdSr�)r�argrAr$rrrr� visit_arg��
�z_Unparser.visit_argc Cs�d}|j|j}dgt|�t|j�|j}tt||�d�D]/\}}|\}}|r,d}n|�d�|�|�|rB|�d�|�|�|t|j�krN|�d�q|jsU|j r~|rZd}n|�d�|�d�|jr~|�|jj
�|jjr~|�d�|�|jj�|j r�t|j |j�D]\}}|�d�|�|�|r�|�d�|�|�q�|j
r�|r�d}n|�d�|�d |j
j
�|j
jr�|�d�|�|j
j�dSdSdS)
NTrMFrP�=z, /rrr�)�posonlyargsr;r=�defaults� enumeraterArr$�vararg�
kwonlyargsrrA�kw_defaults�kwarg) r�r r�Zall_argsr r��elements�a�drrr�visit_arguments�sV
�
�
�z_Unparser.visit_argumentscCs<|jdur|�d�n|�|j�|�d�|�|j�dS)Nr�r)rrr$r'rrrr�
visit_keywords
z_Unparser.visit_keywordcCsp|�tj|��'|�d�|�|j�|�d�|�tj|j�|�|j�Wd�dS1s1wYdS)Nzlambda r)rr�r�rr$r;r rJrrrr�visit_Lambda$s
"�z_Unparser.visit_LambdacCs*|�|j�|jr|�d|j�dSdS�Nrg)rrc�asnamerrrr�visit_alias,s�z_Unparser.visit_aliascCs0|�|j�|jr|�d�|�|j�dSdSr)r$�context_expr�
optional_varsrrrrr�visit_withitem1rz_Unparser.visit_withitemcCsl|�d�|�|j�|jr|�d�|�|j�|���|�|j�Wd�dS1s/wYdS)Nzcase r�)rr$�pattern�guardrrrJrrrr�visit_match_case7s
"�z_Unparser.visit_match_casecCr�r$)r$r'rrrr�visit_MatchValue@rz_Unparser.visit_MatchValuecCr�r$)r�r'rrrr�visit_MatchSingletonCrz_Unparser.visit_MatchSingletoncr�)Nr�r�crrrrr�rrrIrz/_Unparser.visit_MatchSequence.<locals>.<lambda>)rrr$�patternsrrr�r�visit_MatchSequenceFs
�"�z_Unparser.visit_MatchSequencecCs&|j}|dur d}|�d|���dS)N�_r)rcr)r�r rcrrr�visit_MatchStarLsz_Unparser.visit_MatchStarc
s��fdd�}��dd��;|j}���fdd�|t||jdd��|j}|dur?|r/��d ���d
|���Wd�dSWd�dS1sJwYdS)Ncs*|\}}��|���d���|�dSr�r�)�pairr��pr�rr�write_key_pattern_pairSs
z<_Unparser.visit_MatchMapping.<locals>.write_key_pattern_pairr�r�crrrrr�rrr\rz._Unparser.visit_MatchMapping.<locals>.<lambda>T��strictrPr�)rr>rrAr �restr)r�r r&r>r)rr�r�visit_MatchMappingRs
�
�"�z_Unparser.visit_MatchMappingc
s���tj|j���|j���dd��C|j}���fdd��j|�|j}|rO�fdd�}|r6�� d����fdd�|t
||jd d
��Wd�dSWd�dS1sZwYdS)Nrrcrrrrr�rrrlrz,_Unparser.visit_MatchClass.<locals>.<lambda>cs&|\}}��|�d����|�dS)Nr)rr$)r$rrrr�rr�write_attr_patternpsz6_Unparser.visit_MatchClass.<locals>.write_attr_patternrPcrrrrr�rrrxrTr')r r�r�rbr$rr r� kwd_attrsrrA�kwd_patterns)r�r r Zattrsr+rr�r�visit_MatchClassfs(�
��"�z_Unparser.visit_MatchClasscCs�|j}|j}|dur|�d�dS|dur|�|j�dS|�tj|�� |�tj|j�|�|j�|�d|j���Wd�dS1sGwYdS)Nr"rg) rcrrrr�r�r r�r$)r�r rcrrrr�
visit_MatchAs}s"�z_Unparser.visit_MatchAscsh��tj|��#�jtj��g|j�R����fdd��j|j�Wd�dS1s-wYdS)Ncr)Nz | rrr�rrr�rz)_Unparser.visit_MatchOr.<locals>.<lambda>)rr�r�r r�r rr$rrr�r�
visit_MatchOr�s"�z_Unparser.visit_MatchOr)rO)�r]r�r�r�r�rr r
rrr
�propertyrrrrrrrr r!r#r$r�r(r-r1r2r4r7r;r>r@rBrDrHrKrMrNrPrRrSrVrYrZr^rerhrortrursryrzrxr|r}r�r�r�r�r�r�r�r�r�r�r�r'r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r?r�r�r�r�r�r�r�r�� frozensetr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrr!r#r*r.r/r0�
__classcell__rrr&rr��s4
�&
�
���
3
r�cCst�}|�|�Sr$)r�r�)Zast_objr�rrr�unparse�s
r4cCs�ddl}|jdd�}|jd|jdd�ddd d
�|jddd
ddd�|jddddd�|jddddd�|jddtddd�|��}|j�}|��}Wd�n1sTwYt||jj |j
|jd �}tt
||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:�choicesr;z--no-type-commentsTZstore_falsez)don't add information about type comments)r:�actionr;z-az--include-attributes�
store_truez:include attributes such as line numbers and column offsets)r=r;z-iz--indentrz'indentation of nodes (number of spaces))r&r:r;)r )rgrL)�argparse�ArgumentParser�add_argumentZFileTyper(�
parse_argsr6�readrrcrZno_type_comments�printrjrgrL)r?�parserr;r6rZtreerrr�main�s2�
�
�
��
�rF�__main__)rr)TF)rM)T)Kr��sysZ_ast�
contextlibrr�enumrrrrKrjrsrxr{r}rtr�r�r�r�ry�objectr�r�rnr%r�r�r1rzr�r&r�r�r�r�r�r�r�r(r)r*rH�bytes�boolr�r�r�rWr�r�r�r3r�r�r��modr�Zexpr_contextr�r�r�r_�
float_info�
max_10_expr�r�Z_SINGLE_QUOTESr�r�r�r4rFr]rrrr�<module>s��;C
#
%:
<
���m
�