Your IP : 3.144.3.129


Current Path : /lib64/python2.7/Tools/scripts/
Upload File :
Current File : //lib64/python2.7/Tools/scripts/reindent.pyc

�
�mec@s�dZdZddlZddlZddlZddlZddlZdadada	e
add�Z
d�Zd�Zd�Zd	d
�Zddd��YZd
�Zedkr�e�ndS(sAreindent [-d][-r][-v] [ path ... ]

-d (--dryrun)   Dry run.   Analyze, but don't make any changes to, files.
-r (--recurse)  Recurse.   Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose)  Verbose.   Print informative msgs; else no output.
-h (--help)     Help.      Print this usage information and exit.

Change Python (.py) files to use 4-space indents and no hard tab characters.
Also trim excess spaces and tabs from ends of lines, and remove empty lines
at the end of files.  Also ensure the last line ends with a newline.

If no paths are given on the command line, reindent operates as a filter,
reading a single source file from standard input and writing the transformed
source to standard output.  In this case, the -d, -r and -v flags are
ignored.

You can pass one or more file and/or directory paths.  When a directory
path, all .py files within the directory will be examined, and, if the -r
option is given, likewise recursively for subdirectories.

If output is not to standard output, reindent overwrites files in place,
renaming the originals with a .bak extension.  If it finds nothing to
change, the file is left alone.  If reindent does change a file, the changed
file is a fixed-point for future runs (i.e., running reindent on the
resulting .py file won't change it again).

The hard part of reindenting is figuring out what to do with comment
lines.  So long as the input files get a clean bill of health from
tabnanny.py, reindent should do a good job.

The backup file is a copy of the one that is being reindented. The ".bak"
file is generated with shutil.copy(), but some corner cases regarding
user/group and permissions could leave the backup file more readable than
you'd prefer. You can always use the --nobackup option to prevent this.
t1i����NicCs-|dk	rtj|IJntjtIJdS(N(tNonetsyststderrt__doc__(tmsg((s./usr/lib64/python2.7/Tools/scripts/reindent.pytusage6scGsKd}x.|D]&}tjj|t|��d}q
Wtjjd�dS(Ntt s
(RRtwritetstr(targstseptarg((s./usr/lib64/python2.7/Tools/scripts/reindent.pyterrprint;s


cCsEddl}y5|jtjdddddddg�\}}Wn!|jk
rd}t|�dSXx�|D]�\}}|dkr�td7aql|dkr�td7aql|dkr�taql|dkr�t	d7a	ql|dkrlt�dSqlW|s&t
tj�}|j�|j
tj�dSx|D]}t|�q-WdS(Ni����itdrnvhtdryruntrecursetnobackuptverbosethelps-ds--dryruns-rs	--recurses-ns
--nobackups-vs	--verboses-hs--help(s-ds--dryrun(s-rs	--recurse(s-ns
--nobackup(s-vs	--verbose(s-hs--help(tgetoptRtargvterrorRRRtFalset
makebackupRt
ReindentertstdintrunR	tstdouttcheck(RtoptsRRtotatrR
((s./usr/lib64/python2.7/Tools/scripts/reindent.pytmainBs4"


	


c	Cs?tjj|�r�tjj|�r�tr7dG|GHntj|�}x�|D]�}tjj||�}tr�tjj|�r�tjj|�r�tjj|�dj	d�s�|j
�jd�rMt|�qMqMWdStr�dG|GdGnyt
j|�}Wn.tk
r5}td|t|�f�dSXt|�}|j�|j}t|t�rvtd|�dS|j�r)tr�d	GHtr�d
GHq�nts%|d}tr�tj||�tr�dG|Gd
G|GHq�nt
j|dd|�}|j|�|j�tr%dG|GHq%ntStr7dGHntSdS(Nslisting directoryit.s.pytcheckings...s%s: I/O Error: %ss0%s: mixed newlines detected; cannot process fileschanged.s+But this is a dry run, so leaving it alone.s.baks	backed upttotwtnewlines	wrote news
unchanged.(tostpathtisdirtislinkRtlistdirtjoinRtsplitt
startswithtlowertendswithRtiotopentIOErrorRR
Rtclosetnewlinest
isinstancettupleRRRtshutiltcopyfileR	tTrueR(	tfiletnamestnametfullnametfRR"R(tbak((s./usr/lib64/python2.7/Tools/scripts/reindent.pyR_sZ%
 
	


s
 	cCsEt|�}x.|dkr<||d|kr<|d8}qW|| S(sReturn line stripped of trailing spaces, tabs, newlines.

    Note that line.rstrip() instead also strips sundry control characters,
    but at least one known Emacs user expects to keep junk like that, not
    mentioning Barry by name or anything <wink>.
    ii(tlen(tlinetJUNKti((s./usr/lib64/python2.7/Tools/scripts/reindent.pyt_rstrip�s#RcBsSeZd�Zd�Zd�Zd�Zejejej	ej
ejd�ZRS(cCs�d|_d|_|j�|_g|jD]}t|�j�d^q+|_|jjdd�d|_	g|_
|j|_dS(Niis
(t	find_stmttlevelt	readlinestrawRGt
expandtabstlinestinsertRtindextstatsR7(tselfRARD((s./usr/lib64/python2.7/Tools/scripts/reindent.pyt__init__�s		,		cCstj|j|j�|j}x$|rE|ddkrE|j�q"W|j}|jt|�df�i}g}|_|dd}|j	|d|!�xct
t|�d�D]K}||\}}||dd}t||�}	|d}
|
dkr+|	r"|j|	d�}
|
dkr�xkt
|dt|�d�D]I}||\}}
|
dkrD|	t||�kr�|
d}
nPqDqDWn|
dkr
xgt
|ddd�D]L}||\}}
|
dkr�|	t||d�t||�}
Pq�q�Wn|
dkr(|	}
q(q+d}
n|
dks=t�|
||	<|
|	}|dksi|	dkr�|j	|||!�q�x||||!D]m}|dkr�|dkr�|j|�q�|jd||�q�tt|�|�}|j||�q�Wq�W|j|jkS(Ni����s
iiiR(ttokenizetgetlinet
tokeneaterRMtpopRPtappendRCtaftertextendtranget	getlspacetgettxrangetAssertionErrortminRK(RQRMRPt	have2wantRXRFtthisstmtt	thisleveltnextstmtthavetwanttjtjlinetjleveltdiffRDtremove((s./usr/lib64/python2.7/Tools/scripts/reindent.pyR�s`		

$
	

cCs|j|j�dS(N(t
writelinesRX(RQRA((s./usr/lib64/python2.7/Tools/scripts/reindent.pyR	scCsD|jt|j�kr!d}n|j|j}|jd7_|S(NRi(RORCRM(RQRD((s./usr/lib64/python2.7/Tools/scripts/reindent.pyRTs
	c
Cs�|\}}||kr$d|_n�||krKd|_|jd7_n�||krrd|_|jd8_nw||	kr�|jr�|jj|df�q�nF||
kr�n7|jr�d|_|r�|jj||jf�q�ndS(Nii����i(RHRIRPRW(
RQttypettokent.3tendRDtINDENTtDEDENTtNEWLINEtCOMMENTtNLtslinetscol((s./usr/lib64/python2.7/Tools/scripts/reindent.pyRU
s$						(
t__name__t
__module__RRRR	RTRSRpRqRrRsRtRU(((s./usr/lib64/python2.7/Tools/scripts/reindent.pyR�s		E		
cCsDdt|�}}x*||kr?||dkr?|d7}qW|S(NiRi(RC(RDRFtn((s./usr/lib64/python2.7/Tools/scripts/reindent.pyR[4st__main__((Rt__version__RSR)R:RR3RRRR<RRRRR#RRGRR[Rw(((s./usr/lib64/python2.7/Tools/scripts/reindent.pyt<module>(s$			4
�