o
    ,º]Ü  ã                   @   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   ú`/var/www/html/myproject/venv/lib/python3.10/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ƒr)t | jd tƒr)| 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v | _dS )zO
        Skip this fixer if "__future__.division" is already imported.
        ÚdivisionN)Úsuperr   Ú
start_treeÚfuture_featuresÚskip)ÚselfÚtreeÚname©Ú	__class__r   r   r!   >   s   zFixDivisionSafe.start_treec                 C   sž   |j | jjkrMd}d}g }|jD ]1}|rd}qt|ƒr:t|ƒs:d}d|d _td|tƒ |j	 
¡ g |jd�g}d}q| | 
¡ ¡ q|rMt|j ||jd�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   ÚsymsÚtermr   r   r   r+   r	   r   r   ÚcloneÚappendr   r,   )r$   r   Ú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   Ú	transformc   s
   
zFixDivisionSafe.transform)Ú__name__Ú
__module__Ú__qualname__Ú	run_orderr   r
   Ú_accept_typeÚPATTERNr!   r   r4   Ú__classcell__r   r   r'   r   r   4   s    r   )Ú__doc__ÚreÚlib2to3.fixer_utilr   r   r   Úlib2to3r   Úlibfuturize.fixer_utilr   r   r   r	   r   Úcompiler   r   r   ÚBaseFixr   r   r   r   r   Ú<module>   s    
	