a 97a @s|dZddlZddlmZmZmZddlmZddlm Z m Z m Z m Z ddZ edZd d Zd d ZGd ddejZdS)aL For the ``future`` package. Adds this import line: from __future__ import division at the top and changes any old-style divisions to be calls to past.utils.old_div so the code runs as before on Py2.6/2.7 and has the same behaviour on Py3. If "from __future__ import division" is already in effect, this fixer does nothing. N)LeafNodeComma) fixer_base)token future_importtouch_import_topwrap_in_fn_callcCs,tj}|j|ko*|jj|k o*|jj|k S)zw __future__.division redefines the meaning of a single slash for division, so we match that and only that. )rSLASHtype next_sibling prev_sibling)nodeZslashr~/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/libfuturize/fixes/fix_division_safe.pymatch_divisions rz^[0-9]*[.][0-9]*$cCst|jpt|jS)N) _is_floatyr r )rrrr is_floaty"srcCsVt|tr|d}t|tr(t|jSt|trRt|jdtrR|jdjdkSdS)NrfloatF) isinstancelistrconst_rematchvaluerchildren)exprrrrr&s    rcs:eZdZdZejZdZfddZddZ ddZ Z S) FixDivisionSafez4 term<(not('/') any)+ '/' ((not('/') any))> cs"tt|||d|jv|_dS)zO Skip this fixer if "__future__.division" is already imported. divisionN)superr start_treeZfuture_featuresskip)selftreename __class__rrr >szFixDivisionSafe.start_treecCs|j|jjkrd}d}g}|jD]b}|r.d}q t|rtt|std}d|d_td|t|j g|jdg}d}q | | q |rt |j||j dSdS)z Since the tree needs to be fixed once and only once if and only if it matches, we can start discarding matches after the first. FTrold_div)prefix)fixers_applied)r ZsymsZtermrrrr)r rr cloneappendrr*)r"rmatchedr!rchildrrrrEs(  zFixDivisionSafe.matchcCs$|jr dStd|tdd||S)Nrz past.utilsr()r!rr)r"rresultsrrr transformcs   zFixDivisionSafe.transform) __name__ __module__ __qualname__Z run_orderrr Z _accept_typeZPATTERNr rr0 __classcell__rrr%rr4s  r)__doc__reZlib2to3.fixer_utilrrrZlib2to3rZlibfuturize.fixer_utilrrrr rcompilerrrZBaseFixrrrrrs