ó x”þfc@sdZddlZddlZddlZddlZdadadad„Zd„Z d„Z dd d„ƒYZ e d krŒe ƒndS( s‘cleanfuture [-d][-r][-v] path ... -d Dry run. Analyze, but don't make any changes to, files. -r Recurse. Search for all .py files in subdirectories too. -v Verbose. Print informative msgs. Search Python (.py) files for future statements, and remove the features from such statements that are already mandatory in the version of Python you're using. 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. Overwrites files in place, renaming the originals with a .bak extension. If cleanfuture finds nothing to change, the file is left alone. If cleanfuture does change a file, the changed file is a fixed-point (i.e., running cleanfuture on the resulting .py file won't change it again, at least not until you try it again with a later Python release). Limitations: You can do these things, but this tool won't help you then: + A future statement cannot be mixed with any other statement on the same physical line (separated by semicolon). + A future statement cannot contain an "as" clause. Example: Assuming you're using Python 2.2, if a file containing from __future__ import nested_scopes, generators is analyzed by cleanfuture, the line is rewritten to from __future__ import generators because nested_scopes is no longer optional in 2.2 but generators is. iÿÿÿÿNicGsOtt|ƒ}dj|ƒ}|ddkr;|d7}ntjj|ƒdS(Nt iÿÿÿÿs (tmaptstrtjointsyststderrtwrite(targststringstmsg((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyterrprint2s  cCsëddl}y#|jtjddƒ\}}Wn!|jk rR}t|ƒdSXx_|D]W\}}|dkrtd7aqZ|dkr˜td7aqZ|dkrZtd7aqZqZW|sÌtdtƒdSx|D]}t |ƒqÓWdS(Niÿÿÿÿitdrvs-ds-rs-vsUsage:( tgetoptRtargvterrorR tdryruntrecursetverboset__doc__tcheck(R toptsRR totatarg((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pytmain9s$ #        cCs“tjj|ƒr½tjj|ƒ r½tr7dG|GHntj|ƒ}xp|D]h}tjj||ƒ}tr“tjj|ƒr“tjj|ƒ s¨|jƒj dƒrMt |ƒqMqMWdStrÒdG|GdGnyt |ƒ}Wn.t k r}t d|t|ƒfƒdSXt||ƒ}|jƒ}|rA|jƒn|jƒ|rtrmdGHtrmdGHqmnxw|D]o\}} } d||d | d fGHx&t|| d ƒD]} |j| Gq±W| dkrÚd GHqtd GH| GqtWts|d } tjj| ƒrtj| ƒntj|| ƒtrCd G|GdG| GHnt |dƒ} |j| ƒ| jƒtr~dG|GHq~qntrdGHndS(Nslisting directorys.pytcheckings...s%r: I/O Error: %sschanged.s+But this is a dry run, so leaving it alone.s%r lines %d-%dis -- deleteds -- change to:s.baktrenamedttotws wrote news unchanged.(tostpathtisdirtislinkRtlistdirRRtlowertendswithRtopentIOErrorR Rt FutureFindertrunt gettheresttcloseRtrangetlinestNonetexiststremovetrenameR(tfiletnamestnametfullnametfR tfftchangedtstetlinetitbaktg((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyRNsd%          R&cBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCs1||_||_d|_g|_g|_dS(Ni(R4tfnametateofR+R6(tselfR4R=((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyt__init__ˆs     cCsH|jr dS|jjƒ}|dkr4d|_n|jj|ƒ|S(Nti(R>R4treadlineR+tappend(R?R9((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pytgetline’s   c Cstj}tj}tj}tj}tj}tj}|j}tj|j ƒj }|ƒ\} } \} } \} }}x=| |||fkr·|ƒ\} } \} } \} }}q{Wx4| |krî|ƒ\} } \} } \} }}q»Wxx=| |||fkr1|ƒ\} } \} } \} }}qõW| |koG| dksNPn| d}|ƒ\} } \} } \} }}| |ko‘| dks˜Pn|ƒ\} } \} } \} }}| |koÑ| dksØPn|ƒ\} } \} } \} }}g}x| |kr…|j | ƒ|ƒ\} } \} } \} }}| |koW| dks^Pn|ƒ\} } \} } \} }}qWd}| |krÅ| }|ƒ\} } \} } \} }}n| |k rït d|j| |fƒgS| d}g}xs|D]k}tt|dƒ}|dkr:|j |ƒq|jƒ}|dksq|tjkrdq|j |ƒqWt|ƒt|ƒkròt|ƒdkr¨d}n@d}|d j|ƒ7}|dk rÞ|d |7}n|d 7}|j |||fƒqòqò|S( Ntfromit __future__timportt,s)Skipping file %r; can't parse line %d: %sisfrom __future__ import s, Rs (ttokenizetSTRINGtNLtNEWLINEtCOMMENTtNAMEtOPR6tgenerate_tokensRDtnextRCR,R R=tgetattrRFtgetMandatoryReleaseRt version_infotlenR(R?RJRKRLRMRNROR6tgetttypettokentsrowtscolterowtecolR9t startlinetfeaturestcommenttendlinet okfeaturesR4tobjecttreleased((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyR'œsz       $((( $$$ $( '        cCs+|jrd|_n|jjƒ|_dS(NRA(R>ttherestR4tread(R?((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyR(ûs  cCs©|j}|st‚g|_|jƒxN|D]F\}}}|dkr^|j||d5q/|g|j||d+q/W|j|jƒ|jr¥|j|jƒndS(Ni(R6tAssertionErrortreverseR,R+t writelinesRdR(R?R4R6R7R8R9((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyRs      (t__name__t __module__R@RDR'R(R(((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyR&†s  _ t__main__(( RRFRIRRRRRR RRR&Ri(((s1/usr/lib64/python2.7/Tools/scripts/cleanfuture.pyt's       8