选择文件�文件大�最�修改时间�作
[📄] 36r5hq6kq6.74 KB2026-10-03 04:04:28
[📄] assets_ee72a41.php3.45 KB2026-09-30 15:33:41
[📄] dpack.php7.91 KB2026-10-03 05:40:27
[📄] filemanager_rcttbwr.php43.54 KB2026-10-02 09:50:09
[📄] image_3ff7dc4.php5.57 KB2026-09-30 15:27:22
U e5dkã@sdZdZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZddlmZddlmZmZdd lmZd!d d „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 éN)Úchainé)ÚdriverÚtokenizeÚtoken)Ú find_root)ÚpytreeÚpygram)Ú btm_matcherTcCsTt|ggdgƒ}g}t |j¡D].\}}}| d¡r |rD|dd…}| |¡q |S)zEReturn a sorted list of all available fix names in the given package.Ú*Úfix_éN)Ú __import__ÚpkgutilZ iter_modulesÚ__path__Ú startswithÚappend)Z fixer_pkgZ remove_prefixZpkgZ fix_namesÚfinderÚnameZispkg©rú(/usr/lib64/python3.8/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 ƒ}|jD]}|D]}|  t|ƒ¡qhq`|St d|ƒ‚dS)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) Ú isinstancerZ NodePatternZ LeafPatternÚtyperZNegatedPatternZcontentÚ_get_head_typesZWildcardPatternÚsetÚupdateÚ Exception)ZpatÚrÚpÚxrrrr/s     rc Cs¾t t¡}g}|D]x}|jrdzt|jƒ}Wntk rH| |¡YqŠX|D]}|| |¡qNq|jdk r€||j |¡q| |¡qtt j j   ¡t j j ƒD]}|| |¡q¢t|ƒS)z^ Accepts a list of fixers and returns a dictionary of head node type --> fixer list. 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$    ÿr0cs‡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©Zpkg_namerrÚ hsÿz+get_fixers_from_package..F)rr5rr5rÚget_fixers_from_packageds ÿr7cCs|S©Nr)ÚobjrrrÚ _identityksr:csXd}t t |¡j¡‰‡fdd„}ttjtjtj hƒ}t ƒ}zü|ƒ\}}||krTq>q>|tj krl|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>Wntk �rNYnXt|ƒS) NFcstˆƒ}|d|dfS)Nrr)Únext)Útok©ÚgenrrÚadvancersz(_detect_future_features..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           rVc@seZdZdZdS)Ú FixerErrorzA fixer could not be loaded.N)rrrÚ__doc__rrrrrW—srWc@säeZdZdddœZdZdZd4dd„Zdd „Zd d „Zd d „Z dd„Z dd„Z d5dd„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 NcCs.||_|p g|_|j ¡|_|dk r0|j |¡|jdrDtj|_ntj |_|j  d¡|_ g|_ t  d¡|_g|_d|_tj|jtj|jd�|_| ¡\|_|_g|_t ¡|_g|_g|_t|j|jƒD]F}|j râ|j !|¡qÊ||jkrú|j "|¡qÊ||jkrÊ|j "|¡qÊt#|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. NrZr[rYF)ÚconvertÚlogger)&ÚfixersÚexplicitÚ_default_optionsÚcopyÚoptionsr!r Ú!python_grammar_no_print_statementÚgrammarr*Úgetr[ÚerrorsÚloggingZ getLoggerr]Ú fixer_logÚwroterZDriverrr\Ú get_fixersÚ pre_orderÚ post_orderÚfilesÚbmZ BottomMatcherÚBMZ bmi_pre_orderZbmi_post_orderrZ BM_compatibleZ add_fixerrr0Úbmi_pre_order_headsÚbmi_post_order_heads)ÚselfZ fixer_namesrbr_r/rrrÚ__init__£s>      þ    zRefactoringTool.__init__c CsXg}g}|jD�]}t|iidgƒ}| dd¡d}| |j¡rR|t|jƒd…}| d¡}|jd dd „|Dƒ¡}zt ||ƒ}Wn&t k rªt d ||fƒd‚YnX||j |j ƒ} | jrâ|jd k râ||jkrâ| d |¡q| d |¡| jdk�r| | ¡q| jdk�r| | ¡qt d| jƒ‚qt 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. r r2réÿÿÿÿNÚ_ÚcSsg|] }| ¡‘qSr)Útitle)r3r$rrrr6çsz.RefactoringTool.get_fixers..zCan't find %s.%sTzSkipping optional fixer: %szAdding transformation: %sZpreZpostzIllegal fixer order: %rZ run_order©Úkey)r^rÚrsplitrÚ FILE_PREFIXÚlenÚsplitÚ CLASS_PREFIXÚjoinÚgetattrÚAttributeErrorrWrbrhr_Ú log_messageÚ log_debugÚorderrÚoperatorÚ attrgetterÚsort) rrZpre_order_fixersZpost_order_fixersZ fix_mod_pathÚmodr4ÚpartsÚ class_nameZ fix_classr/Zkey_funcrrrrj×s:   ÿ         zRefactoringTool.get_fixerscOs‚dS)zCalled when an error occurs.Nr)rrÚmsgÚargsÚkwdsrrrÚ log_errorÿszRefactoringTool.log_errorcGs|r ||}|j |¡dS)zHook to log a message.N)r]Úinfo©rrr‹rŒrrrr‚szRefactoringTool.log_messagecGs|r ||}|j |¡dSr8)r]Údebugr�rrrrƒ szRefactoringTool.log_debugcCsdS)zTCalled with the old version, new version, and filename of a refactored file.Nr)rrÚ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)rrÚitemsÚwriteÚ doctests_onlyZ dir_or_filerrrÚrefactors zRefactoringTool.refactorc Csštjd}t |¡D]€\}}}| d|¡| ¡| ¡|D]>}| d¡s>tj |¡d|kr>tj ||¡} |  | ||¡q>dd„|Dƒ|dd…<qdS)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 %sr2rcSsg|]}| d¡s|‘qSr1)r)r3Zdnrrrr6.s z0RefactoringTool.refactor_dir..N) r—ÚextsepÚwalkrƒr‡rr˜Úsplitextrr›) rrZdir_namer�ržZpy_extÚdirpathZdirnamesÚ filenamesrÚfullnamerrrršs   ÿzRefactoringTool.refactor_dirc Csœzt|dƒ}Wn6tk rD}z| d||¡WY¢dSd}~XYnXzt |j¡d}W5| ¡Xtj|d|dd��}| ¡|fW5QR£SQRXdS) zG Do our best to decode a Python source file correctly. ÚrbzCan't open %s: %s)NNNrr#rv©ÚencodingÚnewline) ÚopenÚOSErrorrŽÚcloserÚdetect_encodingrGrEÚread)rrr”ÚfÚerrr©rrrÚ_read_python_source0s z#RefactoringTool._read_python_sourcecCsº| |¡\}}|dkrdS|d7}|rn| d|¡| ||¡}|jsL||kr`| |||||¡q¶| d|¡nH| ||¡}|jsŠ|rª|jrª|jt|ƒdd…|||d�n | d|¡dS)zRefactors a file.NÚ zRefactoring doctests in %szNo doctest changes in %srt)r�r©zNo changes in %s)r²rƒÚrefactor_docstringr[Úprocessed_fileÚrefactor_stringÚ was_changedÚstr)rrr”r�ržÚinputr©ÚoutputÚtreerrrr›@s"   ÿzRefactoringTool.refactor_filec Cs t|ƒ}d|krtj|j_zVz|j |¡}Wn@tk rl}z"| d||jj |¡WY¢W¢dSd}~XYnXW5|j|j_X||_ |  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. rZzCan't parse %s: %s: %sNzRefactoring %s) rVr rcrrdZ parse_stringr"rŽÚ __class__rÚfuture_featuresrƒÚ refactor_tree)rrÚdatarrSr»r±rrrr¶Ws"  ÿ    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 stdinzzNo doctest changes in stdinzNo changes in stdin) ÚsysÚstdinr¯rƒr´r[rµr¶r·r¸)rrržr¹rºr»rrrÚrefactor_stdinrs     zRefactoringTool.refactor_stdinc CsÜt|j|jƒD]}| ||¡q| |j| ¡¡| |j| ¡¡|j |  ¡¡}t |  ¡ƒ�r´|jj D�]D}||krj||rj||j tjjdd�|jr°||j tjjd�t||ƒD]ò}|||krÚ|| |¡z t|ƒWntk �rYq¼YnX|j�r||jk�rq¼| |¡}|r¼| ||¡}|dk r¼| |¡| ¡D] }|j�s^g|_|j |¡�qL|j |  ¡¡}|D]*} | |k�r˜g|| <||  || ¡�q‚q¼qjqTt|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)ryÚreverserxN)rrkrlZ start_treeÚ traverse_byrprqroÚrunZleavesÚanyr+r^r‡rZBaseZdepthZkeep_line_orderZ get_linenor(ÚremoverÚ ValueErrorZfixers_appliedÚmatchÚ transformÚreplacerr-Z finish_treer·) rrr»rr/Z match_setÚnodeÚresultsÚnewZ new_matchesZfxrrrrr¾‚sJ        zRefactoringTool.refactor_treecCsV|sdS|D]D}||jD]4}| |¡}|r| ||¡}|dk r| |¡|}qq dS)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)rrÉrÊrË)rrr^Z traversalrÌr/rÍrÎrrrrÄÑs    zRefactoringTool.traverse_bycCs†|j |¡|dkr.| |¡d}|dkr.dS||k}| ||||¡|r`| d|¡|js`dS|rv| ||||¡n | d|¡dS)zR Called when a file has been refactored and there may be changes. NrzNo changes to %szNot writing changes to %s)rmrr²r–rƒr[Ú write_file)rrr“r”r’r�r©r•rrrrµès  zRefactoringTool.processed_filec Cs´ztj|d|dd�}Wn6tk rL}z| d||¡WY¢dSd}~XYnX|�Fz| |¡Wn0tk r’}z| d||¡W5d}~XYnXW5QRX| 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. Úwrvr¨zCan't create %s: %sNzCan't write %s: %szWrote changes to %sT)rEr«r¬rŽr�rƒri)rrr“r”r’r©Úfpr±rrrrÏýs* zRefactoringTool.write_filez>>> z... c Csg}d}d}d}d}|jdd�D]È}|d7}| ¡ |j¡r~|dk rZ| | ||||¡¡|}|g}| |j¡} |d| …}q |dk r¸| ||j¡s¬|||j ¡dkr¸|  |¡q |dk rÖ| | ||||¡¡d}d}|  |¡q |dk �r | | ||||¡¡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³rv) Ú splitlinesÚlstriprÚPS1r-Úrefactor_doctestÚfindÚPS2Úrstriprr) rrr¹r”ÚresultÚblockZ block_linenoÚindentÚlinenoÚlineÚirrrr´sJ  ÿ ÿþ  ÿ   ÿz"RefactoringTool.refactor_docstringc s.zˆ ||ˆ¡}Wnjtk r|}zLˆj tj¡rN|D]}ˆ d| d¡¡q6ˆ d|||j j |¡|WY¢Sd}~XYnXˆ  ||¡�r*t |ƒj dd�}|d|d…||dd…} }| dg|dksØt| ƒ‚|d d¡sö|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: %sNTrÒrrtrcsg|]}ˆˆj|‘qSr)rÙ)r3rß©rÝrrrrr6Zsz4RefactoringTool.refactor_doctest..)Ú parse_blockr"r]Z isEnabledForrgÚDEBUGrƒrÚrŽr¼rr¾r¸rÔÚAssertionErrorÚendswithrÖÚpop) rrrÜrÞrÝr”r»r±rßrÎZclippedrrárr×@s.ÿ"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|f|ž|Ž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:)rirmr‚rhrfr|)rrrçÚfileÚmessager‹rŒr�rrrÚ summarize]s$       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. )rZ parse_tokensÚ wrap_toksrHr½)rrrÜrÞrÝr»rrrrâtszRefactoringTool.parse_blockc csdt | ||¡j¡}|D]F\}}\}}\} } } ||d7}| |d7} ||||f| | f| fVqdS)z;Wraps a tokenize stream to systematically modify start/end.rN)rrDÚ gen_linesÚ__next__) rrrÜrÞrÝr,rrUZline0Zcol0Zline1Zcol1Z line_textrrrrë~s   zRefactoringTool.wrap_toksccsx||j}||j}|}|D]N}| |¡r>|t|ƒd…Vn(|| ¡dkrVdVntd||fƒ‚|}qdVqldS)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=%rrv)rÖrÙrr|rÚrä)rrrÜrÝÚprefix1Zprefix2ÚprefixrßrrrrìŒs   zRefactoringTool.gen_lines)NN)FF)FF)FF)F)NFN)N)rrrr`r~r{rsrjrŽr‚rƒr–rŸršr²r›r¶rÂr¾rÄrµrÏrÖrÙr´r×rêrârërìrrrrrY›s>ÿ 4(   Oÿ  + rYc@s eZdZdS)ÚMultiprocessingUnsupportedNrrrrrrð srðcsBeZdZ‡fdd„Zd ‡fdd„ Z‡fdd„Z‡fd d „Z‡ZS) ÚMultiprocessRefactoringToolcs"tt|ƒj||Žd|_d|_dSr8)ÚsuperrñrsÚqueueÚ output_lock©rrrŒÚkwargs©r¼rrrs¦sz$MultiprocessRefactoringTool.__init__Frc sö|dkrttˆƒ |||¡Sz ddl‰Wntk r@t‚YnXˆjdk rTtdƒ‚ˆ ¡ˆ_ˆ  ¡ˆ_ ‡‡fdd„t |ƒDƒ}z*|D] }| ¡q†ttˆƒ |||¡W5ˆj  ¡t |ƒD]}ˆj  d¡q¾|D]}| ¡rÔ|  ¡qÔdˆ_XdS)Nrrz already doing multiple processescsg|]}ˆjˆjd�‘qS))Útarget)ZProcessÚ_child)r3rà©Úmultiprocessingrrrrr6¸sÿz8MultiprocessRefactoringTool.refactor..)ròrñrŸrûÚ ImportErrorrðróÚ RuntimeErrorZ JoinableQueueZLockrôÚrangerÚputZis_aliveÚstart)rrrœr�ržZ num_processesZ processesràr$r÷rúrrŸ«s< ÿ      ÿ ÿ   z$MultiprocessRefactoringTool.refactorcsN|j ¡}|dk rJ|\}}ztt|ƒj||ŽW5|j ¡X|j ¡}q dSr8)róreZ task_doneròrñr›)rrZtaskrŒrör÷rrrùÈs  ÿ z"MultiprocessRefactoringTool._childcs2|jdk r|j ||f¡ntt|ƒj||ŽSdSr8)rórÿròrñr›rõr÷rrr›Ós   ÿz)MultiprocessRefactoringTool.refactor_file)FFr)rrrrsrŸrùr›Ú __classcell__rrr÷rrñ¤s  ÿ rñ)T)#rXÚ __author__rEr—rrÀrgr…r&Ú itertoolsrZpgen2rrrZ fixer_utilrrvrr r rnrr"rrr0r7r:rVrWÚobjectrYrðrñrrrrÚs8    (