HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/lib2to3/__pycache__/refactor.cpython-310.opt-2.pyc
o

�isk�@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_matcherTcCsV	t|ggdg�}g}t�|j�D]\}}}|�d�r(|r#|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.10/lib2to3/refactor.py�get_all_fix_namess

�rc@�eZdZdS)�
_EveryNodeN��__name__�
__module__�__qualname__rrrrr+�rcCs�	t|tjtjf�r|jdurt�|jhSt|tj�r%|jr#t|j�St�t|tj	�rBt
�}|jD]}|D]	}|�t|��q5q1|Std|��)Nz$Oh no! I don't understand pattern %s)
�
isinstancerZNodePatternZLeafPattern�typerZNegatedPatternZcontent�_get_head_typesZWildcardPattern�set�update�	Exception)�pat�r�p�xrrrr!/s"


�r!c	Cs�	t�t�}g}|D];}|jr2zt|j�}Wnty$|�|�Yq
w|D]	}||�|�q'q
|jdur@||j�|�q
|�|�q
tt	j
j��t	j
j
�D]	}||�|�qQt|�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*
��
�r4cs	�fdd�t�d�D�S)Ncsg|]}�d|�qS��.r)�.0�fix_name�Zpkg_namerr�
<listcomp>hs�z+get_fixers_from_package.<locals>.<listcomp>F)rr9rr9r�get_fixers_from_packageds
�r;cCs|Sr)r)�objrrr�	_identityksr=csjd}t�t�|�j���fdd�}ttjtjtj	h�}t
�}z�	|�\}}||vr*q|tjkr5|r2ncd}n_|tjkr�|dkr�|�\}}|tjksL|dkrMnR|�\}}|tjks[|dkr\nH|�\}}|tj
kro|dkro|�\}}|tjkr�|�|�|�\}}|tj
ks�|d	kr�n
|�\}}|tjkstnnq Wt|�SWt|�SWt|�SWt|�Sty�Yt|�Sw)
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_docstringrB�ignore�features�tp�valuerr@r�_detect_future_featuresos\










��������rYc@r)�
FixerErrorNrrrrrrZ�rrZc@s�eZdZdddd�ZdZdZd4dd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zd5dd�Zd5dd�Z
dd�Zd5dd�Zdd�Zd6dd�Zdd�Zd d!�Z		d7d"d#�Zd8d$d%�Zd&Zd'Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�ZdS)9�RefactoringToolF)�print_function�
exec_function�write_unchanged_filesZFixrNcCsJ	||_|pg|_|j��|_|dur|j�|�tj��|_|jdr*|jj	d=n
|jdr4|jj	d=|j�
d�|_g|_t
�d�|_g|_d|_tj|jtj|jd�|_|��\|_|_g|_t��|_g|_g|_t|j|j�D]#}|j r|j�!|�qs||jvr�|j�"|�qs||jvr�|j�"|�qst#|j�|_$t#|j�|_%dS)	Nr\�printr]�execr^r[F)�convert�logger)&�fixers�explicit�_default_options�copy�optionsr#r	r.�grammar�keywords�getr^�errors�logging�	getLoggerrb�	fixer_log�wroterZDriverrra�
get_fixers�	pre_order�
post_order�files�bmZ
BottomMatcher�BMZ
bmi_pre_orderZbmi_post_orderrZ
BM_compatibleZ	add_fixerrr4�bmi_pre_order_heads�bmi_post_order_heads)�selfZfixer_namesrgrdr3rrr�__init__�sF



�


�zRefactoringTool.__init__c	CsL	g}g}|jD]�}t|iidg�}|�dd�d}|�|j�r)|t|j�d�}|�d�}|jd�dd�|D��}zt	||�}Wnt
yRtd	||f�d�w||j|j
�}	|	jrn|jd
urn||jvrn|�d|�q|�d|�|	jd
kr|�|	�q|	jdkr�|�|	�qtd|	j��t�d�}
|j|
d�|j|
d�||fS)Nrr6r����_�cSsg|]}|���qSr)�title)r7r'rrrr:�sz.RefactoringTool.get_fixers.<locals>.<listcomp>zCan't find %s.%sTzSkipping optional fixer: %szAdding transformation: %s�preZpostzIllegal fixer order: %rZ	run_order��key)rcr�rsplitr�FILE_PREFIX�len�split�CLASS_PREFIX�join�getattr�AttributeErrorrZrgrnrd�log_message�	log_debug�orderr�operator�
attrgetter�sort)rxZpre_order_fixersZpost_order_fixersZfix_mod_path�modr8�parts�
class_nameZ	fix_classr3Zkey_funcrrrrp�s<

�



zRefactoringTool.get_fixerscOs	�r)r)rx�msg�args�kwdsrrr�	log_errorszRefactoringTool.log_errorcGs	|r||}|j�|�dSr))rb�info�rxr�r�rrrr�szRefactoringTool.log_messagecGs|r||}|j�|�dSr))rb�debugr�rrrr�
szRefactoringTool.log_debugcCs	dSr)r)rx�old_text�new_text�filename�equalrrr�print_outputszRefactoringTool.print_outputcCs:	|D]}tj�|�r|�|||�q|�|||�qdSr))�os�path�isdir�refactor_dir�
refactor_file)rx�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 %sr6rcSsg|]	}|�d�s|�qSr5)r)r7Zdnrrrr:2�z0RefactoringTool.refactor_dir.<locals>.<listcomp>)
r��extsep�walkr�r�rr��splitextr�r�)
rxZdir_namer�r�Zpy_ext�dirpath�dirnames�	filenamesr�fullnamerrrr� s

��zRefactoringTool.refactor_dirc
Cs�	zt|d�}Wnty"}z|�d||�WYd}~dSd}~wwzt�|j�d}W|��n|��wtj|d|dd��}|��|fWd�S1sQwYdS)N�rbzCan't open %s: %s�NNrr&r|��encoding�newline)	�open�OSErrorr�r�detect_encodingrJ�closerH�read)rxr��f�errr�rrr�_read_python_source4s��
$�z#RefactoringTool._read_python_sourcecCs�	|�|�\}}|durdS|d7}|r:|�d|�|�||�}|js'||kr2|�|||||�dS|�d|�dS|�||�}|jsH|rY|jrY|jt|�dd�|||d�dS|�d|�dS)N�
zRefactoring doctests in %szNo doctest changes in %srz)r�r�zNo changes in %s)r�r��refactor_docstringr^�processed_file�refactor_string�was_changed�str)rxr�r�r��inputr��output�treerrrr�Ds"
�zRefactoringTool.refactor_filec
Cs�	t|�}d|vrtj|j_z3z|j�|�}Wn#ty:}z|�d||jj	|�WYd}~W|j|j_dSd}~wwW|j|j_n|j|j_w||_
|�d|�|�||�|S)Nr\zCan't parse %s: %s: %szRefactoring %s)
rYr	Z!python_grammar_no_print_statementrrhZparse_stringr$r��	__class__r�future_featuresr��
refactor_tree)rx�datarrVr�r�rrrr�[s(


����zRefactoringTool.refactor_stringcCs�tj��}|r)|�d�|�|d�}|js||kr"|�|d|�dS|�d�dS|�|d�}|js7|rB|jrB|�t	|�d|�dS|�d�dS)NzRefactoring doctests in stdinz<stdin>zNo doctest changes in stdinzNo changes in stdin)
�sys�stdinr�r�r�r^r�r�r�r�)rxr�r�r�r�rrr�refactor_stdinvs

zRefactoringTool.refactor_stdinc

Cs�	t|j|j�D]}|�||�q|�|j|���|�|j|���|j�|�	��}t
|���r�|jjD]�}||vr�||r�||j
tjjdd�|jrW||j
tjjd�t||�D]o}|||vrl||�|�zt|�Wn	ty{Yq]w|jr�||jvr�q]|�|�}|r�|�||�}|dur�|�|�|��D]}|js�g|_|j�|�q�|j�|�	��}|D]}	|	|vr�g||	<||	�||	�q�q]q5t
|���s1t|j|j�D]}|�||�q�|jS)NT)r��reverser)rrqrrZ
start_tree�traverse_byrvrwru�runZleaves�anyr/rcr�rZBase�depthZkeep_line_orderZ
get_linenor,�remover�
ValueErrorZfixers_applied�match�	transform�replacerr1Zfinish_treer�)
rxr�rr3Z	match_set�node�results�newZnew_matchesZfxrrrrr��sR�

��1zRefactoringTool.refactor_treecCsX	|sdS|D]"}||jD]}|�|�}|r(|�||�}|dur(|�|�|}qqdSr))r r�r�r�)rxrcZ	traversalr�r3r�r�rrrr��s

���zRefactoringTool.traverse_bycCs�	|j�|�|dur|�|�d}|durdS||k}|�||||�|r1|�d|�|js1dS|r=|�||||�dS|�d|�dS)NrzNo changes to %szNot writing changes to %s)rsrr�r�r�r^�
write_file)rxr�r�r�r�r�r�rrrr��szRefactoringTool.processed_filecCs�	ztj|d|dd�}Wnty&}z|�d||�WYd}~dSd}~ww|�)z|�|�WntyJ}z
|�d||�WYd}~nd}~wwWd�n1sUwY|�d|�d|_dS)N�wr|r�zCan't create %s: %szCan't write %s: %szWrote changes to %sT)rHr�r�r�r�r�ro)rxr�r�r�r��fpr�rrrr�s&������
zRefactoringTool.write_filez>>> z... c
	Cs	g}d}d}d}d}|jdd�D]d}|d7}|���|j�r@|dur.|�|�||||��|}|g}|�|j�}	|d|	�}q|dur]|�||j�sW|||j��dkr]|�	|�q|durl|�|�||||��d}d}|�	|�q|dur�|�|�||||��d�
|�S)NrT��keependsrr�r|)�
splitlines�lstripr�PS1r1�refactor_doctest�find�PS2�rstriprr�)
rxr�r��result�blockZblock_lineno�indent�lineno�line�irrrr�sD����
z"RefactoringTool.refactor_docstringc

s	z	��||��}Wn4ty>}z(�j�tj�r'|D]}��d|�d��q��d|||j	j
|�|WYd}~Sd}~ww��||�r�t|�j
dd�}|d|d�||dd�}	}|d�d�sm|dd7<��j|�d�g}|r�|��fd	d
�|D�7}|S)Nz
Source: %sr�z+Can't parse docstring in %s line %s: %s: %sTr�rrzrcsg|]	}��j|�qSr)r�)r7r��r�rxrrr:^r�z4RefactoringTool.refactor_doctest.<locals>.<listcomp>)�parse_blockr$rb�isEnabledForrl�DEBUGr�r�r�r�rr�r�r��endswithr��pop)
rxr�r�r�r�r�r�r�r�Zclippedrr�rr�Ds,���"z RefactoringTool.refactor_doctestcCs�|jrd}nd}|js|�d|�n|�d|�|jD]}|�|�q|jr6|�d�|jD]}|�|�q.|jrdt|j�dkrF|�d�n	|�dt|j��|jD]\}}}|j|g|�Ri|��qRdSdS)	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:)rorsr�rnrkr�)rxr��file�messager�r�r�rrr�	summarizeas(


�zRefactoringTool.summarizecCs$	|j�|�|||��}t�|_|Sr))rZparse_tokens�	wrap_toksrKr�)rxr�r�r�r�rrrr�xszRefactoringTool.parse_blockccsh�	t�|�||�j�}|D]#\}}\}}\}	}
}||d7}|	|d7}	||||f|	|
f|fVqdS)Nr)rrG�	gen_lines�__next__)rxr�r�r�r0r rXZline0Zcol0Zline1Zcol1Z	line_textrrrr��s��zRefactoringTool.wrap_toksccsz�	||j}||j}|}|D]'}|�|�r!|t|�d�Vn||��dkr-dVntd||f��|}q	dVq9)Nr�zline=%r, prefix=%rTr|)r�r�rr�r��AssertionError)rxr�r��prefix1Zprefix2�prefixr�rrrr��s�


�zRefactoringTool.gen_linesr�)FF)F)NFNr))rrrrer�r�ryrpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr[�sB�
7(

	

O
�
+
r[c@r)�MultiprocessingUnsupportedNrrrrrr��rr�csFeZdZ�fdd�Z		d�fdd�	Z�fdd�Z�fd	d
�Z�ZS)�MultiprocessRefactoringToolcs&tt|�j|i|��d|_d|_dSr))�superr�ry�queue�output_lock�rxr��kwargs�r�rrry�s
z$MultiprocessRefactoringTool.__init__Frc
s2|dkrtt���|||�Szddl�Wn	tyt�w�jdur'td������_��	��_
��fdd�t|�D�}z8|D]}|��q@tt���|||�W�j�
�t|�D]}�j�d�q[|D]
}|��rp|�
�qfd�_dS�j�
�t|�D]}�j�d�q|D]
}|��r�|�
�q�d�_w)Nrrz already doing multiple processescsg|]	}�j�jd��qS))�target)�Process�_child)r7r���multiprocessingrxrrr:�s�z8MultiprocessRefactoringTool.refactor.<locals>.<listcomp>)r�r�r�r�ImportErrorr�r��RuntimeError�
JoinableQueue�Lockr�range�startr��put�is_alive)rxr�r�r�Z
num_processes�	processesr'r�rrrr��sL
��


�
�
�

��z$MultiprocessRefactoringTool.refactorcsf|j��}|dur1|\}}ztt|�j|i|��W|j��n|j��w|j��}|dus	dSdSr))r�rjr�r�r��	task_done)rxZtaskr�rrrrr�s

��
�z"MultiprocessRefactoringTool._childcs4|jdur|j�||f�dStt|�j|i|��Sr))r�rr�r�r�rrrrr��s

��z)MultiprocessRefactoringTool.refactor_file)FFr)rrrryr�rr��
__classcell__rrrrr��s�r�)T)"�
__author__rHr�rr�rlr�r*�	itertoolsrZpgen2rrrZ
fixer_utilrr|rr	r
rtrr$rr!r4r;r=rYrZ�objectr[r�r�rrrr�<module>s:
(