AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.10/lib2to3/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3.10/lib2to3/__pycache__/refactor.cpython-310.pyc
o

��bcsk�@sdZdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZddlmZddlmZmZdd	lmZd!dd�ZGd
d�de�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd �d e �Z"dS)"z�Refactoring framework.

Used as a main program, this can refactor any number of files and/or
recursively descend down directories.  Imported as a module, this
provides infrastructure to write your own refactoring tool.
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'|r"|dd�}|�|�q|S)zEReturn a sorted list of all available fix names in the given package.�*�fix_�N)�
__import__�pkgutil�iter_modules�__path__�
startswith�append)�	fixer_pkg�
remove_prefix�pkg�	fix_names�finder�name�ispkg�r�'/usr/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	�rAt
�}|jD]}|D]	}|�t|��q4q0|Std|��)zf Accepts a pytree Pattern Node and returns a set
        of the pattern types which will match first. Nz$Oh no! I don't understand pattern %s)
�
isinstancer�NodePattern�LeafPattern�typer�NegatedPattern�content�_get_head_types�WildcardPattern�set�update�	Exception)�pat�r�p�xrrrr+/s 


�r+c	Cs�t�t�}g}|D];}|jr1zt|j�}Wnty#|�|�Yq	w|D]	}||�|�q&q	|jdur?||j�|�q	|�|�q	tt	j
j��t	j
j
�D]	}||�|�qPt|�S)z^ Accepts a list of fixers and returns a dictionary
        of head node type --> fixer list.  N)�collections�defaultdict�list�patternr+rr�_accept_typerr	�python_grammar�
symbol2number�values�tokens�extend�dict)�
fixer_list�
head_nodes�every�fixer�heads�	node_typerrr�_get_headnode_dictKs(
��
�rEcs�fdd�t�d�D�S)zN
    Return the fully qualified names for fixers in the package pkg_name.
    csg|]}�d|�qS��.r)�.0�fix_name��pkg_namerr�
<listcomp>hs�z+get_fixers_from_package.<locals>.<listcomp>F)rrJrrJr�get_fixers_from_packageds
�rMcCs|S�Nr)�objrrr�	_identityksrPcsjd}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�from�
__future__�import�(�,)r�generate_tokens�io�StringIO�readline�	frozensetr�NEWLINE�NL�COMMENTr-�STRING�NAME�OP�add�
StopIteration)�source�have_docstringrU�ignore�features�tp�valuerrSr�_detect_future_featuresos\










��������rnc@seZdZdZdS)�
FixerErrorzA fixer could not be loaded.N)r!r"r#�__doc__rrrrro�sroc@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_files�FixrNcCsH||_|pg|_|j��|_|dur|j�|�tj��|_|jdr)|jj	d=n
|jdr3|jj	d=|j�
d�|_g|_t
�d�|_g|_d|_tj|jtj|jd	�|_|��\|_|_g|_t��|_g|_g|_t|j|j�D]#}|j r~|j�!|�qr||jvr�|j�"|�qr||jvr�|j�"|�qrt#|j�|_$t#|j�|_%dS)
z�Initializer.

        Args:
            fixer_names: a list of fixers to import
            options: a dict with configuration.
            explicit: a list of fixers to run even if they are explicit.
        Nrr�printrs�execrtrqF)�convert�logger)&�fixers�explicit�_default_options�copy�optionsr.r	r9�grammar�keywords�getrt�errors�logging�	getLoggerry�	fixer_log�wroter�Driverrrx�
get_fixers�	pre_order�
post_order�files�bm�
BottomMatcher�BM�
bmi_pre_order�bmi_post_orderr�
BM_compatible�	add_fixerrrE�bmi_pre_order_heads�bmi_post_order_heads)�self�fixer_namesr~r{rBrrr�__init__�sD



�


�zRefactoringTool.__init__c	CsJg}g}|jD]�}t|iidg�}|�dd�d}|�|j�r(|t|j�d�}|�d�}|jd�dd	�|D��}zt	||�}Wnt
yQtd
||f�d�w||j|j
�}	|	jrm|jdurm||jvrm|�d|�q|�d
|�|	jdkr~|�|	�q|	jdkr�|�|	�qtd|	j��t�d�}
|j|
d�|j|
d�||fS)aInspects the options to load the requested patterns and handlers.

        Returns:
          (pre_order, post_order), where pre_order is the list of fixers that
          want a pre-order AST traversal, and post_order is the list that want
          post-order traversal.
        rrGr���N�_�cSsg|]}|���qSr)�title)rHr2rrrrL�sz.RefactoringTool.get_fixers.<locals>.<listcomp>zCan't find %s.%sTzSkipping optional fixer: %szAdding transformation: %s�pre�postzIllegal fixer order: %r�	run_order��key)rzr�rsplitr�FILE_PREFIX�len�split�CLASS_PREFIX�join�getattr�AttributeErrorror~r�r{�log_message�	log_debug�orderr�operator�
attrgetter�sort)r��pre_order_fixers�post_order_fixers�fix_mod_path�modrI�parts�
class_name�	fix_classrB�key_funcrrrr��s:

�



zRefactoringTool.get_fixerscOs�)zCalled when an error occurs.r)r��msg�args�kwdsrrr�	log_errorszRefactoringTool.log_errorcGs|r||}|j�|�dS)zHook to log a message.N)ry�info�r�r�r�rrrr�szRefactoringTool.log_messagecGs|r||}|j�|�dSrN)ry�debugr�rrrr�
szRefactoringTool.log_debugcCsdS)zTCalled with the old version, new version, and filename of a
        refactored file.Nr)r��old_text�new_text�filename�equalrrr�print_outputszRefactoringTool.print_outputcCs8|D]}tj�|�r|�|||�q|�|||�qdS)z)Refactor a list of files and directories.N)�os�path�isdir�refactor_dir�
refactor_file)r��items�write�
doctests_only�dir_or_filerrr�refactors
�zRefactoringTool.refactorc
Cs�tjd}t�|�D]@\}}}|�d|�|��|��|D]}|�d�s>tj�|�d|kr>tj�||�}	|�	|	||�qdd�|D�|dd�<q
dS)z�Descends down a directory and refactor every Python file found.

        Python files are assumed to have a .py extension.

        Files and subdirectories starting with '.' are skipped.
        �pyzDescending into %srGrcSsg|]	}|�d�s|�qSrF)r)rH�dnrrrrL2�z0RefactoringTool.refactor_dir.<locals>.<listcomp>N)
r��extsep�walkr�r�rr��splitextr�r�)
r��dir_namer�r��py_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�S1sPwYdS)	zG
        Do our best to decode a Python source file correctly.
        �rbzCan't open %s: %sN�NNrr1r���encoding�newline)	�open�OSErrorr�r�detect_encodingr^�closer\�read)r�r��f�errr�rrr�_read_python_source4s��
$�z#RefactoringTool._read_python_sourcecCs�|�|�\}}|dur
dS|d7}|r9|�d|�|�||�}|js&||kr1|�|||||�dS|�d|�dS|�||�}|jsG|rX|jrX|jt|�dd�|||d�dS|�d|�dS)zRefactors a file.N�
zRefactoring doctests in %szNo doctest changes in %sr�)r�r�zNo changes in %s)r�r��refactor_docstringrt�processed_file�refactor_string�was_changed�str)r�r�r�r��inputr��output�treerrrr�Ds 
�zRefactoringTool.refactor_filec
Cs�t|�}d|vr
tj|j_z3z|j�|�}Wn#ty9}z|�d||jj	|�WYd}~W|j|j_dSd}~wwW|j|j_n|j|j_w||_
|�d|�|�||�|S)aFRefactor a given input string.

        Args:
            data: a string holding the code to be refactored.
            name: a human-readable name for use in error/log messages.

        Returns:
            An AST corresponding to the refactored input stream; None if
            there were errors during the parse.
        rrzCan't parse %s: %s: %sNzRefactoring %s)
rnr	�!python_grammar_no_print_statementrr�parse_stringr/r��	__class__r!�future_featuresr��
refactor_tree)r��datarrkr�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�rtr�r�r�r�)r�r�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�|jrV||j
tjjd�t||�D]o}|||vrk||�|�zt|�Wn	tyzYq\w|jr�||jvr�q\|�|�}|r�|�||�}|dur�|�|�|��D]}|js�g|_|j�|�q�|j�|�	��}|D]}	|	|vr�g||	<||	�||	�q�q\q4t
|���s0t|j|j�D]}|�||�q�|jS)a�Refactors a parse tree (modifying the tree in place).

        For compatible patterns the bottom matcher module is
        used. Otherwise the tree is traversed node-to-node for
        matches.

        Args:
            tree: a pytree.Node instance representing the root of the tree
                  to be refactored.
            name: a human-readable name for this tree.

        Returns:
            True if the tree was modified, False otherwise.
        T)r��reverser�N)rr�r��
start_tree�traverse_byr�r�r��run�leaves�anyr;rzr�r�Base�depth�keep_line_order�
get_linenor6�remover�
ValueError�fixers_applied�match�	transform�replacerr=�finish_treer�)
r�r�rrB�	match_set�node�results�new�new_matches�fxrrrrr��sP�

��1zRefactoringTool.refactor_treecCsV|sdS|D]"}||jD]}|�|�}|r'|�||�}|dur'|�|�|}q
qdS)aTraverse an AST, applying a set of fixers to each node.

        This is a helper method for refactor_tree().

        Args:
            fixers: a list of fixer instances.
            traversal: a generator that yields AST nodes.

        Returns:
            None
        N)r(rrr)r�rz�	traversalr
rBrrrrrr��s

���zRefactoringTool.traverse_bycCs�|j�|�|dur|�|�d}|durdS||k}|�||||�|r0|�d|�|js0dS|r<|�||||�dS|�d|�dS)zR
        Called when a file has been refactored and there may be changes.
        NrzNo changes to %szNot writing changes to %s)r�rr�r�r�rt�
write_file)r�r�r�r�r�r�r�rrrr��szRefactoringTool.processed_filecCs�ztj|d|dd�}Wnty%}z|�d||�WYd}~dSd}~ww|�)z|�|�WntyI}z
|�d||�WYd}~nd}~wwWd�n1sTwY|�d|�d|_dS)	z�Writes a string to a file.

        It first shows a unified diff between the old text and the new text, and
        then rewrites the file; the latter is only done if the write option is
        set.
        �wr�r�zCan't create %s: %sNzCan't write %s: %szWrote changes to %sT)r\r�r�r�r�r�r�)r�r�r�r�r��fpr�rrrrs$������
zRefactoringTool.write_filez>>> z... c
	Csg}d}d}d}d}|jdd�D]d}|d7}|���|j�r?|dur-|�|�||||��|}|g}|�|j�}	|d|	�}q|dur\|�||j�sV|||j��dkr\|�	|�q|durk|�|�||||��d}d}|�	|�q|dur�|�|�||||��d�
|�S)a�Refactors a docstring, looking for doctests.

        This returns a modified version of the input string.  It looks
        for doctests, which start with a ">>>" prompt, and may be
        continued with "..." prompts, as long as the "..." is indented
        the same as the ">>>".

        (Unfortunately we can't use the doctest module's parser,
        since, like most parsers, it is not geared towards preserving
        the original source.)
        NrT��keependsrr�r�)�
splitlines�lstripr�PS1r=�refactor_doctest�find�PS2�rstriprr�)
r�r�r��result�block�block_lineno�indent�lineno�line�irrrr�sB����
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�}	}|	dg|dksjJ|	��|d�d�sy|dd7<��j|�d	�g}|r�|��fd
d�|D�7}|S)z�Refactors one doctest.

        A doctest is given as a block of lines, the first of which starts
        with ">>>" (possibly indented), while the remaining lines start
        with "..." (identically indented).

        z
Source: %sr�z+Can't parse docstring in %s line %s: %s: %sNTrrr�rcsg|]	}��j|�qSr)r)rHr!�rr�rrrL^r�z4RefactoringTool.refactor_doctest.<locals>.<listcomp>)�parse_blockr/ry�isEnabledForr��DEBUGr�rr�r�r!r�r�r�endswithr�pop)
r�rr rr�r�r�r!r�clippedrr#rrDs,���"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:)r�r�r�r�r�r�)r�r*�file�messager�r�r�rrr�	summarizeas(


�zRefactoringTool.summarizecCs"|j�|�|||��}t�|_|S)z�Parses a block into a tree.

        This is necessary to get correct line number / offset information
        in the parser diagnostics and embedded into the parse tree.
        )r�parse_tokens�	wrap_toksr_r�)r�rr rr�rrrr$xszRefactoringTool.parse_blockccsf�t�|�||�j�}|D]#\}}\}}\}	}
}||d7}|	|d7}	||||f|	|
f|fVq
dS)z;Wraps a tokenize stream to systematically modify start/end.rN)rr[�	gen_lines�__next__)r�rr rr<r(rm�line0�col0�line1�col1�	line_textrrrr/�s��zRefactoringTool.wrap_toksccsx�||j}||j}|}|D]'}|�|�r |t|�d�Vn||��dkr,dVntd||f��|}q	dVq8)z�Generates lines as expected by tokenize from a list of lines.

        This strips the first len(indent + self.PS1) characters off each line.
        Nr�zline=%r, prefix=%rTr�)rrrr�r�AssertionError)r�rr�prefix1�prefix2�prefixr!rrrr0�s�


�zRefactoringTool.gen_linesr�)FF)F)NFNrN)r!r"r#r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�rr-r$r/r0rrrrrq�sB�
7(

	

O
�
+
rqc@r)�MultiprocessingUnsupportedNr rrrrr;�r$r;csFeZdZ�fdd�Z		d�fdd�	Z�fdd�Z�fd	d
�Z�ZS)�MultiprocessRefactoringToolcs&tt|�j|i|��d|_d|_dSrN)�superr<r��queue�output_lock�r�r��kwargs�r�rrr��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)rHr"��multiprocessingr�rrrL�s�z8MultiprocessRefactoringTool.refactor.<locals>.<listcomp>)r=r<r�rG�ImportErrorr;r>�RuntimeError�
JoinableQueue�Lockr?�range�startr��put�is_alive)r�r�r�r��
num_processes�	processesr2r"rBrFrr��sL
��


�
�
�

��z$MultiprocessRefactoringTool.refactorcsf|j��}|dur1|\}}ztt|�j|i|��W|j��n|j��w|j��}|dus	dSdSrN)r>r�r=r<r��	task_done)r��taskr�rArBrrrE�s

��
�z"MultiprocessRefactoringTool._childcs4|jdur|j�||f�dStt|�j|i|��SrN)r>rNr=r<r�r@rBrrr��s

��z)MultiprocessRefactoringTool.refactor_file)FFr)r!r"r#r�r�rEr��
__classcell__rrrBrr<�s�r<)T)#rp�
__author__r\r�rr�r�r�r4�	itertoolsr�pgen2rrr�
fixer_utilrr�rr	r
r�rr/rr+rErMrPrnro�objectrqr;r<rrrr�<module>s:
(


Anon7 - 2022
AnonSec Team