U
    h/                     @   s|   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	m
Z
mZmZ dd ZedZd	d
 Zdd ZG dd dejZdS )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)LeafNodeComma)
fixer_base)tokenfuture_importtouch_import_topwrap_in_fn_callc                 C   s,   t j}| j|ko*| jj|k o*| jj|k S )zw
    __future__.division redefines the meaning of a single slash for division,
    so we match that and only that.
    )r   SLASHtypenext_siblingprev_sibling)nodeslash r   U/var/www/html/venv/lib/python3.8/site-packages/libfuturize/fixes/fix_division_safe.pymatch_division   s    r   z^[0-9]*[.][0-9]*$c                 C   s   t | jpt | jS )N)
_is_floatyr   r   )r   r   r   r   	is_floaty"   s    r   c                 C   sV   t | tr| d } t | tr(t| jS t | trRt | jd trR| jd jdkS dS )Nr   floatF)
isinstancelistr   const_rematchvaluer   children)exprr   r   r   r   &   s    


r   c                       s:   e Zd ZdZejZdZ fddZdd Z	dd Z
  ZS )	FixDivisionSafe   z4
    term<(not('/') any)+ '/' ((not('/') any))>
    c                    s"   t t| || d|jk| _dS )zO
        Skip this fixer if "__future__.division" is already imported.
        divisionN)superr   
start_treeZfuture_featuresskip)selftreename	__class__r   r   r!   >   s    zFixDivisionSafe.start_treec                 C   s   |j | jjkrd}d}g }|jD ]b}|r.d}q t|rtt|std}d|d _td|t |j	
 g |jdg}d}q ||
  q |rttdrt|j ||jdS t|j |S dS )	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.
        FT r   old_div)prefixfixers_applied)r+   )r   Zsymstermr   r   r   r*   r	   r   r   cloneappendhasattrr   r+   )r#   r   Zmatchedr"   r   childr   r   r   r   E   s,    


zFixDivisionSafe.matchc                 C   s$   | j r
d S td| tdd| |S )Nr   z
past.utilsr)   )r"   r   r   )r#   r   resultsr   r   r   	transformh   s
    
zFixDivisionSafe.transform)__name__
__module____qualname__Z	run_orderr   r
   Z_accept_typeZPATTERNr!   r   r2   __classcell__r   r   r&   r   r   4   s   #r   )__doc__reZlib2to3.fixer_utilr   r   r   Zlib2to3r   Zlibfuturize.fixer_utilr   r   r   r	   r   compiler   r   r   ZBaseFixr   r   r   r   r   <module>   s   	
