ACC SHELL

Path : /usr/lib/python/lib2to3/
File Upload :
Current File : //usr/lib/python/lib2to3/refactor.pyo

sMc
@sdZdZddkZddkZddkZddkZddkZddkZddkl	Z	ddk
lZlZl
Z
ddklZlZedZd	efd
YZdZdZd
ZdZeiddfjo+ddkZeiZdZdZneZeZeZdZdefdYZ de!fdYZ"defdYZ#de"fdYZ$dS(sRefactoring 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.
s#Guido van Rossum <guido@python.org>iN(tchaini(tdriverttokenizettoken(tpytreetpygramcCst|ggdg}tii|i}g}xgtti|D]P}|ido:|ido*|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/lib/python2.6/lib2to3/refactor.pytget_all_fix_namess t
_EveryNodecBseZRS((t__name__t
__module__(((s&/usr/lib/python2.6/lib2to3/refactor.pyR)scCst|titifo+|idjo
tnt|igSt|tio"|i	ot
|i	Stnt|tioFt}x5|i	D]*}x!|D]}|it
|qWqW|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
isinstanceRtNodePatterntLeafPatternttypetNoneRtsettNegatedPatterntcontentt_get_head_typestWildcardPatterntupdatet	Exception(tpattrtptx((s&/usr/lib/python2.6/lib2to3/refactor.pyR$-s"


	
cCstit}g}x|D]}|io\yt|i}Wn tj
o|i|qXxX|D]}||i|qiWq|idj	o||ii|q|i|qWx:t	t
iii
t
iiD]}||i|qWt|S(s^ Accepts a list of fixers and returns a dictionary
        of head node type --> fixer list.  N(tcollectionstdefaultdicttlisttpatternR$RRt_accept_typeR RRtpython_grammart
symbol2numbert
itervaluesttokenstextendtdict(t
fixer_listt
head_nodesteverytfixertheadst	node_type((s&/usr/lib/python2.6/lib2to3/refactor.pyt_get_headnode_dictIs(

cCs0g}t|tD]}||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/lib/python2.6/lib2to3/refactor.pytget_fixers_from_packagebscCs|S(N((tobj((s&/usr/lib/python2.6/lib2to3/refactor.pyt	_identityisiicCs|iddS(Nu
u
(treplace(tinput((s&/usr/lib/python2.6/lib2to3/refactor.pyt_from_system_newlinespscCs,tidjo|idtiS|SdS(Ns
u
(R	tlinesepRF(RG((s&/usr/lib/python2.6/lib2to3/refactor.pyt_to_system_newlinesrscst}titi|ifd}ttititi	f}yxt
oz|\}}||joqTqT|tijo|oPnt
}qT|tijo|djo|\}}|tijo|djoPn|\}}|tijo|djoPn|\}}|ti
jo |djo|\}}nxl|tijoV|djot
S|\}}|ti
jo|djoPn|\}}qeWqTPqTWWntj
onXtS(Ncst}|d|dfS(Nii(tnext(ttok(tgen(s&/usr/lib/python2.6/lib2to3/refactor.pytadvancesufromu
__future__uimportu(uprint_functionu,(R?Rtgenerate_tokenstStringIOtreadlinet	frozensetRtNEWLINEtNLtCOMMENTtTruetSTRINGtNAMEtOPt
StopIteration(tsourcethave_docstringRNtignorettptvalue((RMs&/usr/lib/python2.6/lib2to3/refactor.pyt_detect_future_print}sH



t
FixerErrorcBseZdZRS(sA fixer could not be loaded.(RRt__doc__(((s&/usr/lib/python2.6/lib2to3/refactor.pyRastRefactoringToolcBseZhed6ZdZdZdddZdZdZ	dZ
dZdZeed	Z
eed
ZdZeedZd
ZedZdZdZdeddZddZdZdZdZdZdZdZdZdZRS(tprint_functiontFixRcCs||_|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(sInitializer.

        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.
        RdRctconverttloggerN(tfixerstexplicitt_default_optionstcopytoptionsR R&Rt!python_grammar_no_print_statementtgrammarR1terrorstloggingt	getLoggerRgt	fixer_logR?twroteRtDriverRRft
get_fixerst	pre_ordert
post_orderR=tpre_order_headstpost_order_headstfiles(tselftfixer_namesRlRi((s&/usr/lib/python2.6/lib2to3/refactor.pyt__init__s&	
				c

Csg}g}x|iD]}t|hhdg}|iddd}|i|io|t|i}n|id}|idig}|D]}||i	q~}	yt
||	}
Wn)tj
otd||	fnX|
|i
|i}|io7|itj	o'||ijo|id|qn|id	||id
jo|i|q|idjo|i|qtd|iqWtid
}|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>iit_tsCan't find %s.%ssSkipping implicit fixer: %ssAdding transformation: %stpretpostsIllegal fixer order: %rt	run_ordertkey(RhRtrsplitRtFILE_PREFIXtlentsplittCLASS_PREFIXtjointtitletgetattrtAttributeErrorRaRlRrRiRVtlog_messaget	log_debugtorderRtoperatort
attrgettertsort(
R{tpre_order_fixerstpost_order_fixerstfix_mod_pathtmodRBtpartsRAR*t
class_namet	fix_classR:tkey_func((s&/usr/lib/python2.6/lib2to3/refactor.pyRus:
7cOsdS(sCalled when an error occurs.N((R{tmsgtargstkwds((s&/usr/lib/python2.6/lib2to3/refactor.pyt	log_errorscGs)|o||}n|ii|dS(sHook to log a message.N(Rgtinfo(R{RR((s&/usr/lib/python2.6/lib2to3/refactor.pyRscGs)|o||}n|ii|dS(N(Rgtdebug(R{RR((s&/usr/lib/python2.6/lib2to3/refactor.pyRscCsdS(sTCalled with the old version, new version, and filename of a
        refactored file.N((R{told_texttnew_texttfilenametequal((s&/usr/lib/python2.6/lib2to3/refactor.pytprint_outputscCsRxK|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_onlytdir_or_file((s&/usr/lib/python2.6/lib2to3/refactor.pytrefactors
cCsxti|D]\}}}|id||i|ixk|D]c}|idoLtii|dido,tii||}|i	|||qJqJWg}	|D]!}
|
idp|	|
qq~	|(qWdS(sDescends 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	twalkRRRR
tsplitextRRR(R{tdir_nameRRtdirpathtdirnamest	filenamesRtfullnameRAtdn((s&/usr/lib/python2.6/lib2to3/refactor.pyRs

 cCsyt|d}Wn)tj
o}|id||dSXzti|id}Wd|iXt|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(
topentIOErrorRR Rtdetect_encodingRQtcloset_open_with_encodingt__exit__t	__enter__RHtread(R{RtfterrRRA((s&/usr/lib/python2.6/lib2to3/refactor.pyt_read_python_source&s,cCs|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 %siRRsNo changes in %s(RR Rtrefactor_docstringtprocessed_filetrefactor_stringtwas_changedtunicode(R{RRRRGRtoutputttree((s&/usr/lib/python2.6/lib2to3/refactor.pyR6s


c	Cst|oti|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.
        sCan't parse %s: %s: %sNsRefactoring %s(R`RRmRRntparse_stringR'Rt	__class__RRt
refactor_tree(R{tdataRRR((s&/usr/lib/python2.6/lib2to3/refactor.pyRMs
	
cCstii}|oT|id|i|d}||jo|i|d|q|idnN|i|d}|o'|io|it|d|n|iddS(NsRefactoring doctests in stdins<stdin>sNo doctest changes in stdinsNo changes in stdin(	tsyststdinRRRRRRR(R{RRGRR((s&/usr/lib/python2.6/lib2to3/refactor.pytrefactor_stdinfs

cCsx-t|i|iD]}|i||qW|i|i|i|i|i|ix-t|i|iD]}|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.
        (	RRvRwt
start_treettraverse_byRxRytfinish_treeR(R{RRR:((s&/usr/lib/python2.6/lib2to3/refactor.pyRvscCs|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(Rtmatcht	transformR RF(R{Rht	traversaltnodeR:tresultstnew((s&/usr/lib/python2.6/lib2to3/refactor.pyRs

cCs|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(RzRR RRRt
write_file(R{RRRRRR((s&/usr/lib/python2.6/lib2to3/refactor.pyRs

	cCsyt|dd|}Wn,tij
o}|id||dSXzIy|it|Wn+tij
o}|id||nXWd|iX|id|t|_	dS(sWrites 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.
        twRsCan't create %s: %sNsCan't write %s: %ssWrote changes to %s(
RR	terrorRRRJRRRVRs(R{RRRRRR((s&/usr/lib/python2.6/lib2to3/refactor.pyRss>>> s... c
Csg}d}d}d}d}x5|itD]$}|d7}|ii|io_|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(sRefactors 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
splitlinesRVtlstripRtPS1R5trefactor_doctesttfindtPS2trstripRR(
R{RGRtresulttblocktblock_linenotindenttlinenotlineti((s&/usr/lib/python2.6/lib2to3/refactor.pyRs<

	


cCsby|i|||}Wnytj
om}|iitio.x+|D]}|id|idqIWn|id|||i	i
||SX|i||ot|i
t}||d ||d}	}|didp|dcd7<n||i|idg}|o4|g}
|D]}|
||i|q4~
7}q^n|S(sRefactors 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: %siii(tparse_blockR'tlogtisEnabledForRptDEBUGRRRRRRRRRVRRtpopR(R{RRRRRRRRtclippedRA((s&/usr/lib/python2.6/lib2to3/refactor.pyRs&!	8c	Cs'|io
d}nd}|ip|id|n2|id|x|iD]}|i|qRW|io2|idx"|iD]}|i|qWn|iott|idjo|idn|idt|ix1|iD]"\}}}|i|||qWndS(	Ntweres
need to besNo files %s modified.sFiles that %s modified:s$Warnings/messages while refactoring:isThere was 1 error:sThere were %d errors:(RsRzRRrRoR(R{RtfiletmessageRRR((s&/usr/lib/python2.6/lib2to3/refactor.pyt	summarizes*








cCs|ii|i|||S(sParses 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_toks(R{RRR((s&/usr/lib/python2.6/lib2to3/refactor.pyR-sccsti|i||i}xe|D]]\}}\}}\}	}
}||d7}|	|d7}	||||f|	|
f|fVq%WdS(s;Wraps a tokenize stream to systematically modify start/end.iN(RROt	gen_linesRK(R{RRRR4RR_tline0tcol0tline1tcol1t	line_text((s&/usr/lib/python2.6/lib2to3/refactor.pyR5s!ccs||i}||i}|}xm|D]e}|i|o|t|Vn7||idjo	dVntd||f|}q'Wxto	dVqWdS(sGenerates 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=%rRN(RRRRRtAssertionErrorRV(R{RRtprefix1tprefix2tprefixR((s&/usr/lib/python2.6/lib2to3/refactor.pyRCs

	
N(RRR?RjRRR R}RuRRRRRRRRRRRRRRRRRRRRRR(((s&/usr/lib/python2.6/lib2to3/refactor.pyRcs8
	(									+				tMultiprocessingUnsupportedcBseZRS((RR(((s&/usr/lib/python2.6/lib2to3/refactor.pyRWstMultiprocessRefactoringToolcBs5eZdZeeddZdZdZRS(cOs&tt|i||d|_dS(N(tsuperRR}R tqueue(R{Rtkwargs((s&/usr/lib/python2.6/lib2to3/refactor.pyR}]sic
Csg|djott|i|||Syddk}Wntj
o
tnX|idj	otdn|i	|_g}t
|D]}||id|iq~}z;x|D]}	|	i
qWtt|i|||Wd|iix$t
|D]}|iidqWx)|D]!}	|	io|	iq4q4Wd|_XdS(Niis already doing multiple processesttarget(RRRtmultiprocessingtImportErrorRRR tRuntimeErrort
JoinableQueuetxrangetProcesst_childtstartRtputtis_alive(
R{RRRt
num_processesRRARt	processesR*((s&/usr/lib/python2.6/lib2to3/refactor.pyRas6
/


cCsq|ii}x[|dj	oM|\}}ztt|i||Wd|iiX|ii}qWdS(N(RtgetR RRRt	task_done(R{ttaskRR((s&/usr/lib/python2.6/lib2to3/refactor.pyR}s
cOsG|idj	o|ii||fntt|i||SdS(N(RR RRRR(R{RR((s&/usr/lib/python2.6/lib2to3/refactor.pyRs(RRR}R?RRR(((s&/usr/lib/python2.6/lib2to3/refactor.pyR[s
		(%Rbt
__author__R	RRpRR,RPt	itertoolsRtpgen2RRRRRRRVRR'RR$R=RCREtversion_infotcodecsRRRHRJR`RatobjectRcRR(((s&/usr/lib/python2.6/lib2to3/refactor.pyt<module>	s<
						
	(

ACC SHELL 2018