Hacked By AnonymousFox

Current Path : /proc/thread-self/root/usr/lib64/python2.7/Tools/scripts/
Upload File :
Current File : //proc/thread-self/root/usr/lib64/python2.7/Tools/scripts/fixdiv.pyc

�
�fc@s�dZddlZddlZddlZddlZdad�Zd�ZdZd�Z	d�Z
d	�Zd
�Zddd��YZ
d
�Zd�Zedkr�eje��ndS(s(fixdiv - tool to fix division operators.

To use this tool, first run `python -Qwarnall yourscript.py 2>warnings'.
This runs the script `yourscript.py' while writing warning messages
about all uses of the classic division operator to the file
`warnings'.  The warnings look like this:

  <file>:<line>: DeprecationWarning: classic <type> division

The warnings are written to stderr, so you must use `2>' for the I/O
redirect.  I know of no way to redirect stderr on Windows in a DOS
box, so you will have to modify the script to set sys.stderr to some
kind of log file if you want to do this on Windows.

The warnings are not limited to the script; modules imported by the
script may also trigger warnings.  In fact a useful technique is to
write a test script specifically intended to exercise all code in a
particular module or set of modules.

Then run `python fixdiv.py warnings'.  This first reads the warnings,
looking for classic division warnings, and sorts them by file name and
line number.  Then, for each file that received at least one warning,
it parses the file and tries to match the warnings up to the division
operators found in the source code.  If it is successful, it writes
its findings to stdout, preceded by a line of dashes and a line of the
form:

  Index: <file>

If the only findings found are suggestions to change a / operator into
a // operator, the output is acceptable input for the Unix 'patch'
program.

Here are the possible messages on stdout (N stands for a line number):

- A plain-diff-style change ('NcN', a line marked by '<', a line
  containing '---', and a line marked by '>'):

  A / operator was found that should be changed to //.  This is the
  recommendation when only int and/or long arguments were seen.

- 'True division / operator at line N' and a line marked by '=':

  A / operator was found that can remain unchanged.  This is the
  recommendation when only float and/or complex arguments were seen.

- 'Ambiguous / operator (..., ...) at line N', line marked by '?':

  A / operator was found for which int or long as well as float or
  complex arguments were seen.  This is highly unlikely; if it occurs,
  you may have to restructure the code to keep the classic semantics,
  or maybe you don't care about the classic semantics.

- 'No conclusive evidence on line N', line marked by '*':

  A / operator was found for which no warnings were seen.  This could
  be code that was never executed, or code that was only executed
  with user-defined objects as arguments.  You will have to
  investigate further.  Note that // can be overloaded separately from
  /, using __floordiv__.  True division can also be separately
  overloaded, using __truediv__.  Classic division should be the same
  as either of those.  (XXX should I add a warning for division on
  user-defined objects, to disambiguate this case from code that was
  never executed?)

- 'Phantom ... warnings for line N', line marked by '*':

  A warning was seen for a line not containing a / operator.  The most
  likely cause is a warning about code executed by 'exec' or eval()
  (see note below), or an indirect invocation of the / operator, for
  example via the div() function in the operator module.  It could
  also be caused by a change to the file between the time the test
  script was run to collect warnings and the time fixdiv was run.

- 'More than one / operator in line N'; or
  'More than one / operator per statement in lines N-N':

  The scanner found more than one / operator on a single line, or in a
  statement split across multiple lines.  Because the warnings
  framework doesn't (and can't) show the offset within the line, and
  the code generator doesn't always give the correct line number for
  operations in a multi-line statement, we can't be sure whether all
  operators in the statement were executed.  To be on the safe side,
  by default a warning is issued about this case.  In practice, these
  cases are usually safe, and the -m option suppresses these warning.

- 'Can't find the / operator in line N', line marked by '*':

  This really shouldn't happen.  It means that the tokenize module
  reported a '/' operator but the line it returns didn't contain a '/'
  character at the indicated position.

- 'Bad warning for line N: XYZ', line marked by '*':

  This really shouldn't happen.  It means that a 'classic XYZ
  division' warning was read with XYZ being something other than
  'int', 'long', 'float', or 'complex'.

Notes:

- The augmented assignment operator /= is handled the same way as the
  / operator.

- This tool never looks at the // operator; no warnings are ever
  generated for use of this operator.

- This tool never looks at the / operator when a future division
  statement is in effect; no warnings are generated in this case, and
  because the tool only looks at files for which at least one classic
  division warning was seen, it will never look at files containing a
  future division statement.

- Warnings may be issued for code not read from a file, but executed
  using an exec statement or the eval() function.  These may have
  <string> in the filename position, in which case the fixdiv script
  will attempt and fail to open a file named '<string>' and issue a
  warning about this failure; or these may be reported as 'Phantom'
  warnings (see above).  You're on your own to deal with these.  You
  could make all recommended changes and add a future division
  statement to all affected files, and then re-run the test script; it
  should not issue any warnings.  If there are any, and you have a
  hard time tracking down where they are generated, you can use the
  -Werror option to force an error instead of a first warning,
  generating a traceback.

- The tool should be run from the same directory as that from which
  the original script was run, otherwise it won't be able to open
  files given by relative pathnames.
i����Nic
CsJy#tjtjdd�\}}Wn!tjk
rF}t|�dSXx>|D]6\}}|dkrotGHdS|dkrNdaqNqNW|s�td�dS|dr�tjjdtjd�nt	|d�}|dkr�dS|j�}|sd	G|dGHdS|j�d}x-|D]%}t
|||�}	|p?|	}qW|S(
Nithmis-hs-ms&at least one file argument is requireds!%s: extra file arguments ignored
is&No classic division warnings read from(tgetopttsystargvterrortusaget__doc__tmulti_oktstderrtwritetreadwarningstNonetkeystsorttprocess(
toptstargstmsgtotatwarningstfilestexittfilenametx((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pytmain�s:#






cCs[tjjdtjd|f�tjjdtjd�tjjdtjd�dS(Ns%s: %s
isUsage: %s [-m] warnings
s"Try `%s -h' for more information.
(RRR	R(R((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyR�s!sL^(.+?):(\d+): DeprecationWarning: classic (int|long|float|complex) division$cCs"tjt�}yt|�}Wn(tk
rI}tjjd|�dSXi}x�|j�}|siPn|j	|�}|s�|j
d�dkrStjjd|�qSqSn|j�\}}}	|j|�}
|
dkr�g||<}
n|
jt|�t|	�f�qSW|j�|S(Nscan't open: %s
tdivisionisWarning: ignored input (tretcompiletPATTERNtopentIOErrorRRR	treadlinetmatchtfindtgroupstgetRtappendtinttinterntclose(twarningsfiletprogtfRRtlinetmRtlinenotwhattlist((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyR
�s.#
cCs@ddGH|st�yt|�}Wn(tk
rO}tjjd|�dSXdG|GHt|�}|j�d}tj	|j
�}x�t|�\}}}	}
|dkr�Pn||ko�dk	ns�t�g}xE|t
|�kr"||d|kr"|j||�|d7}q�W|r9t||�ng}xE|t
|�kr�||d|kr�|j||�|d7}qBW|	r�|r�q�|	r�|r�t|	d�q�|r�|	r�t||�q�t
|	�dkr�ts�g}
d}x?|	D]7\\}}}||kr!q�n|
j|�|}q�W|
sDt�t
|
�dkrfdG|
dGHq�d	Gd
|
d|
dfGHq�ng}g}g}xY|D]Q\}}|dkr�|j|�q�|dkr�|j|�q�|j|�q�Wd}x0|	D](\\}}}||kr&qn|}t|�}|||d!dkrgd|GHdG|GHqn|r�d|G|GHdG|GHq|r�|r�d||fGHdG|GHdGHdG|| d||GHq|r�|r�d|GHdG|GHq|r|rddj|�dj|�|fGHdG|GHqqWq�W|j�dS(Nt-iFscan't open: %s
isIndex:isNo conclusive evidences$*** More than one / operator in lines**** More than one / operator per statementsin lines %d-%di����R&tlongtfloattcomplext/s)*** Can't find the / operator in line %d:t*s*** Bad warning for line %d:s%dc%dt<s---t>s$True division / operator at line %d:t=s-*** Ambiguous / operator (%s, %s) at line %d:t|t?(R&R2(R3R4(tAssertionErrorRRRRR	tFileContextR
ttokenizetgenerate_tokensR tscanlineRtlenR%treportphantomwarningstreportRtchoptjoinR((RR0tfpRR+tindextgtstartlinenot	endlinenotslashestlineinfotorphansRtrowstlastrowtrowtcolR,tintlongtfloatcomplextbadR.R/((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyR�s�		
"))



		

	
	!c	Cs�g}d}d}xF|D]>\}}||krJ|g}|j|�n|j|�qWxM|D]E}|d}dj|d�}d||fGH|j|dd�qbWdS(NiR5is$*** Phantom %s warnings for line %d:tmarkR6(RR%RERC(	RR+tblocksROt	lastblockRPR/tblocktwhats((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyRB$s	

cCsZd}xM|D]E\\}}}||kr
d||fGHdGt|�GH|}q
q
WdS(Ns*** %s on line %d:R6(RRD(RKtmessageRORPRQR,((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyRC3sR=cBsAeZddd�Zd�Zd�Zd�Zddd�ZRS(	iicCs:||_d|_d|_d|_g|_g|_dS(Niii(RFtwindowR.teoflookaheadt	lookaheadtbuffer(tselfRFR[R.((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyt__init__<s					cCs_xXt|j�|jkrZ|jrZ|jj�}|sGd|_Pn|jj|�qWdS(Ni(RAR]R[R\RFR R%(R_R,((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pytfillCs%	cCsL|j�|jsdS|jjd�}|jj|�|jd7_|S(Ntii(RaR]tpopR^R%R.(R_R,((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyR Js
	cCs�|j�|jt|j�}|jt|j�}||koP|jknrd|j||S|j|ko~|knr�|j||jSt�dS(N(RaR.RAR^R]tKeyError(R_RGtbufstarttlookend((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyt__getitem__Rs
R6cCsn|dkr|}nxRt||d�D]=}y||}Wntk
rVd}nX|Gt|�GHq)WdS(Nis<missing line>(RtrangeRdRD(R_tfirsttlastRUtiR,((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyRC[s	

N(t__name__t
__module__R`RaR RgRRC(((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyR=;s
				c	Cs�g}d}d}xq|D]i\}}}}}|d}|dkrM|}n|dkro|j||f�n|tjkrPqqW|||fS(NiR5s/=(R5s/=(RR%R>tNEWLINE(	RHRKRIRJttypettokentstarttendR,((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyR@es
	cCs|jd�r|d S|SdS(Ns
i����(tendswith(R,((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyRDsst__main__((RRRRR>RRRRR
RRBRCR=R@RDRlR(((s,/usr/lib64/python2.7/Tools/scripts/fixdiv.pyt<module>�s"	 			W		*		

Hacked By AnonymousFox1.0, Coded By AnonymousFox