b374k
m1n1 1.01
Apache/2.2.15 (CentOS)
Linux obd60-6c49958d75-2q7cw 5.4.0-174-generic #193-Ubuntu SMP Thu Mar 7 14:29:28 UTC 2024 x86_64
uid=48(apache) gid=48(apache) groups=48(apache)
server ip : 104.21.65.202 | your ip : 10.244.126.0
safemode OFF
 >  / usr / lib64 / python2.6 / lib2to3 /
Filename/usr/lib64/python2.6/lib2to3/refactor.pyc
Size22.16 kb
Permissionrw-r--r--
Ownerapache
Create time23-Dec-2025 17:41
Last modified20-Jun-2019 19:45
Last accessed22-Apr-2026 09:45
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
Ñò
§ÚêLc@�s¤dZddklZdZddkZddkZddkZddkZddkZddk Z ddk
l Z ddk l
Z
lZlZddklZlZed �Zd
efd ��YZd �Zd
�Zd�Zd�Zeiddfjo+ddkZeiZd�Zd�Z neZeZeZ d�Z!defd��YZ"de#fd��YZ$defd��YZ%de$fd��YZ&dS(sÛ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.
iÿÿÿÿ(twith_statements#Guido van Rossum <[email protected]>N(tchaini(tdriverttokenizettoken(tpytreetpygramcC�s¡t|ggdg�}tii|i�}g}xgtti|��D]P}|id�o:|id�o*|o|d}n|i |d �qIqIW|S(sEReturn a sorted list of all available fix names in the given package.t*tfix_s.pyiiýÿÿÿ(
t
__import__tostpathtdirnamet__file__tsortedtlistdirt
startswithtendswithtappend(t fixer_pkgt
remove_prefixtpkgt fixer_dirt fix_namestname((s(/usr/lib64/python2.6/lib2to3/refactor.pytget_all_fix_namess t
_EveryNodecB�seZRS((t__name__t
__module__(((s(/usr/lib64/python2.6/lib2to3/refactor.pyR+scC�sét|titif�o+|idjo
t�nt|ig�St|ti�o"|i ot
|i �St�nt|ti �oFt�}x5|i D]*}x!|D]}|i t
|��q¯Wq¢W|St
d|��dS(sf Accepts a pytree Pattern Node and returns a set
of the pattern types which will match first. s$Oh no! I don't understand pattern %sN(t
isinstanceRt NodePatternt LeafPatternttypetNoneRtsettNegatedPatterntcontentt_get_head_typestWildcardPatterntupdatet Exception(tpattrtptx((s(/usr/lib64/python2.6/lib2to3/refactor.pyR%/s"


 
cC�stit�}g}x©|D]¡}|io\yt|i�}Wn tj
o|i|�q½XxX|D]}||i|�qiWq|idj o||ii|�q|i|�qWx:t t
i i i
�t
i i�D]}||i|�qãWt|�S(s^ Accepts a list of fixers and returns a dictionary
of head node type --> fixer list. N(t collectionst defaultdicttlisttpatternR%RRt _accept_typeR!RRtpython_grammart
symbol2numbert
itervaluesttokenstextendtdict(t
fixer_listt
head_nodesteverytfixertheadst node_type((s(/usr/lib64/python2.6/lib2to3/refactor.pyt_get_headnode_dictKs(

cC�s0g}t|t�D]}||d|q~S(sN
Return the fully qualified names for fixers in the package pkg_name.
t.(RtFalse(tpkg_namet_[1]tfix_name((s(/usr/lib64/python2.6/lib2to3/refactor.pytget_fixers_from_packagedscC�s|S(N((tobj((s(/usr/lib64/python2.6/lib2to3/refactor.pyt _identityksiicC�s|idd�S(Nu
u
(treplace(tinput((s(/usr/lib64/python2.6/lib2to3/refactor.pyt_from_system_newlinesrscC�s,tidjo|idti�S|SdS(Ns
u
(R
tlinesepRG(RH((s(/usr/lib64/python2.6/lib2to3/refactor.pyt_to_system_newlinestsc�sût}titi|�i���fd�}ttititi f�}t
�}y�x}t ou|�\}}||joq]q]|ti jo|oPnt }q]|ti
jo|djo
|�\}}|ti
jp
|djoPn|�\}}|ti
jp
|djoPn|�\}}|tijo |djo|�\}}nxg|ti
joQ|i|�|�\}}|tijp
|djoPn|�\}}qnWq]Pq]WWntj
onXt|�S(Nc�s�i�}|d|dfS(Nii(tnext(ttok(tgen(s(/usr/lib64/python2.6/lib2to3/refactor.pytadvance�s ufromu
__future__uimportu(u,(R@Rtgenerate_tokenstStringIOtreadlinet frozensetRtNEWLINEtNLtCOMMENTR"tTruetSTRINGtNAMEtOPtaddt
StopIteration(tsourcethave_docstringROtignoretfeaturesttptvalue((RNs(/usr/lib64/python2.6/lib2to3/refactor.pyt_detect_future_featuressH 



t
FixerErrorcB�seZdZRS(sA fixer could not be loaded.(RRt__doc__(((s(/usr/lib64/python2.6/lib2to3/refactor.pyRd§stRefactoringToolcB�seZhed6ZdZdZddd�Zd�Zd�Z d�Z
d�Z d�Z eed �Z
eed
�Zd �Zeed �Zd
�Zed�Zd�Zd�Zdedd�Zdd�ZdZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(tprint_functiontFixRcC�s||_|pg|_|ii�|_|dj o|ii|�n|idoti|_ n
ti
|_ g|_ t i
d�|_g|_t|_ti|i dtid|i�|_|i�\|_|_t|i�|_t|i�|_g|_dS(sÒInitializer.

Args:
fixer_names: a list of fixers to import
options: an dict with configuration.
explicit: a list of fixers to run even if they are explicit.
RgRftconverttloggerN(tfixerstexplicitt_default_optionstcopytoptionsR!R'Rt!python_grammar_no_print_statementtgrammarR2terrorstloggingt getLoggerRjt fixer_logR@twroteRtDriverRRit
get_fixerst pre_ordert
post_orderR>tpre_order_headstpost_order_headstfiles(tselft fixer_namesRoRl((s(/usr/lib64/python2.6/lib2to3/refactor.pyt__init__²s& 
     c

C�sñg}g}x©|iD]�}t|hhdg�}|idd�d}|i|i�o|t|i�}n|id�}|idig}|D]}||i �q�~�} yt
|| �}
Wn)t j
ot d|| f��nX|
|i
|i�} | io7|itj o'||ijo|id|�qn|id |�| id
jo|i| �q| id jo|i| �qt d | i��qWtid
�} |id| �|id| �||fS(sInspects 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.
RR?iiÿÿÿÿt_tsCan't find %s.%ssSkipping implicit fixer: %ssAdding transformation: %stpretpostsIllegal fixer order: %rt run_ordertkey(RkR trsplitRt FILE_PREFIXtlentsplitt CLASS_PREFIXtjointtitletgetattrtAttributeErrorRdRoRuRlRWt log_messaget log_debugtorderRtoperatort
attrgettertsort(
R~tpre_order_fixerstpost_order_fixerst fix_mod_pathtmodRCtpartsRBR+t
class_namet fix_classR;tkey_func((s(/usr/lib64/python2.6/lib2to3/refactor.pyRxÑs:
7cO�s�dS(sCalled when an error occurs.N((R~tmsgtargstkwds((s(/usr/lib64/python2.6/lib2to3/refactor.pyt log_errorùscG�s)|o||}n|ii|�dS(sHook to log a message.N(Rjtinfo(R~R�R�((s(/usr/lib64/python2.6/lib2to3/refactor.pyR�ýscG�s)|o||}n|ii|�dS(N(Rjtdebug(R~R�R�((s(/usr/lib64/python2.6/lib2to3/refactor.pyR�scC�sdS(sTCalled with the old version, new version, and filename of a
refactored file.N((R~told_texttnew_texttfilenametequal((s(/usr/lib64/python2.6/lib2to3/refactor.pyt print_outputscC�sRxK|D]C}tii|�o|i|||�q|i|||�qWdS(s)Refactor a list of files and directories.N(R
R tisdirt refactor_dirt
refactor_file(R~titemstwritet
doctests_onlyt dir_or_file((s(/usr/lib64/python2.6/lib2to3/refactor.pytrefactor
s
c C�sïxèti|�D]×\}}}|id|�|i�|i�xk|D]c}|id� oLtii|�did�o,tii||�}|i |||�qJqJWg} |D]!}
|
id�p | |
q¼q¼~ |(qWdS(sÄ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.
sDescending into %sR?itpyN(
R
twalkR�R�RR tsplitextRR�R«( R~tdir_nameR­R®tdirpathtdirnamest filenamesRtfullnameRBtdn((s(/usr/lib64/python2.6/lib2to3/refactor.pyRªs

 c C�s³yt|d�}Wn)tj
o}|id||�dSXzti|i�d}Wd|i�Xt|dd|�i i
�}z#|~}t |i ��|fSWdQXdS(sG
Do our best to decode a Python source file correctly.
trbsCan't open %s: %siNR*tencoding(NN(
topentIOErrorR¡R!Rtdetect_encodingRRtcloset_open_with_encodingt__exit__t __enter__RItread(R~R¦tfterrR»RB((s(/usr/lib64/python2.6/lib2to3/refactor.pyt_read_python_source(s ,cC�sù|i|�\}}|djodS|d7}|o`|id|�|i||�}||jo|i|||||�qõ|id|�n^|i||�}|o4|io*|it|�d |d|d|�n|id|�dS( sRefactors a file.Nu
sRefactoring doctests in %ssNo doctest changes in %siÿÿÿÿR­R»sNo changes in %s(RÆR!R�trefactor_docstringtprocessed_filetrefactor_stringt was_changedtunicode(R~R¦R­R®RHR»toutputttree((s(/usr/lib64/python2.6/lib2to3/refactor.pyR«8s


c C�s»t|�}d|joti|i_nzOy|ii|�}Wn2tj
o&}|id||ii |�dSXWd|i|i_X||_
|i d|�|i ||�|S(sFRefactor 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.
RgsCan't parse %s: %s: %sNsRefactoring %s(
RcRRpRRqt parse_stringR(R¡t __class__Rtfuture_featuresR�t
refactor_tree(R~tdataRR`RÍRÅ((s(/usr/lib64/python2.6/lib2to3/refactor.pyRÉOs 
 
 cC�s»tii�}|oT|id�|i|d�}||jo|i|d|�q·|id�nN|i|d�}|o'|io|it|�d|�n|id�dS(NsRefactoring doctests in stdins<stdin>sNo doctest changes in stdinsNo changes in stdin( tsyststdinRÃR�RÇRÈRÉRÊRË(R~R®RHRÌRÍ((s(/usr/lib64/python2.6/lib2to3/refactor.pytrefactor_stdinjs

cC�s�x-t|i|i�D]}|i||�qW|i|i|i��|i|i|i��x-t|i|i�D]}|i||�qxW|iS(sARefactors a parse tree (modifying the tree in place).

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.
( RRyRzt
start_treet traverse_byR{R|t finish_treeRÊ(R~RÍRR;((s(/usr/lib64/python2.6/lib2to3/refactor.pyRÑzs cC�s�|pdSxv|D]n}xe||iD]V}|i|�}|o:|i||�}|dj o|i|�|}q}q'q'WqWdS(sTraverse 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 tmatcht transformR!RG(R~Rkt traversaltnodeR;tresultstnew((s(/usr/lib64/python2.6/lib2to3/refactor.pyR�s 

cC�s¹|ii|�|djo)|i|�d}|djodSn||j}|i||||�|o|id|�dS|o|i||||�n|id|�dS(sP
Called when a file has been refactored, and there are changes.
iNsNo changes to %ssNot writing changes to %s(R}RR!RÆR¨R�t
write_file(R~R¥R¦R¤R­R»R§((s(/usr/lib64/python2.6/lib2to3/refactor.pyRȦs

  c C�s¼yt|dd|�}Wn,tij
o}|id||�dSXzIy|it|��Wn+tij
o}|id||�nXWd|i�X|id|�t|_ dS(sÑ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.
twR»sCan't create %s: %sNsCan't write %s: %ssWrote changes to %s(
RÀR
terrorR¡R­RKR¿R�RWRv(R~R¥R¦R¤R»RÄRÅ((s(/usr/lib64/python2.6/lib2to3/refactor.pyRߺs s>>> s... c
C�s�g}d}d}d}d}x5|it�D]$}|d7}|i�i|i�o_|dj o#|i|i||||��n|}|g}|i|i�} || }q.|dj oF|i||i �p|||i i
�djo|i |�q.|dj o#|i|i||||��nd}d}|i |�q.W|dj o#|i|i||||��ndi |�S(sË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.)
iiu
uN(
R!t
splitlinesRWtlstripRtPS1R6trefactor_doctesttfindtPS2trstripRR�(
R~RHR¦tresulttblockt block_linenotindenttlinenotlineti((s(/usr/lib64/python2.6/lib2to3/refactor.pyRÇÒs< 

 


c C�s�y|i|||�}Wnytj
om}|iiti�o.x+|D]}|id|id��qIWn|id|||i i
|�|SX|i ||�oØt |�i
t�}||d ||d} }| dg|djp
t| �|did�p|dcd7<n||i|id�g}|o4|g}
|D]}|
||i|qV~
7}q�n|S(sÞ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).

s
Source: %su
s+Can't parse docstring in %s line %s: %s: %siiÿÿÿÿi(t parse_blockR(tlogt isEnabledForRstDEBUGR�RèR¡RÏRRÑRËRâRWtAssertionErrorRRätpopRç( R~RêRíRìR¦RÍRÅRîRÞtclippedRB((s(/usr/lib64/python2.6/lib2to3/refactor.pyRåýs(! "8c C�s'|io
d}nd}|ip|id|�n2|id|�x|iD]}|i|�qRW|io2|id�x"|iD]}|i|�q�Wn|iott|i�djo|id�n|idt|i��x1|iD]"\}}}|i|||�qùWndS( Ntweres
need to besNo files %s modified.sFiles that %s modified:s$Warnings/messages while refactoring:isThere was 1 error:sThere were %d errors:(RvR}R�RuRrR�(R~R÷tfiletmessageR�R�R ((s(/usr/lib64/python2.6/lib2to3/refactor.pyt summarizes*








cC�s1|ii|i|||��}t�|_|S(s³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.
(Rt parse_tokenst wrap_toksRSRÐ(R~RêRíRìRÍ((s(/usr/lib64/python2.6/lib2to3/refactor.pyRð1s! c c�s�ti|i||�i�}xe|D]]\}}\}}\} }
} ||d7}| |d7} ||||f| |
f| fVq%WdS(s;Wraps a tokenize stream to systematically modify start/end.iN(RRPt gen_linesRL( R~RêRíRìR5R Rbtline0tcol0tline1tcol1t line_text((s(/usr/lib64/python2.6/lib2to3/refactor.pyRü;s !cc�s¨||i}||i}|}xm|D]e}|i|�o|t|�Vn7||i�djo dVntd||f��|}q'Wxto dVq�WdS(s�Generates lines as expected by tokenize from a list of lines.

This strips the first len(indent + self.PS1) characters off each line.
u
sline=%r, prefix=%rR�N(RäRçRR�RèRôRW(R~RêRìtprefix1tprefix2tprefixRî((s(/usr/lib64/python2.6/lib2to3/refactor.pyRýIs

 
N(RRR@RmR�R�R!R�RxR¡R�R�R¨R°RªRÆR«RÉRÕRÑR×RÈRßRäRçRÇRåRúRðRüRý(((s(/usr/lib64/python2.6/lib2to3/refactor.pyRf«s8
 (            +  
tMultiprocessingUnsupportedcB�seZRS((RR(((s(/usr/lib64/python2.6/lib2to3/refactor.pyR]stMultiprocessRefactoringToolcB�s5eZd�Zeedd�Zd�Zd�ZRS(cO�s/tt|�i||�d|_d|_dS(N(tsuperRR�R!tqueuet output_lock(R~R�tkwargs((s(/usr/lib64/python2.6/lib2to3/refactor.pyR�cs ic
C�sv|djott|�i|||�Syddk}Wntj
o
t�nX|idj otd��n|i �|_|i
�|_ g}t |�D]}||i
d|i�q¥~}z;x|D]} | i�qÔWtt|�i|||�Wd|ii�x$t |�D]}|iid�q"Wx)|D]!} | i�o| i�qCqCWd|_XdS(Niiÿÿÿÿs already doing multiple processesttarget(RRR°tmultiprocessingt ImportErrorRR R!t RuntimeErrort
JoinableQueuetLockR
txrangetProcesst_childtstartR�tputtis_alive(
R~R¬R­R®t
num_processesR
RBRït processesR+((s(/usr/lib64/python2.6/lib2to3/refactor.pyR°hs8
 / 


cC�sq|ii�}x[|dj oM|\}}ztt|�i||�Wd|ii�X|ii�}qWdS(N(R tgetR!RRR«t task_done(R~ttaskR�R ((s(/usr/lib64/python2.6/lib2to3/refactor.pyR�s
 cO�sG|idj o|ii||f�ntt|�i||�SdS(N(R R!RRRR«(R~R�R ((s(/usr/lib64/python2.6/lib2to3/refactor.pyR«�s(RRR�R@R°RR«(((s(/usr/lib64/python2.6/lib2to3/refactor.pyRas
   ('Ret
__future__Rt
__author__R
RÓRsR�R-RQt itertoolsRtpgen2RRRR�RRRWRR(RR%R>RDRFt version_infotcodecsR¼RÀRIRKRcRdtobjectRfRR(((s(/usr/lib64/python2.6/lib2to3/refactor.pyt<module> s>      
       
 (ÿ³