Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/lib2to3/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/lib2to3/__pycache__/refactor.cpython-39.opt-2.pyc

a

��gsk�@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/local/lib/python3.9/lib2to3/refactor.py�get_all_fix_namess
rc@seZdZdS)�
_EveryNodeN��__name__�
__module__�__qualname__rrrrr+srcCs�t|tjtjf�r(|jdur 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)�pat�r�p�xrrrr/s


rc	Cs�t�t�}g}|D]v}|jrbzt|j�}WntyF|�|�Yq�0|D]}||�|�qLq|jdur~||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$

�r2cs�fdd�t�d�D�S)Ncsg|]}�d|�qS��.r)�.0�fix_name�Zpkg_namerr�
<listcomp>hs�z+get_fixers_from_package.<locals>.<listcomp>F)rr7rr7r�get_fixers_from_packageds
�r9cCs|Sr'r)�objrrr�	_identityksr;csVd}t�t�|�j���fdd�}ttjtjtj	h�}t
�}z�|�\}}||vrTq>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>Wnt�yLYn0t|�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








rWc@seZdZdS)�
FixerErrorNrrrrrrX�srXc@s�eZdZdddd�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�
exec_function�write_unchanged_filesZFixrNcCsJ||_|pg|_|j��|_|dur0|j�|�tj��|_|jdrR|jj	d=n|jdrf|jj	d=|j�
d�|_g|_t
�d�|_g|_d|_tj|jtj|jd�|_|��\|_|_g|_t��|_g|_g|_t|j|j�D]H}|j r�|j�!|�q�||jv�r|j�"|�q�||jvr�|j�"|�q�t#|j�|_$t#|j�|_%dS)	NrZ�printr[�execr\rYF)�convert�logger)&�fixers�explicit�_default_options�copy�optionsr!r	r,�grammar�keywords�getr\�errors�logging�	getLoggerr`�	fixer_log�wroterZDriverrr_�
get_fixers�	pre_order�
post_order�files�bmZ
BottomMatcher�BMZ
bmi_pre_orderZbmi_post_orderrZ
BM_compatibleZ	add_fixerrr2�bmi_pre_order_heads�bmi_post_order_heads)�selfZfixer_namesrerbr1rrr�__init__�sB



�

zRefactoringTool.__init__c	CsVg}g}|jD�]}t|iidg�}|�dd�d}|�|j�rR|t|j�d�}|�d�}|jd�dd�|D��}zt	||�}Wn$t
y�td	||f�d�Yn0||j|j
�}	|	jr�|jd
ur�||jvr�|�d|�q|�d|�|	jd
k�r|�|	�q|	jdk�r|�|	�qtd|	j��qt�d�}
|j|
d�|j|
d�||fS)Nrr4r����_�cSsg|]}|���qSr)�title)r5r%rrrr8��z.RefactoringTool.get_fixers.<locals>.<listcomp>zCan't find %s.%sTzSkipping optional fixer: %szAdding transformation: %s�preZpostzIllegal fixer order: %rZ	run_order��key)rar�rsplitr�FILE_PREFIX�len�split�CLASS_PREFIX�join�getattr�AttributeErrorrXrerlrb�log_message�	log_debug�orderr�operator�
attrgetter�sort)rvZpre_order_fixersZpost_order_fixersZfix_mod_path�modr6�parts�
class_nameZ	fix_classr1Zkey_funcrrrrn�s:
�
zRefactoringTool.get_fixerscOs�dSr'r)rv�msg�args�kwdsrrr�	log_errorszRefactoringTool.log_errorcGs|r||}|j�|�dSr')r`�info�rvr�r�rrrr�szRefactoringTool.log_messagecGs|r||}|j�|�dSr')r`�debugr�rrrr�
szRefactoringTool.log_debugcCsdSr'r)rv�old_text�new_text�filename�equalrrr�print_outputszRefactoringTool.print_outputcCs8|D].}tj�|�r$|�|||�q|�|||�qdSr')�os�path�isdir�refactor_dir�
refactor_file)rv�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 %sr4rcSsg|]}|�d�s|�qSr3)r)r5Zdnrrrr82r|z0RefactoringTool.refactor_dir.<locals>.<listcomp>)
r��extsep�walkr�r�rr��splitextr�r�)
rvZdir_namer�r�Zpy_ext�dirpath�dirnames�	filenamesr�fullnamerrrr� s

�zRefactoringTool.refactor_dirc
Cs�zt|d�}Wn4tyB}z|�d||�WYd}~dSd}~00zt�|j�d}W|��n
|��0tj|d|dd��}|��|fWd�S1s�0YdS)N�rbzCan't open %s: %s)NNrr$rz��encoding�newline)	�open�OSErrorr�r�detect_encodingrH�closerF�read)rvr��f�errr�rrr�_read_python_source4sz#RefactoringTool._read_python_sourcecCs�|�|�\}}|durdS|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 %srx)r�r�zNo changes in %s)r�r��refactor_docstringr\�processed_file�refactor_string�was_changed�str)rvr�r�r��inputr��output�treerrrr�Ds �zRefactoringTool.refactor_filec
Cs�t|�}d|vrtj|j_zfz|j�|�}WnFtyr}z.|�d||jj	|�WYd}~W|j|j_dSd}~00W|j|j_n|j|j_0||_
|�d|�|�||�|S)NrZzCan't parse %s: %s: %szRefactoring %s)
rWr	Z!python_grammar_no_print_statementrrfZparse_stringr"r��	__class__r�future_featuresr��
refactor_tree)rv�datarrTr�r�rrrr�[s"

�
�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�r\r�r�r�r�)rvr�r�r�r�rrr�refactor_stdinvs

zRefactoringTool.refactor_stdinc

Cs�t|j|j�D]}|�||�q|�|j|���|�|j|���|j�|�	��}t
|����r�|jjD�]B}||vrj||rj||j
tjjdd�|jr�||j
tjjd�t||�D]�}|||vr�||�|�zt|�Wnt�y�Yq�Yn0|j�r||jv�rq�|�|�}|r�|�||�}|dur�|�|�|��D] }|j�s\g|_|j�|��qJ|j�|�	��}|D]*}	|	|v�r�g||	<||	�||	��q�q�qjqTt|j|j�D]}|�||��q�|jS)NT)r�reverser~)rrorpZ
start_tree�traverse_byrtrurs�runZleaves�anyr-rar�rZBase�depthZkeep_line_orderZ
get_linenor*�remover�
ValueErrorZfixers_applied�match�	transform�replacerr/Zfinish_treer�)
rvr�rr1Z	match_set�node�results�newZnew_matchesZfxrrrrr��sJ



zRefactoringTool.refactor_treecCsV|sdS|D]D}||jD]4}|�|�}|r|�||�}|dur|�|�|}qqdSr')rr�r�r�)rvraZ	traversalr�r1r�r�rrrr��s

zRefactoringTool.traverse_bycCs�|j�|�|dur.|�|�d}|dur.dS||k}|�||||�|r`|�d|�|js`dS|rv|�||||�n|�d|�dS)NrzNo changes to %szNot writing changes to %s)rqrr�r�r�r\�
write_file)rvr�r�r�r�r�r�rrrr��szRefactoringTool.processed_filecCs�ztj|d|dd�}Wn4tyJ}z|�d||�WYd}~dSd}~00|�Rz|�|�Wn2ty�}z|�d||�WYd}~n
d}~00Wd�n1s�0Y|�d|�d|_dS)N�wrzr�zCan't create %s: %szCan't write %s: %szWrote changes to %sT)rFr�r�r�r�r�rm)rvr�r�r�r��fpr�rrrr�sBzRefactoringTool.write_filez>>> z... c
	Csg}d}d}d}d}|jdd�D]�}|d7}|���|j�r~|durZ|�|�||||��|}|g}|�|j�}	|d|	�}q |dur�|�||j�s�|||j��dkr�|�	|�q |dur�|�|�||||��d}d}|�	|�q |du�r
|�|�||||��d�
|�S)NrT��keependsrr�rz)�
splitlines�lstripr�PS1r/�refactor_doctest�find�PS2�rstriprr�)
rvr�r��result�blockZblock_lineno�indent�lineno�line�irrrr�sD����
�z"RefactoringTool.refactor_docstringc

sz��||��}Wnhtyz}zP�j�tj�rL|D]}��d|�d��q4��d|||j	j
|�|WYd}~Sd}~00��||��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�rrxrcsg|]}��j|�qSr)r�)r5r��r�rvrrr8^r|z4RefactoringTool.refactor_doctest.<locals>.<listcomp>)�parse_blockr"r`�isEnabledForrj�DEBUGr�r�r�r�rr�r�r��endswithr��pop)
rvr�r�r�r�r�r�r�r�Zclippedrr�rr�Ds&�"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|g|�Ri|��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:)rmrqr�rlrir�)rvr��file�messager�r�r�rrr�	summarizeas$


zRefactoringTool.summarizecCs"|j�|�|||��}t�|_|Sr')rZparse_tokens�	wrap_toksrIr�)rvr�r�r�r�rrrr�xszRefactoringTool.parse_blockccsdt�|�||�j�}|D]F\}}\}}\}	}
}||d7}|	|d7}	||||f|	|
f|fVqdS)Nr)rrE�	gen_lines�__next__)rvr�r�r�r.rrVZline0Zcol0Zline1Zcol1Z	line_textrrrr��s
zRefactoringTool.wrap_toksccsx||j}||j}|}|D]N}|�|�r>|t|�d�Vn(||��dkrVdVntd||f��|}qdVqldS)Nr�zline=%r, prefix=%rrz)r�r�rr�r��AssertionError)rvr�r��prefix1Zprefix2�prefixr�rrrr��s


zRefactoringTool.gen_lines)NN)FF)FF)FF)F)NFN)N)rrrrcr�r�rwrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrY�s@�
7(
	


O�

+
rYc@seZdZdS)�MultiprocessingUnsupportedNrrrrrr��sr�csBeZdZ�fdd�Zd�fdd�	Z�fdd�Z�fd	d
�Z�ZS)�MultiprocessRefactoringToolcs&tt|�j|i|��d|_d|_dSr')�superr�rw�queue�output_lock�rvr��kwargs�r�rrrw�sz$MultiprocessRefactoringTool.__init__Frc
s>|dkrtt���|||�Szddl�Wnty>t�Yn0�jdurRtd������_��	��_
��fdd�t|�D�}zn|D]}|��q�tt���|||�W�j�
�t|�D]}�j�d�q�|D]}|��r�|�
�q�d�_nL�j�
�t|�D]}�j�d��q|D]}|���r|�
��qd�_0dS)Nrrz already doing multiple processescsg|]}�j�jd��qS))�target)�Process�_child)r5r���multiprocessingrvrrr8�s�z8MultiprocessRefactoringTool.refactor.<locals>.<listcomp>)r�r�r�r�ImportErrorr�r��RuntimeError�
JoinableQueue�Lockr��range�startr��put�is_alive)rvr�r�r�Z
num_processes�	processesr%r�rrrr��sF
�



�
�

�

z$MultiprocessRefactoringTool.refactorcs\|j��}|durX|\}}z$tt|�j|i|��W|j��n|j��0|j��}q
dSr')r�rhr�r�r��	task_done)rvZtaskr�r�rrrr�s

��z"MultiprocessRefactoringTool._childcs6|jdur|j�||f�ntt|�j|i|��SdSr')r�rr�r�r�r�rrrr��s

��z)MultiprocessRefactoringTool.refactor_file)FFr)rrrrwr�rr��
__classcell__rrrrr��s�r�)T)"�
__author__rFr�rr�rjr�r(�	itertoolsrZpgen2rrrZ
fixer_utilrrzrr	r
rrrr"rrr2r9r;rWrX�objectrYr�r�rrrr�<module>s6
(


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists