o ,] @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)nodeslashrE/usr/lib/python3/dist-packages/libfuturize/fixes/fix_division_safe.pymatch_divisions rz^[0-9]*[.][0-9]*$cCst|jp t|jS)N) _is_floatyr r )rrrr is_floaty"srcCsVt|tr |d}t|trt|jSt|tr)t|jdtr)|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_treefuture_featuresskip)selftreename __class__rrr!>szFixDivisionSafe.start_treecCs|j|jjkrMd}d}g}|jD]1}|rd}qt|r:t|s:d}d|d_td|t|j g|jdg}d}q| | q|rMt |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 symstermrrrr+r rr cloneappendrr,)r$rmatchedr#rchildrrrrEs(  zFixDivisionSafe.matchcCs$|jrdStd|tdd||S)Nrz past.utilsr*)r#rr)r$rresultsrrr transformcs   zFixDivisionSafe.transform) __name__ __module__ __qualname__ run_orderrr _accept_typePATTERNr!rr4 __classcell__rrr'rr4s r)__doc__relib2to3.fixer_utilrrrlib2to3rlibfuturize.fixer_utilrrrr rcompilerrrBaseFixrrrrrs