AlkantarClanX12

Your IP : 3.144.89.152


Current Path : /proc/self/root/usr/lib64/python3.8/lib2to3/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.8/lib2to3/__pycache__/refactor.cpython-38.opt-2.pyc

U

e5dk�@s
dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
ddlmZddlmZmZddlmZd d
d�ZGdd
�d
e�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!dS)!z#Guido van Rossum <guido@python.org>�N)�chain�)�driver�tokenize�token)�	find_root)�pytree�pygram)�btm_matcherTcCsTt|ggdg�}g}t�|j�D].\}}}|�d�r |rD|dd�}|�|�q |S)N�*�fix_�)�
__import__�pkgutilZiter_modules�__path__�
startswith�append)Z	fixer_pkgZ
remove_prefixZpkgZ	fix_names�finder�nameZispkg�r�(/usr/lib64/python3.8/lib2to3/refactor.py�get_all_fix_namess
rc@seZdZdS)�
_EveryNodeN��__name__�
__module__�__qualname__rrrrr+srcCs�t|tjtjf�r(|jdkr t�|jhSt|tj�rH|jrDt|j�St�t|tj	�r�t
�}|jD]}|D]}|�t|��qhq`|Std|��dS)Nz$Oh no! I don't understand pattern %s)
�
isinstancerZNodePatternZLeafPattern�typerZNegatedPatternZcontent�_get_head_typesZWildcardPattern�set�update�	Exception)Zpat�r�p�xrrrr/s


rc	Cs�t�t�}g}|D]x}|jrdzt|j�}Wntk
rH|�|�Yq�X|D]}||�|�qNq|jdk	r�||j�|�q|�|�qtt	j
j��t	j
j
�D]}||�|�q�t|�S�N)�collections�defaultdict�list�patternrrrZ_accept_typerr	�python_grammarZ
symbol2number�values�tokens�extend�dict)Z
fixer_listZ
head_nodesZevery�fixerZheadsZ	node_typerrr�_get_headnode_dictKs$

�r1cs�fdd�t�d�D�S)Ncsg|]}�d|�qS��.r)�.0�fix_name�Zpkg_namerr�
<listcomp>hs�z+get_fixers_from_package.<locals>.<listcomp>F)rr6rr6r�get_fixers_from_packageds
�r8cCs|Sr&r)�objrrr�	_identityksr:csXd}t�t�|�j���fdd�}ttjtjtj	h�}t
�}z�|�\}}||krTq>q>|tjkrl|rf�q6d}q>|tjk�r6|dk�r6|�\}}|tjks�|dkr��q6|�\}}|tjks�|dkrq6|�\}}|tj
kr�|dkr�|�\}}|tjk�r4|�|�|�\}}|tj
k�s.|d	k�r"�q4|�\}}q�q>�q6q>Wntk
�rNYnXt|�S)
NFcst��}|d|dfS)Nrr)�next)�tok��genrr�advancersz(_detect_future_features.<locals>.advanceT�fromZ
__future__�import�(�,)r�generate_tokens�io�StringIO�readline�	frozensetr�NEWLINE�NL�COMMENTr �STRING�NAME�OP�add�
StopIteration)�sourceZhave_docstringr?�ignore�features�tp�valuerr=r�_detect_future_featuresosB








rVc@seZdZdS)�
FixerErrorNrrrrrrW�srWc@s�eZdZddd�ZdZdZd4dd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zd5dd�Zd6dd�Z
dd�Zd7dd�Zdd�Zd8dd�Zdd�Zd d!�Zd9d"d#�Zd:d$d%�Zd&Zd'Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�ZdS);�RefactoringToolF)�print_function�write_unchanged_filesZFixrNcCs.||_|pg|_|j��|_|dk	r0|j�|�|jdrDtj|_ntj	|_|j�
d�|_g|_t
�d�|_g|_d|_tj|jtj|jd�|_|��\|_|_g|_t��|_g|_g|_t|j|j�D]F}|j r�|j�!|�q�||jkr�|j�"|�q�||jkr�|j�"|�q�t#|j�|_$t#|j�|_%dS)NrYrZrXF)�convert�logger)&�fixers�explicit�_default_options�copy�optionsr!r	�!python_grammar_no_print_statement�grammarr+�getrZ�errors�loggingZ	getLoggerr\�	fixer_log�wroterZDriverrr[�
get_fixers�	pre_order�
post_order�files�bmZ
BottomMatcher�BMZ
bmi_pre_orderZbmi_post_orderrZ
BM_compatibleZ	add_fixerrr1�bmi_pre_order_heads�bmi_post_order_heads)�selfZfixer_namesrar^r0rrr�__init__�s>


�


zRefactoringTool.__init__c	CsXg}g}|jD�]}t|iidg�}|�dd�d}|�|j�rR|t|j�d�}|�d�}|jd�dd�|D��}zt	||�}Wn&t
k
r�td	||f�d�YnX||j|j
�}	|	jr�|jd
k	r�||jkr�|�d|�q|�d|�|	jd
k�r|�|	�q|	jdk�r|�|	�qtd|	j��qt�d�}
|j|
d�|j|
d�||fS)Nrr3r����_�cSsg|]}|���qSr)�title)r4r$rrrr7�sz.RefactoringTool.get_fixers.<locals>.<listcomp>zCan't find %s.%sTzSkipping optional fixer: %szAdding transformation: %sZpreZpostzIllegal fixer order: %rZ	run_order��key)r]r�rsplitr�FILE_PREFIX�len�split�CLASS_PREFIX�join�getattr�AttributeErrorrWrargr^�log_message�	log_debug�orderr�operator�
attrgetter�sort)rqZpre_order_fixersZpost_order_fixersZfix_mod_path�modr5�parts�
class_nameZ	fix_classr0Zkey_funcrrrri�s:
�
zRefactoringTool.get_fixerscOs�dSr&r)rq�msg�args�kwdsrrr�	log_error�szRefactoringTool.log_errorcGs|r||}|j�|�dSr&)r\�info�rqr�r�rrrr�szRefactoringTool.log_messagecGs|r||}|j�|�dSr&)r\�debugr�rrrr�	szRefactoringTool.log_debugcCsdSr&r)rq�old_text�new_text�filename�equalrrr�print_outputszRefactoringTool.print_outputcCs8|D].}tj�|�r$|�|||�q|�|||�qdSr&)�os�path�isdir�refactor_dir�
refactor_file)rq�items�write�
doctests_onlyZdir_or_filerrr�refactorszRefactoringTool.refactorc
Cs�tjd}t�|�D]�\}}}|�d|�|��|��|D]>}|�d�s>tj�|�d|kr>tj�||�}	|�	|	||�q>dd�|D�|dd�<qdS)N�pyzDescending into %sr3rcSsg|]}|�d�s|�qSr2)r)r4Zdnrrrr7.s
z0RefactoringTool.refactor_dir.<locals>.<listcomp>)
r��extsep�walkr�r�rr��splitextr~r�)
rqZdir_namer�r�Zpy_ext�dirpathZdirnames�	filenamesr�fullnamerrrr�s

�zRefactoringTool.refactor_dirc
Cs�zt|d�}Wn6tk
rD}z|�d||�WY�dSd}~XYnXzt�|j�d}W5|��Xtj|d|dd��}|��|fW5QR�SQRXdS)N�rbzCan't open %s: %s)NNrr#ru��encoding�newline)	�open�OSErrorr��closer�detect_encodingrGrE�read)rqr��f�errr�rrr�_read_python_source0s
z#RefactoringTool._read_python_sourcecCs�|�|�\}}|dkrdS|d7}|rn|�d|�|�||�}|jsL||kr`|�|||||�q�|�d|�nH|�||�}|js�|r�|jr�|jt|�dd�|||d�n|�d|�dS)N�
zRefactoring doctests in %szNo doctest changes in %srs)r�r�zNo changes in %s)r�r��refactor_docstringrZ�processed_file�refactor_string�was_changed�str)rqr�r�r��inputr��output�treerrrr�@s"�zRefactoringTool.refactor_filec
Cs�t|�}d|krtj|j_zVz|j�|�}Wn@tk
rl}z"|�d||jj	|�WY�W�dSd}~XYnXW5|j|j_X||_
|�d|�|�||�|S)NrYzCan't parse %s: %s: %szRefactoring %s)
rVr	rbrrcZparse_stringr"r��	__class__r�future_featuresr��
refactor_tree)rq�datarrSr�r�rrrr�Ws"
� zRefactoringTool.refactor_stringcCs�tj��}|rN|�d�|�|d�}|js2||krB|�|d|�q�|�d�n:|�|d�}|jsj|r~|jr~|�t	|�d|�n
|�d�dS)NzRefactoring doctests in stdinz<stdin>zNo doctest changes in stdinzNo changes in stdin)
�sys�stdinr�r�r�rZr�r�r�r�)rqr�r�r�r�rrr�refactor_stdinrs

zRefactoringTool.refactor_stdinc

Cs�t|j|j�D]}|�||�q|�|j|���|�|j|���|j�|�	��}t
|����r�|jjD�]D}||krj||rj||j
tjjdd�|jr�||j
tjjd�t||�D]�}|||kr�||�|�zt|�Wntk
�rYq�YnX|j�r||jk�rq�|�|�}|r�|�||�}|dk	r�|�|�|��D] }|j�s^g|_|j�|��qL|j�|�	��}|D]*}	|	|k�r�g||	<||	�||	��q�q�qjqTt|j|j�D]}|�||��q�|jS)NT)rx�reverserw)rrjrkZ
start_tree�traverse_byrorprn�runZleaves�anyr,r]r�rZBaseZdepthZkeep_line_orderZ
get_linenor)�remover�
ValueErrorZfixers_applied�match�	transform�replacerr.Zfinish_treer�)
rqr�rr0Z	match_set�node�results�newZnew_matchesZfxrrrrr��sJ



zRefactoringTool.refactor_treecCsV|sdS|D]D}||jD]4}|�|�}|r|�||�}|dk	r|�|�|}qqdSr&)rr�r�r�)rqr]Z	traversalr�r0r�r�rrrr��s

zRefactoringTool.traverse_bycCs�|j�|�|dkr.|�|�d}|dkr.dS||k}|�||||�|r`|�d|�|js`dS|rv|�||||�n|�d|�dS)NrzNo changes to %szNot writing changes to %s)rlrr�r�r�rZ�
write_file)rqr�r�r�r�r�r�rrrr��szRefactoringTool.processed_filecCs�ztj|d|dd�}Wn6tk
rL}z|�d||�WY�dSd}~XYnX|�Fz|�|�Wn0tk
r�}z|�d||�W5d}~XYnXW5QRX|�d|�d|_dS)N�wrur�zCan't create %s: %szCan't write %s: %szWrote changes to %sT)rEr�r�r�r�r�rh)rqr�r�r�r��fpr�rrrr��s*zRefactoringTool.write_filez>>> z... c
	Csg}d}d}d}d}|jdd�D]�}|d7}|���|j�r~|dk	rZ|�|�||||��|}|g}|�|j�}	|d|	�}q |dk	r�|�||j�s�|||j��dkr�|�	|�q |dk	r�|�|�||||��d}d}|�	|�q |dk	�r
|�|�||||��d�
|�S)NrT��keependsrr�ru)�
splitlines�lstripr�PS1r.�refactor_doctest�find�PS2�rstriprr~)
rqr�r��result�blockZblock_lineno�indent�lineno�line�irrrr�sJ����
�z"RefactoringTool.refactor_docstringc

sz��||��}Wnjtk
r|}zL�j�tj�rN|D]}��d|�d��q6��d|||j	j
|�|WY�Sd}~XYnX��||��rt|�j
dd�}|d|d�||dd�}	}|d�d�s�|dd7<��j|�d�g}|�r|��fd	d
�|D�7}|S)Nz
Source: %sr�z+Can't parse docstring in %s line %s: %s: %sTr�rrsrcsg|]}��j|�qSr)r�)r4r��r�rqrrr7Zsz4RefactoringTool.refactor_doctest.<locals>.<listcomp>)�parse_blockr"r\ZisEnabledForrf�DEBUGr�r�r�r�rr�r�r��endswithr��pop)
rqr�r�r�r�r�r�r�r�Zclippedrr�rr�@s,�"z RefactoringTool.refactor_doctestcCs�|jrd}nd}|js$|�d|�n"|�d|�|jD]}|�|�q6|jrl|�d�|jD]}|�|�q\|jr�t|j�dkr�|�d�n|�dt|j��|jD]\}}}|j|f|�|�q�dS)	N�werez
need to bezNo files %s modified.zFiles that %s modified:z$Warnings/messages while refactoring:rzThere was 1 error:zThere were %d errors:)rhrlr�rgrer{)rqr��file�messager�r�r�rrr�	summarize]s$


zRefactoringTool.summarizecCs"|j�|�|||��}t�|_|Sr&)rZparse_tokens�	wrap_toksrHr�)rqr�r�r�r�rrrr�tszRefactoringTool.parse_blockccsdt�|�||�j�}|D]F\}}\}}\}	}
}||d7}|	|d7}	||||f|	|
f|fVqdS)Nr)rrD�	gen_lines�__next__)rqr�r�r�r-rrUZline0Zcol0Zline1Zcol1Z	line_textrrrr�~s
zRefactoringTool.wrap_toksccsx||j}||j}|}|D]N}|�|�r>|t|�d�Vn(||��dkrVdVntd||f��|}qdVqldS)Nr�zline=%r, prefix=%rru)r�r�rr{r��AssertionError)rqr�r��prefix1Zprefix2�prefixr�rrrr��s


zRefactoringTool.gen_lines)NN)FF)FF)FF)F)NFN)N)rrrr_r}rzrrrir�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrX�s>�
4(
	


O�

+
rXc@seZdZdS)�MultiprocessingUnsupportedNrrrrrr��sr�csBeZdZ�fdd�Zd�fdd�	Z�fdd�Z�fd	d
�Z�ZS)�MultiprocessRefactoringToolcs"tt|�j||�d|_d|_dSr&)�superr�rr�queue�output_lock�rqr��kwargs�r�rrrr�sz$MultiprocessRefactoringTool.__init__Frc
s�|dkrtt���|||�Szddl�Wntk
r@t�YnX�jdk	rTtd������_��	��_
��fdd�t|�D�}z*|D]}|��q�tt���|||�W5�j��t|�D]}�j�
d�q�|D]}|��r�|��q�d�_XdS)Nrrz already doing multiple processescsg|]}�j�jd��qS))�target)ZProcess�_child)r4r���multiprocessingrqrrr7�s�z8MultiprocessRefactoringTool.refactor.<locals>.<listcomp>)r�r�r�r��ImportErrorr�r��RuntimeErrorZ
JoinableQueueZLockr��ranger~�putZis_alive�start)rqr�r�r�Z
num_processesZ	processesr�r$r�r�rr��s<
�



�
�

z$MultiprocessRefactoringTool.refactorcsN|j��}|dk	rJ|\}}ztt|�j||�W5|j��X|j��}q
dSr&)r�rdZ	task_doner�r�r�)rqZtaskr�r�r�rrr��s

�z"MultiprocessRefactoringTool._childcs2|jdk	r|j�||f�ntt|�j||�SdSr&)r�r�r�r�r�r�r�rrr��s

�z)MultiprocessRefactoringTool.refactor_file)FFr)rrrrrr�r�r��
__classcell__rrr�rr��s�r�)T)"�
__author__rEr�rr�rfr�r'�	itertoolsrZpgen2rrrZ
fixer_utilrrurr	r
rmrr"rrr1r8r:rVrW�objectrXr�r�rrrr�<module>s6
(