ok

Mini Shell

Direktori : /usr/lib64/python3.6/lib2to3/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/lib2to3/__pycache__/refactor.cpython-36.opt-2.pyc

3


 \=m�@s8dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZddl
mZddlmZmZddlmZd%d
d�ZGdd
�d
e�Zdd�Zdd�Zdd�Zdd�Zejd&kr�ddlZejZdd�Zdd�Z neZeZeZ dd�Z!Gdd�de�Z"Gdd �d e#�Z$Gd!d"�d"e�Z%Gd#d$�d$e$�Z&dS)'z#Guido van Rossum <guido@python.org>�N)�chain�)�driver�tokenize�token)�	find_root)�pytree�pygram)�btm_matcherTcCstt|ggdg�}tjj|j�}g}xLttj|��D]:}|jd�r2|jd�r2|rZ|dd�}|j	|dd��q2W|S)N�*�fix_z.py�����)
�
__import__�os�path�dirname�__file__�sorted�listdir�
startswith�endswith�append)Z	fixer_pkgZ
remove_prefixZpkgZ	fixer_dirZ	fix_names�name�r�(/usr/lib64/python3.6/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
�}x*|jD] }x|D]}|jt|��qlWqbW|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


r$cCs�tjt�}g}x�|D]|}|jrjyt|j�}Wntk
rJ|j|�Yq�XxB|D]}||j|�qRWq|jdk	r�||jj|�q|j|�qWx,tt	j
jj�t	j
j
�D]}||j|�q�Wt|�S)N)�collections�defaultdict�list�patternr$rrZ_accept_typerr	�python_grammarZ
symbol2number�values�tokens�extend�dict)Z
fixer_listZ
head_nodesZevery�fixerZheadsZ	node_typerrr�_get_headnode_dictKs"



r5cs�fdd�t�d�D�S)Ncsg|]}�d|�qS)�.r)�.0�fix_name)�pkg_namerr�
<listcomp>hsz+get_fixers_from_package.<locals>.<listcomp>F)r)r9r)r9r�get_fixers_from_packageds
r;cCs|S)Nr)�objrrr�	_identityksr=rcCs|jdd�S)Nz
�
)�replace)�inputrrr�_from_system_newlinesrsrAcCs tjdkr|jdtj�S|SdS)Nr>)r�linesepr?)r@rrr�_to_system_newlinests
rCcsTd}tjtj|�j���fdd�}ttjtjtj	h�}t
�}y�x�|�\}}||krVq@q@|tjkrl|rfPd}q@|tjko||dk�r,|�\}}|tjks�|dkr�P|�\}}|tjks�|dkr�P|�\}}|tj
kr�|dkr�|�\}}xJ|tjk�r(|j|�|�\}}|tj
k�s|d	k�rP|�\}}q�Wq@Pq@WWntk
�rJYnXt|�S)
NFcst��}|d|dfS)Nrr)�next)�tok)�genrr�advance�sz(_detect_future_features.<locals>.advanceT�fromZ
__future__�import�(�,)r�generate_tokens�io�StringIO�readline�	frozensetr�NEWLINE�NL�COMMENTr%�STRING�NAME�OP�add�
StopIteration)�sourceZhave_docstringrG�ignore�features�tp�valuer)rFr�_detect_future_featuressD








r^c@seZdZdS)�
FixerErrorN)rr r!rrrrr_�sr_c@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NcCs2||_|pg|_|jj�|_|dk	r0|jj|�|jdrDtj|_ntj	|_|jj
d�|_g|_t
jd�|_g|_d|_tj|jtj|jd�|_|j�\|_|_g|_tj�|_g|_g|_xXt|j|j�D]F}|j r�|jj!|�q�||jkr�|jj"|�q�||jkr�|jj"|�q�Wt#|j�|_$t#|j�|_%dS)Nrarbr`F)�convert�logger)&�fixers�explicit�_default_options�copy�optionsr&r	�!python_grammar_no_print_statement�grammarr/�getrb�errors�loggingZ	getLoggerrd�	fixer_log�wroterZDriverrrc�
get_fixers�	pre_order�
post_order�files�bmZ
BottomMatcher�BMZ
bmi_pre_orderZbmi_post_orderrZ
BM_compatibleZ	add_fixerrr5�bmi_pre_order_heads�bmi_post_order_heads)�selfZfixer_namesrirfr4rrr�__init__�s<





zRefactoringTool.__init__cCs\g}g}�x&|jD�]}t|iidg�}|jdd�d}|j|j�rV|t|j�d�}|jd�}|jdjdd�|D��}yt	||�}Wn$t
k
r�td||f��YnX||j|j
�}	|	jr�|jd	k	r�||jkr�|jd
|�q|jd|�|	jdk�r|j|	�q|	jd
k�r |j|	�qtd|	j��qWtjd�}
|j|
d�|j|
d�||fS)Nrr6r�_�cSsg|]}|j��qSr)�title)r7r)rrrr:�sz.RefactoringTool.get_fixers.<locals>.<listcomp>zCan't find %s.%sTzSkipping optional fixer: %szAdding transformation: %sZpreZpostzIllegal fixer order: %rZ	run_order)�key���)rer�rsplitr�FILE_PREFIX�len�split�CLASS_PREFIX�join�getattr�AttributeErrorr_rirorf�log_message�	log_debug�orderr�operator�
attrgetter�sort)ryZpre_order_fixersZpost_order_fixersZfix_mod_path�modr8�parts�
class_nameZ	fix_classr4Zkey_funcrrrrq�s8


zRefactoringTool.get_fixerscOs�dS)Nr)ry�msg�args�kwdsrrr�	log_errorszRefactoringTool.log_errorcGs|r||}|jj|�dS)N)rd�info)ryr�r�rrrr�szRefactoringTool.log_messagecGs|r||}|jj|�dS)N)rd�debug)ryr�r�rrrr�szRefactoringTool.log_debugcCsdS)Nr)ry�old_text�new_text�filename�equalrrr�print_outputszRefactoringTool.print_outputcCs<x6|D].}tjj|�r&|j|||�q|j|||�qWdS)N)rr�isdir�refactor_dir�
refactor_file)ry�items�write�
doctests_onlyZdir_or_filerrr�refactor#s
zRefactoringTool.refactorc
Cs�tjd}x�tj|�D]�\}}}|jd|�|j�|j�xH|D]@}|jd�rBtjj|�d|krBtjj||�}	|j	|	||�qBWdd�|D�|dd�<qWdS)N�pyzDescending into %sr6rcSsg|]}|jd�s|�qS)r6)r)r7Zdnrrrr:>sz0RefactoringTool.refactor_dir.<locals>.<listcomp>)
r�extsep�walkr�r�rr�splitextr�r�)
ryZdir_namer�r�Zpy_ext�dirpathZdirnames�	filenamesr�fullnamerrrr�,s

zRefactoringTool.refactor_dircCs�yt|d�}Wn.tk
r<}z|jd||�dSd}~XnXztj|j�d}Wd|j�Xt|d|d��}t|j	��|fSQRXdS)N�rbzCan't open %s: %srr()�encoding)NN)
�open�OSErrorr�r�detect_encodingrO�close�_open_with_encodingrA�read)ryr��f�errr�rrr�_read_python_source@s
z#RefactoringTool._read_python_sourcecCs�|j|�\}}|dkrdS|d7}|rn|jd|�|j||�}|jsL||kr`|j|||||�q�|jd|�nH|j||�}|js�|r�|jr�|jt|�dd�|||d�n|jd|�dS)Nr>zRefactoring doctests in %szNo doctest changes in %sr)r�r�zNo changes in %sr)r�r��refactor_docstringrb�processed_file�refactor_string�was_changed�str)ryr�r�r�r@r��output�treerrrr�PszRefactoringTool.refactor_filecCs�t|�}d|krtj|j_zJy|jj|�}Wn4tk
r`}z|jd||jj	|�dSd}~XnXWd|j|j_X||_
|jd|�|j||�|S)NrazCan't parse %s: %s: %szRefactoring %s)
r^r	rjrrkZparse_stringr'r��	__class__r�future_featuresr��
refactor_tree)ry�datarr[r�r�rrrr�gs
zRefactoringTool.refactor_stringcCs�tjj�}|rN|jd�|j|d�}|js2||krB|j|d|�q�|jd�n:|j|d�}|jsj|r~|jr~|jt	|�d|�n
|jd�dS)NzRefactoring doctests in stdinz<stdin>zNo doctest changes in stdinzNo changes in stdin)
�sys�stdinr�r�r�rbr�r�r�r�)ryr�r@r�r�rrr�refactor_stdin�s

zRefactoringTool.refactor_stdinc
Cs�x"t|j|j�D]}|j||�qW|j|j|j��|j|j|j��|jj|j	��}�xvt
|j���rАx`|jjD�]R}||ko�||rv||j
tjjdd�|jr�||j
tjjd��x
t||�D�]�}|||kr�||j|�yt|�Wntk
�rw�YnX|j�r(||jk�r(q�|j|�}|r�|j||�}|dk	r�|j|�x,|j�D] }|j�spg|_|jj|��q^W|jj|j	��}x2|D]*}	|	|k�r�g||	<||	j||	��q�Wq�WqvWq\Wx$t|j|j�D]}|j||��q�W|jS)NT)r~�reverse)r~)rrrrsZ
start_tree�traverse_byrwrxrvZrunZleaves�anyr0rer�rZBaseZdepthZkeep_line_orderZ
get_linenor-�remover�
ValueErrorZfixers_applied�match�	transformr?rr2Zfinish_treer�)
ryr�rr4Z	match_set�node�results�newZnew_matchesZfxrrrrr��sJ



$zRefactoringTool.refactor_treecCs^|sdSxP|D]H}xB||jD]4}|j|�}|r|j||�}|dk	r|j|�|}qWqWdS)N)r#r�r�r?)ryreZ	traversalr�r4r�r�rrrr��s


zRefactoringTool.traverse_bycCs�|jj|�|dkr.|j|�d}|dkr.dS||k}|j||||�|r`|jd|�|js`dS|rv|j||||�n|jd|�dS)NrzNo changes to %szNot writing changes to %s)rtrr�r�r�rb�
write_file)ryr�r�r�r�r�r�rrrr��szRefactoringTool.processed_filec%Cs�yt|d|d�}Wn.tk
r@}z|jd||�dSd}~XnXzHy|jt|��Wn0tk
r�}z|jd||�WYdd}~XnXWd|j�X|jd|�d|_dS)N�w)r�zCan't create %s: %szCan't write %s: %szWrote changes to %sT)r�r�r�r�rCr�r�rp)ryr�r�r�r�r�r�rrrr�
s$
zRefactoringTool.write_filez>>> z... c
Csg}d}d}d}d}x�|jdd�D]�}|d7}|j�j|j�r�|dk	r\|j|j||||��|}|g}|j|j�}	|d|	�}q"|dk	r�|j||j�s�|||jj�dkr�|j	|�q"|dk	r�|j|j||||��d}d}|j	|�q"W|dk	�r|j|j||||��dj
|�S)NrT)�keependsrr>r|)�
splitlines�lstripr�PS1r2�refactor_doctest�find�PS2�rstriprr�)
ryr@r��result�blockZblock_lineno�indent�lineno�line�irrrr�%s:



z"RefactoringTool.refactor_docstringc
sy�j||��}Wndtk
rv}zH�jjtj�rRx|D]}�jd|jd��q8W�jd|||j	j
|�|Sd}~XnX�j||��r
t|�j
dd�}|d|d�||dd�}	}|d
jd�s�|dd7<��j|jd�g}|�r
|��fdd	�|D�7}|S)Nz
Source: %sr>z+Can't parse docstring in %s line %s: %s: %sT)r�rrcsg|]}��j|�qSr)r�)r7r�)r�ryrrr:jsz4RefactoringTool.refactor_doctest.<locals>.<listcomp>rr)�parse_blockr'rdZisEnabledForrn�DEBUGr�r�r�r�rr�r�r�rr��pop)
ryr�r�r�r�r�r�r�r�Zclippedr)r�ryrr�Ps$
"z RefactoringTool.refactor_doctestcCs�|jrd}nd}|js$|jd|�n&|jd|�x|jD]}|j|�q8W|jrt|jd�x|jD]}|j|�qbW|jr�t|j�dkr�|jd�n|jdt|j��x&|jD]\}}}|j|f|�|�q�WdS)	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:)rprtr�rormr�)ryr��file�messager�r�r�rrr�	summarizems$
zRefactoringTool.summarizecCs"|jj|j|||��}t�|_|S)N)rZparse_tokens�	wrap_toksrPr�)ryr�r�r�r�rrrr��szRefactoringTool.parse_blockccshtj|j||�j�}xN|D]F\}}\}}\}	}
}||d7}|	|d7}	||||f|	|
f|fVqWdS)Nr)rrL�	gen_lines�__next__)ryr�r�r�r1r#r]Zline0Zcol0Zline1Zcol1Z	line_textrrrr��s
zRefactoringTool.wrap_toksccs�||j}||j}|}xV|D]N}|j|�r@|t|�d�Vn(||j�dkrXdVntd||f��|}qWx
dVqrWdS)Nr>zline=%r, prefix=%rr|)r�r�rr�r��AssertionError)ryr�r��prefix1Zprefix2�prefixr�rrrr��s



zRefactoringTool.gen_lines)NN)FF)FF)FF)F)NFN)N)rr r!rgr�r�rzrqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr`�s:
4(
	


O

+
r`c@seZdZdS)�MultiprocessingUnsupportedN)rr r!rrrrr��sr�csBeZdZ�fdd�Zd�fdd�	Z�fdd�Z�fd	d
�Z�ZS)�MultiprocessRefactoringToolcs"tt|�j||�d|_d|_dS)N)�superr�rz�queue�output_lock)ryr��kwargs)r�rrrz�sz$MultiprocessRefactoringTool.__init__Frcs|dkrtt��j|||�Syddl�Wntk
r@t�YnX�jdk	rTtd���j��_�j	��_
��fdd�t|�D�}z.x|D]}|j�q�Wtt��j|||�Wd�jj
�xt|�D]}�jjd�q�Wx|D]}|j�r�|j
�q�Wd�_XdS)Nrrz already doing multiple processescsg|]}�j�jd��qS))�target)ZProcess�_child)r7r�)�multiprocessingryrrr:�sz8MultiprocessRefactoringTool.refactor.<locals>.<listcomp>)r�r�r�r��ImportErrorr�r��RuntimeErrorZ
JoinableQueueZLockr��range�startr��putZis_alive)ryr�r�r�Z
num_processesZ	processesr)r�)r�)r�ryrr��s2









z$MultiprocessRefactoringTool.refactorc
sR|jj�}xB|dk	rL|\}}ztt|�j||�Wd|jj�X|jj�}qWdS)N)r�rlr�r�r�Z	task_done)ryZtaskr�r�)r�rrr��s


z"MultiprocessRefactoringTool._childcs2|jdk	r|jj||f�ntt|�j||�SdS)N)r�r�r�r�r�)ryr�r�)r�rrr��s

z)MultiprocessRefactoringTool.refactor_file)FFr)rr r!rzr�r�r��
__classcell__rr)r�rr��s
r�)T)rr)'�
__author__rr�rnr�r+rM�	itertoolsrZpgen2rrrZ
fixer_utilrr|rr	r
rurr'rr$r5r;r=�version_info�codecsr�r�rArCr^r_�objectr`r�r�rrrr�<module>sD



(	

Zerion Mini Shell 1.0