xfc@sdZd ZddlZddlZddlZddlZdadZdZdZ e d\Z Z Z ZZd d d YZed krendS(scheckappend.py -- search for multi-argument .append() calls. Usage: specify one or more file or directory paths: checkappend [-v] file_or_dir [file_or_dir] ... Each file_or_dir is checked for multi-argument .append() calls. When a directory, all .py files in the directory, and recursively in its subdirectories, are checked. Use -v for status msgs. Use -vv for more status msgs. In the absence of -v, the only output is pairs of the form filename(linenumber): line containing the suspicious append Note that this finds multi-argument append calls regardless of whether they're attached to list objects. If a module defines a class with an append method that takes more than one argument, calls to that method will be listed. Note that this will not find multi-argument list.append calls made via a bound method object. For example, this is not caught: somelist = [] push = somelist.append push(1, 2, 3) iiiNcGs3dj|}tjj|tjjddS(Nt s (tjointsyststderrtwrite(targstmsg((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyterrprint+scCstjd}y#tjtjdd\}}Wn/tjk ra}tt|dtdSXx-|D]%\}}|dkritdaqiqiW|sttdSx|D]}t|qWdS(Nitvs s-v( RtargvtgetoptterrorRtstrt__doc__tverbosetcheck(RtoptsRtopttoptargtarg((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pytmain0s #   cCsKtjj|rtjj| rtr:d|fGHntj|}xq|D]i}tjj||}tjj|rtjj| stjj|ddkrPt|qPqPWdSyt |}Wn(t k r}t d||fdSXtdkrd|fGHnt ||j }trG|rGd|fGHndS(Ns%r: listing directoryis.pys%r: I/O Error: %sischecking %r ...s%r: Clean bill of health.(tostpathtisdirtislinkRtlistdirRtnormcaseRtopentIOErrorRt AppendCheckertrun(tfiletnamestnametfullnametfRtok((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyRAs*%   iRcBsDeZdZdZejejejfejej dZ RS(cCs(||_||_t|_d|_dS(Ni(tfnameRtFIND_DOTtstatetnerrors(tselfR%R((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyt__init__bs   cCsjytj|jj|jWn=tjk r\}td|j|f|jd|_nX|jdkS(Ns%r: Token Error: %sii(ttokenizeRtreadlinet tokeneatert TokenErrorRR%R((R)R((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyRhs c Cs|j} ||krn| tkrH||kr|dkrt} qn| tkr|| kr|dkr||_|d|_t} qt} n9| tkr||kr|dkrd|_t} qt} n| tkr||kr|dkr |jd|_q|dkrA|jd|_|jdkrt} qq|d kr|jdkr|jd|_d |j |j|jfGHt } qqn7| t kr||krt} qnt d | f| |_dS(Nt.tappendit(it{t[t)t}t]t,s %s(%d): %ssunknown internal state '%r'(R1R2R3(R4R5R6( R'R&t FIND_APPENDtlinetlinenot FIND_LPARENtlevelt FIND_COMMAR(R%t FIND_STMTt SystemError( R)ttypettokentstarttendR9tNEWLINEtJUNKtOPtNAMER'((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyR-psF                      ( t__name__t __module__R*RR+RDtCOMMENTtNLRFRGR-(((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyRas   t__main__(iii((R t __version__RRR R+RRRRtrangeR&R8R;R=R>RRH(((s1/usr/lib64/python2.7/Tools/scripts/checkappend.pyt s       E